Java Code Examples for org.apache.commons.collections4.CollectionUtils#addAll()

The following examples show how to use org.apache.commons.collections4.CollectionUtils#addAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParserTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpectsPastWhitespace() {
	AssemblyGrammar g = new AssemblyGrammar();
	AssemblyNonTerminal S = new AssemblyNonTerminal("S");
	addProduction(S, g, "a", " ", "b");

	AssemblyParser parser = new AssemblyParser(g);

	String sentence = "a ";
	Collection<AssemblyParseResult> results = new HashSet<>();
	CollectionUtils.addAll(results, parser.parse(sentence));
	assertEquals(1, results.size());
	for (AssemblyParseResult res : results) {
		assertTrue(res instanceof AssemblyParseErrorResult);
		AssemblyParseErrorResult err = (AssemblyParseErrorResult) res;
		Collection<String> sug = err.getSuggestions();
		assertEquals(Set.of("b"), sug);
	}
}
 
Example 2
Source File: MultiReadHttpServletRequestWrapper.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
private Iterable<NameValuePair> decodeParams(String body) {
    String encoding = getRequest().getCharacterEncoding();
    if (StringUtils.isEmpty(encoding)) {
        encoding = Charset.defaultCharset().name();
    }
    List<NameValuePair> params = new ArrayList<>(
            URLEncodedUtils.parse(body, Charset.forName(encoding)));
    try {
        String cts = getContentType();
        if (cts != null) {
            ContentType ct = ContentType.parse(cts);
            if (ct.getMimeType().equals(ContentType.APPLICATION_FORM_URLENCODED.getMimeType())) {
                List<NameValuePair> postParams = URLEncodedUtils.parse(
                        IOUtils.toString(getReader()), Charset.forName(encoding));
                CollectionUtils.addAll(params, postParams);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return params;
}
 
Example 3
Source File: AllyUtils.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
public static Ally[] getAlliesByFilter(final String pFilter, Comparator<Ally> pComparator) {
    if (pFilter == null) {
        return new Ally[0];
    }
    final String filter = pFilter.toLowerCase();

    List<Ally> allies = new LinkedList<>();
    CollectionUtils.addAll(allies, DataHolder.getSingleton().getAllies().values());

    if (filter.length() > 0) {
        CollectionUtils.filter(allies, new Predicate() {

            @Override
            public boolean evaluate(Object o) {
                return pFilter.length() == 0 || ((Ally) o).getName().toLowerCase().contains(filter) || ((Ally) o).getTag().toLowerCase().contains(filter);
            }
        });
    }

    if (pComparator != null) {
        Collections.sort(allies, pComparator);
    }
    allies.add(0, NoAlly.getSingleton());
    //result = (Ally[]) ArrayUtils.add(result, 0, NoAlly.getSingleton());
    return allies.toArray(new Ally[allies.size()]);
}
 
Example 4
Source File: XReferenceUtil.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Returns all xrefs to the given location.  If in data, then xrefs to the specific data
 * component will be returned.  Otherwise, the code unit containing the address of the 
 * given location will be used as the source of the xrefs.
 * 
 * @param location the location for which to get xrefs
 * @return the xrefs
 */
public static Set<Reference> getAllXrefs(ProgramLocation location) {

	CodeUnit cu = DataUtilities.getDataAtLocation(location);
	if (cu == null) {
		Address toAddress = location.getAddress();
		Listing listing = location.getProgram().getListing();
		cu = listing.getCodeUnitContaining(toAddress);
	}

	Reference[] xrefs = getXReferences(cu, ALL_REFS);
	Reference[] offcuts = getOffcutXReferences(cu, ALL_REFS);

	// Remove duplicates
	Set<Reference> set = new HashSet<>();
	CollectionUtils.addAll(set, xrefs);
	CollectionUtils.addAll(set, offcuts);
	return set;
}
 
Example 5
Source File: ParserTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testEndsOptionalWhitespaceEpsilon() {
	AssemblyGrammar g = new AssemblyGrammar();
	AssemblyNonTerminal S = new AssemblyNonTerminal("S");
	AssemblyNonTerminal E = new AssemblyNonTerminal("E");

	addProduction(S, g, "t", " ", E);
	addProduction(E, g);

	AssemblyParser parser = new AssemblyParser(g);
	String sentence = "t";
	Collection<AssemblyParseResult> results = new HashSet<>();
	CollectionUtils.addAll(results, parser.parse(sentence));
	assertEquals(1, results.size());
	String expected = StringUtils.join(new String[] { //
		"[S] := 0. [S] => \"t\" _ [E]", //
		"  \"t\" := 't'", //
		"  _ := ''", //
		"  [E] := 1. [E] => e", //
	}, "\n").trim();
	for (AssemblyParseResult res : results) {
		assertEquals(expected, res.toString().trim());
	}
}
 
Example 6
Source File: Application.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
/**
   * @param msgs
   * @return
   */
  protected static String formatBootMsg(String...msgs) {
List<String> msgsList = new ArrayList<>();
CollectionUtils.addAll(msgsList, msgs);
msgsList.add("\n  Version : " + VER);
msgsList.add("OS      : " + SystemUtils.OS_NAME + " " + SystemUtils.OS_ARCH);
msgsList.add("Report an issue :");
msgsList.add("https://getrebuild.com/report-issue?title=boot");

      return "\n###################################################################\n\n  "
              + StringUtils.join(msgsList, "\n  ") +
              "\n\n###################################################################";
  }
 
Example 7
Source File: BoomEngineOriginalTest.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBigBoomAtClassicWalls() {
    List<Wall> barriers = new LinkedList<Wall>();
    CollectionUtils.addAll(barriers, new OriginalWalls(v(SIZE)).iterator());
    Point source = pt(11, 11);
    int radius = 3;
    int countBlasts = 4*radius + 1;

    assertBoom(barriers, source, radius, countBlasts,
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼       ҉҉҉☻҉҉҉     ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n");
}
 
Example 8
Source File: BoomEngineOriginalTest.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBigBoomAtClassicWalls3() {
    List<Wall> barriers = new LinkedList<Wall>();
    CollectionUtils.addAll(barriers, new OriginalWalls(v(SIZE)).iterator());
    Point source = pt(11, 12);
    int radius = 3;
    int countBlasts = 2*radius + 1;

    assertBoom(barriers, source, radius, countBlasts,
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼☻☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n");
}
 
Example 9
Source File: BoomEngineOriginalTest.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBigBoomAtClassicWalls5() {
    List<Wall> barriers = new LinkedList<>();
    CollectionUtils.addAll(barriers, new OriginalWalls(v(SIZE)).iterator());
    Point source = pt(11, 11);
    int radius = 15;
    int countBlasts = 2 * (SIZE - 2) - 1;

    assertBoom(barriers, source, radius, countBlasts,
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼҉҉҉҉҉҉҉҉҉҉☻҉҉҉҉҉҉҉҉☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼҉☼ ☼ ☼ ☼ ☼\n" +
            "☼          ҉        ☼\n" +
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n");
}
 
Example 10
Source File: ListOptions.java    From cuba with Apache License 2.0 5 votes vote down vote up
@SafeVarargs
public static <V> ListOptions<V> of(V v, V... vs) {
    List<V> options = new ArrayList<>();
    options.add(v);

    if (vs != null) {
        CollectionUtils.addAll(options, vs);
    }

    return new ListOptions<>(options);
}
 
Example 11
Source File: BoomEngineOriginalTest.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBigBoomAtClassicWalls4() {
    List<Wall> barriers = new LinkedList<Wall>();
    CollectionUtils.addAll(barriers, new OriginalWalls(v(SIZE)).iterator());
    Point source = pt(1, 1);
    int radius = 15;
    int countBlasts = 2*radius + 1;

    assertBoom(barriers, source, radius, countBlasts,
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼҉☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼҉                  ☼\n" +
            "☼҉☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼҉                  ☼\n" +
            "☼҉☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼҉                  ☼\n" +
            "☼҉☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼҉                  ☼\n" +
            "☼҉☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼҉                  ☼\n" +
            "☼҉☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼҉                  ☼\n" +
            "☼҉☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼҉                  ☼\n" +
            "☼҉☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼☻҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉   ☼\n" +
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n");
}
 
Example 12
Source File: BranchNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a BranchNode using a logical operator and a list of children.
 *
 * @param assertionType the node's type
 * @param childList the child nodes under this branch node.
 */
protected BranchNode( AssertionType assertionType, ExprNode... childList )
{
    super( assertionType );

    if ( null == children )
    {
        this.children = new ArrayList<>( childList.length );
    }

    CollectionUtils.addAll( children, childList );
}
 
Example 13
Source File: BoomEngineOriginalTest.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBigBoomAtClassicWalls6() {
    List<Wall> barriers = new LinkedList<Wall>();
    CollectionUtils.addAll(barriers, new OriginalWalls(v(SIZE)).iterator());
    Point source = pt(12, 11);
    int radius = 15;
    int countBlasts = SIZE - 2;

    assertBoom(barriers, source, radius, countBlasts,
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼҉҉҉҉҉҉҉҉҉҉҉☻҉҉҉҉҉҉҉☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼ ☼\n" +
            "☼                   ☼\n" +
            "☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼☼\n");
}
 
Example 14
Source File: ShareToManager.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 是否共享
 *
 * @param shareTo
 * @param user
 * @return
 */
private boolean isShareTo(String shareTo, ID user) {
    if (SHARE_ALL.equals(shareTo)) {
        return true;
    } else if (shareTo.length() >= 20) {
        Set<String> userDefs = new HashSet<>();
        CollectionUtils.addAll(userDefs, shareTo.split(","));
        Set<ID> sharedUsers = UserHelper.parseUsers(userDefs, null);
        return sharedUsers.contains(user);
    }
    return false;
}
 
Example 15
Source File: JavaCollectionConversionUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
public final void givenUsingCommonsCollections_whenSetConvertedToList_thenCorrect() {
    final Set<Integer> sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5);

    final List<Integer> targetList = new ArrayList<>(6);
    CollectionUtils.addAll(targetList, sourceSet);
}
 
Example 16
Source File: CollectionUtilsSample.java    From spring-boot with Apache License 2.0 4 votes vote down vote up
/**
	 * @param args
	 */
	@SuppressWarnings({ "unchecked"})
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String[] arrayA = new String[] { "1", "2", "3", "3", "4", "5" };
		String[] arrayB = new String[] { "3", "4", "4", "5", "6", "7" };

		List<String> a = Arrays.asList(arrayA);
		List<String> b = Arrays.asList(arrayB);

		// === list
		//并集    
		Collection<String> l_union = CollectionUtils.union(a, b);
		//交集    
		Collection<String> l_intersection = CollectionUtils.intersection(a, b);
		//交集的补集    
		Collection<String> l_disjunction = CollectionUtils.disjunction(a, b);
		//集合相减
		Collection<String> l_subtract = CollectionUtils.subtract(a, b);

		Collections.sort((List<String>) l_union);
		Collections.sort((List<String>) l_intersection);
		Collections.sort((List<String>) l_disjunction);
		Collections.sort((List<String>) l_subtract);

		// === set

		String[] arrayC = new String[] { "1", "2", "3", "4", "5" };
		String[] arrayD = new String[] { "3", "4", "5", "6", "7" };

		TreeSet<String> c = new TreeSet<String>();
		CollectionUtils.addAll(c, arrayC);
		TreeSet<String> d = new TreeSet<String>();
		CollectionUtils.addAll(d, arrayD);
		
		//并集
		Collection<String> s_union = CollectionUtils.union(c, d);
		//交集
		Collection<String> s_intersection = CollectionUtils.intersection(c, d);
		//交集的补集
		Collection<String> s_disjunction = CollectionUtils.disjunction(c, d);
		//集合相减
		Collection<String> s_subtract = CollectionUtils.subtract(c, d);

//		Collections.sort((List<String>) s_union);
//		Collections.sort((List<String>) s_intersection);
//		Collections.sort((List<String>) s_disjunction);
//		Collections.sort((List<String>) s_subtract);

		System.out.println("List =========");
		System.out.println("A: " + ArrayUtils.toString(a.toArray()));
		System.out.println("B: " + ArrayUtils.toString(b.toArray()));
		System.out.println("--------------------------------------------");
		System.out.println("List: Union(A, B) 并集 : "
				+ ArrayUtils.toString(l_union.toArray()));
		System.out.println("List: Intersection(A, B) 交集 : "
				+ ArrayUtils.toString(l_intersection.toArray()));
		System.out.println("List: Disjunction(A, B) 交集的补集: "
				+ ArrayUtils.toString(l_disjunction.toArray()));
		System.out.println("List: Subtract(A, B) 集合相减  : "
				+ ArrayUtils.toString(l_subtract.toArray()));

		System.out.println("Set =========");
		System.out.println("C: " + ArrayUtils.toString(c.toArray()));
		System.out.println("D: " + ArrayUtils.toString(d.toArray()));
		System.out.println("--------------------------------------------");
		System.out.println("Set: Union(C, D) 并集 : "
				+ ArrayUtils.toString(s_union.toArray()));
		System.out.println("Set: Intersection(C, D) 交集 : "
				+ ArrayUtils.toString(s_intersection.toArray()));
		System.out.println("Set: Disjunction(C, D) 交集的补集: "
				+ ArrayUtils.toString(s_disjunction.toArray()));
		System.out.println("Set: Subtract(C, D) 集合相减  : "
				+ ArrayUtils.toString(s_subtract.toArray()));
	}
 
Example 17
Source File: DSWorkbenchSOSRequestAnalyzer.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
private void copySelectionToClipboardAsBBCode() {
    HashMap<Tribe, SOSRequest> selectedRequests = new HashMap<>();
    List<DefenseInformation> selection = getSelectedRows();
    if (selection.isEmpty()) {
        showInfo("Keine SOS Anfragen eingelesen");
        return;
    }

    for (DefenseInformation info : selection) {
        Tribe defender = info.getTarget().getTribe();
        SOSRequest request = selectedRequests.get(defender);
        if (request == null) {
            request = new SOSRequest(defender);
            selectedRequests.put(defender, request);
        }
        TargetInformation targetInfo = request.addTarget(info.getTarget());
        targetInfo.merge(info.getTargetInformation());
    }

    try {
        boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this, "Erweiterte BB-Codes verwenden (nur für Forum und Notizen geeignet)?", "Erweiterter BB-Code", "Nein", "Ja") == JOptionPane.YES_OPTION);

        StringBuilder buffer = new StringBuilder();
        if (extended) {
            buffer.append("[u][size=12]SOS Anfragen[/size][/u]\n\n");
        } else {
            buffer.append("[u]SOS Anfragen[/u]\n\n");
        }

        List<SOSRequest> requests = new LinkedList<>();
        CollectionUtils.addAll(requests, selectedRequests.values());
        buffer.append(new SosListFormatter().formatElements(requests,
                extended));

        if (extended) {
            buffer.append("\n[size=8]Erstellt am ");
            buffer.append(new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n");
        } else {
            buffer.append("\nErstellt am ");
            buffer.append(new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n");
        }

        String b = buffer.toString();
        StringTokenizer t = new StringTokenizer(b, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this, "Die momentan vorhandenen Anfragen benötigen mehr als 1000 BB-Codes\n"
                    + "und können daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?", "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }

        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null);
        showSuccess("Daten in Zwischenablage kopiert");
    } catch (Exception e) {
        logger.error("Failed to copy data to clipboard", e);
        showError("Fehler beim Kopieren in die Zwischenablage");
    }

}
 
Example 18
Source File: JavaCollectionConversionUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
public final void givenUsingCommonsCollections_whenListConvertedToSet_thenCorrect() {
    final List<Integer> sourceList = Lists.newArrayList(0, 1, 2, 3, 4, 5);

    final Set<Integer> targetSet = new HashSet<>(6);
    CollectionUtils.addAll(targetSet, sourceList);
}
 
Example 19
Source File: JavaCollectionConversionUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public final void givenUsingCommonsCollections_whenArrayConvertedToSet_thenCorrect() {
    final Integer[] sourceArray = { 0, 1, 2, 3, 4, 5 };
    final Set<Integer> targetSet = new HashSet<>(6);
    CollectionUtils.addAll(targetSet, sourceArray);
}
 
Example 20
Source File: CollectionsUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 添加所有的{@link Iterable}元素到指定的<code>objectCollection</code>,如果 {@code iterable}是null将忽略.
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * 
 * List{@code <String>} list = toList("xinge", "feilong1");
 * CollectionsUtil.addAllIgnoreNull(list, null); = false
 * </pre>
 * 
 * </blockquote>
 * 
 * <h3>重构:</h3>
 * 
 * <blockquote>
 * <p>
 * 对于以下代码:
 * </p>
 * 
 * <pre class="code">
 * 
 * private Set{@code <String>} getItemComboIds(List{@code <ShoppingCartLineCommand>} lines){
 *     Set{@code <String>} set = new HashSet{@code <>}();
 *     if ({@code null != lines && lines.size() > 0}){
 *         for (ShoppingCartLineCommand line : lines){
 *             if (line.getComboIds() != null){
 *                 set.addAll(line.getComboIds());
 *             }
 *         }
 *     }
 *     return set;
 * }
 * 
 * </pre>
 * 
 * <b>可以重构成:</b>
 * 
 * <pre class="code">
 * 
 * private Set{@code <String>} getItemComboIds(List{@code <ShoppingCartLineCommand>} lines){
 *     if (isNullOrEmpty(lines)){
 *         return Collections.emptySet();
 *     }
 *     Set{@code <String>} set = new HashSet{@code <>}();
 *     for (ShoppingCartLineCommand line : lines){
 *         CollectionsUtil.addAllIgnoreNull(set, line.getComboIds());
 *     }
 *     return set;
 * }
 * </pre>
 * 
 * <p>
 * 重构之后,方法的复杂度会更小,阅读性更高
 * </p>
 * </blockquote>
 * 
 * @param <O>
 *            the type of object the {@link Collection} contains
 * @param objectCollection
 *            the collection to add to, 不能为null
 * @param iterable
 *            the iterable of elements to add
 * @return a boolean 标识 <code>objectCollection</code> 是否改变,如果改变了,返回true.<br>
 *         如果 <code>objectCollection</code> 是null,抛出 {@link NullPointerException}<br>
 *         如果 <code>iterable</code> 是null,直接返回false<br>
 *         否则调用{@link CollectionUtils#addAll(Collection, Iterable)}
 * @see org.apache.commons.collections4.CollectionUtils#addIgnoreNull(Collection, Object)
 * @see org.apache.commons.collections4.CollectionUtils#addAll(Collection, Iterable)
 * @see org.apache.commons.collections4.CollectionUtils#addAll(Collection, Iterator)
 * @since 1.6.3
 */
public static <O> boolean addAllIgnoreNull(final Collection<O> objectCollection,final Iterable<? extends O> iterable){
    Validate.notNull(objectCollection, "objectCollection can't be null!");
    return null != iterable && CollectionUtils.addAll(objectCollection, iterable);
}