List of usage examples for java.util Collection add
boolean add(E e);
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection in(Collection source, Collection target) { if (source == null || source.size() == 0) { return null; }/*from w ww .j a va2 s . c o m*/ if (target == null || target.size() == 0) { return null; } Collection result = new ArrayList(); for (Iterator it = source.iterator(); it.hasNext();) { Object candidate = it.next(); if (target.contains(candidate)) { result.add(candidate); } } return result; }
From source file:Main.java
/** * Converts the specified Array to a Collection containing the same elements. * * @param source Array of Objects to be converted to a Collection. * @return Collection of Objects containing the elements of the specified Array. *//*from w w w. ja va 2s . c om*/ public static <E> Collection<E> toCollection(E[] source) { Collection<E> collection = null; if (source != null) { collection = new ArrayList<E>(); for (E next : source) { if (next != null) { collection.add(next); } } } return collection; }
From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.ModelImporter.java
/** * Collects all given process model paths and returns them. * @param args the parameter the main class has been executed with * @return a {@link Collection} of all model paths *//*w w w. j a v a 2 s . c o m*/ private static Collection<String> getModelPaths(String[] args) { Collection<String> modelDirectories = new ArrayList<String>(); for (int i = 2; i < args.length; i++) { modelDirectories.add(args[i]); } return modelDirectories; }
From source file:Main.java
/** * Adds all elements in the array to the given collection. * //from w w w . j ava2 s. c o m * @param collection * the collection to add to, must not be null * @param elements * the array of elements to add, must not be null * @throws NullPointerException * if the collection or array is null */ public static <E> void addAll(Collection<E> collection, E[] elements) { if (collection == null || elements == null) { return; } for (E e : elements) { collection.add(e); } }
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection substract(Collection source, Collection target) { if (source == null || source.size() == 0) { return null; }//from w ww . java 2 s. c o m if (target == null || target.size() == 0) { return source; } Collection result = new ArrayList(); for (Iterator it = source.iterator(); it.hasNext();) { Object candidate = it.next(); if (!target.contains(candidate)) { result.add(candidate); } } return result; }
From source file:Main.java
public static <T> void add_news(Collection<T> target, Collection<? extends T> to_add) { for (Iterator<? extends T> it = to_add.iterator(); it.hasNext();) { T element = it.next();// w ww .ja v a 2s . c o m if (!target.contains(element)) target.add(element); } }
From source file:com.evolveum.midpoint.model.common.expression.ExpressionTestUtil.java
public static ExpressionFactory createInitializedExpressionFactory(ObjectResolver resolver, ProtectorImpl protector, PrismContext prismContext, SecurityContextManager securityContextManager, RepositoryService repositoryService) { ExpressionFactory expressionFactory = new ExpressionFactory(securityContextManager, prismContext, LocalizationTestUtil.getLocalizationService()); expressionFactory.setObjectResolver(resolver); // NOTE: we need to register the evaluator factories to expressionFactory manually here // this is not spring-wired test. PostConstruct methods are not invoked here // asIs/*from w w w . j a v a 2 s . c o m*/ AsIsExpressionEvaluatorFactory asIsFactory = new AsIsExpressionEvaluatorFactory(prismContext, protector); expressionFactory.registerEvaluatorFactory(asIsFactory); expressionFactory.setDefaultEvaluatorFactory(asIsFactory); // value LiteralExpressionEvaluatorFactory valueFactory = new LiteralExpressionEvaluatorFactory(prismContext); expressionFactory.registerEvaluatorFactory(valueFactory); // const ConstantsManager constManager = new ConstantsManager(createConfiguration()); ConstExpressionEvaluatorFactory constFactory = new ConstExpressionEvaluatorFactory(protector, constManager, prismContext); expressionFactory.registerEvaluatorFactory(constFactory); // path PathExpressionEvaluatorFactory pathFactory = new PathExpressionEvaluatorFactory(expressionFactory, prismContext, protector); pathFactory.setObjectResolver(resolver); expressionFactory.registerEvaluatorFactory(pathFactory); // generate ValuePolicyProcessor valuePolicyGenerator = new ValuePolicyProcessor(); valuePolicyGenerator.setExpressionFactory(expressionFactory); GenerateExpressionEvaluatorFactory generateFactory = new GenerateExpressionEvaluatorFactory( expressionFactory, protector, valuePolicyGenerator, prismContext); generateFactory.setObjectResolver(resolver); expressionFactory.registerEvaluatorFactory(generateFactory); // script Collection<FunctionLibrary> functions = new ArrayList<>(); functions.add(FunctionLibraryUtil.createBasicFunctionLibrary(prismContext, protector)); functions.add(FunctionLibraryUtil.createLogFunctionLibrary(prismContext)); ScriptExpressionFactory scriptExpressionFactory = new ScriptExpressionFactory(prismContext, protector, repositoryService); scriptExpressionFactory.setObjectResolver(resolver); scriptExpressionFactory.setFunctions(functions); XPathScriptEvaluator xpathEvaluator = new XPathScriptEvaluator(prismContext); scriptExpressionFactory.registerEvaluator(XPathScriptEvaluator.XPATH_LANGUAGE_URL, xpathEvaluator); Jsr223ScriptEvaluator groovyEvaluator = new Jsr223ScriptEvaluator("Groovy", prismContext, protector, LocalizationTestUtil.getLocalizationService()); scriptExpressionFactory.registerEvaluator(groovyEvaluator.getLanguageUrl(), groovyEvaluator); ScriptExpressionEvaluatorFactory scriptExpressionEvaluatorFactory = new ScriptExpressionEvaluatorFactory( scriptExpressionFactory, securityContextManager); expressionFactory.registerEvaluatorFactory(scriptExpressionEvaluatorFactory); return expressionFactory; }
From source file:Main.java
/** * Merge the given array into the given Collection. * @param <T> type of elements of array * @param array the array to merge (may be <code>null</code>) * @param collection the target Collection to merge the array into *//* ww w . j av a 2s . c om*/ public static <T> void mergeArrayIntoCollection(T[] array, Collection<T> collection) { if (collection == null) { throw new IllegalArgumentException("Collection must not be null"); } for (int i = 0; i < array.length; i++) { collection.add(array[i]); } }
From source file:Main.java
/** * /*w ww.j a va 2s . co m*/ * @param value * @return Object[] */ public static Object[] toArray(final String value) { if (value == null) { return new Object[] {}; } final int BRACKET_LENGTH = 1; final String strippedValue = value.substring(BRACKET_LENGTH, value.length() - BRACKET_LENGTH); final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR); final Collection<Object> collection = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { collection.add(tokenizer.nextToken().trim()); } return collection.toArray(); }
From source file:Main.java
/** * Adds an element to the collection unless the element is null. * * @param <T> the type of object the {@link Collection} contains * @param collection the collection to add to, must not be null * @param object the object to add, if null it will not be added * @return true if the collection changed * @throws NullPointerException if the collection is null * @since 3.2//from w ww .ja v a 2 s . c om */ public static <T> boolean addIgnoreNull(final Collection<T> collection, final T object) { if (collection == null) { throw new NullPointerException("The collection must not be null"); } return object != null && collection.add(object); }