List of usage examples for java.util Collection add
boolean add(E e);
From source file:com.evolveum.midpoint.web.util.WebModelUtils.java
public static Collection<SelectorOptions<GetOperationOptions>> createOptionsForParentOrgRefs() { Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<SelectorOptions<GetOperationOptions>>(); options.add(SelectorOptions.create(ObjectType.F_PARENT_ORG_REF, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE))); return options; }
From source file:de.iteratec.iteraplan.businesslogic.service.ecore.BuildingBlocksToEcoreServiceImpl.java
private static void setEStructuralFeature(EObject instance, EStructuralFeature feature, Object value, Map<?, ?> translation) { if (value == null || (value instanceof Collection && ((Collection<?>) value).isEmpty())) { return;//ww w . ja v a 2s . c om } if (value instanceof Collection) { Collection<Object> values = Lists.newLinkedList(); for (Object v : (Collection<?>) value) { if (translation.containsKey(v)) { values.add(translation.get(v)); } } setEStructuralFeature(instance, feature, values); } else { setEStructuralFeature(instance, feature, translation.get(value)); } }
From source file:com.gc.iotools.fmt.base.TestUtils.java
/** * @deprecated/*from w ww .j a v a 2 s .c om*/ * @see FileUtils#iterate(); * @param allowed * @return * @throws IOException */ @Deprecated public static String[] listFilesIncludingExtension(final String[] allowed) throws IOException { final URL fileURL = TestUtils.class.getResource("/testFiles"); String filePath = URLDecoder.decode(fileURL.getPath(), "UTF-8"); final File dir = new File(filePath); final String[] files = dir.list(); final Collection<String> goodFiles = new Vector<String>(); if (!filePath.endsWith(File.separator)) { filePath = filePath + File.separator; } for (final String file : files) { for (final String element : allowed) { if (file.endsWith(element)) { goodFiles.add(filePath + file); } } } return goodFiles.toArray(new String[goodFiles.size()]); }
From source file:Main.java
public static <V> void get(final Map<?, ? extends V> map, final Collection<? super V> values, final Object... keys) { for (final Object key2 : keys) { final Object key = key2; if (!map.containsKey(key)) { continue; }//w ww .ja va 2 s . c om final V value = map.get(key); values.add(value); } }
From source file:com.basistech.rosette.apimodel.NonNullTest.java
@Parameterized.Parameters(name = "{0}") public static Collection<Object[]> data() throws URISyntaxException, IOException { File dir = new File("src/test/data"); Collection<Object[]> params = new ArrayList<>(); try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir.toPath())) { for (Path file : paths) { if (file.toString().endsWith(".json")) { String className = file.getFileName().toString().replace(".json", ""); params.add(new Object[] { NonNullTest.class.getPackage().getName() + "." + className, file.toFile() }); }//from w w w .ja va 2 s. c om } } return params; }
From source file:com.glaf.core.util.JsonUtils.java
public static Map<String, Object> decode(String str) { Map<String, Object> dataMap = new LinkedHashMap<String, Object>(); if (StringUtils.isNotEmpty(str) && (str.length() > 0 && str.charAt(0) == '{') && str.endsWith("}")) { try {/*from w w w . java2s .c om*/ JSONObject jsonObject = (JSONObject) JSON.parse(str); Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); String key = (String) entry.getKey(); Object value = entry.getValue(); if (value != null) { if (value instanceof Object[]) { Object[] array = (Object[]) value; Collection<Object> collection = new java.util.ArrayList<Object>(); for (int i = 0; i < array.length; i++) { collection.add(array[i]); } dataMap.put(key, collection); } else if (value instanceof JSONArray) { JSONArray array = (JSONArray) value; Collection<Object> collection = new java.util.ArrayList<Object>(); for (int i = 0, len = array.size(); i < len; i++) { collection.add(array.get(i)); } dataMap.put(key, collection); } else if (value instanceof Collection<?>) { Collection<?> collection = (Collection<?>) value; dataMap.put(key, collection); } else if (value instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) value; dataMap.put(key, map); } else { if ((!key.startsWith("x_filter_")) && key.toLowerCase().endsWith("date")) { String datetime = value.toString(); try { java.util.Date date = DateUtils.toDate(datetime); dataMap.put(key, date); } catch (Exception ex) { ex.printStackTrace(); dataMap.put(key, value); } } else { dataMap.put(key, value); } } } } } catch (JSONException ex) { ex.printStackTrace(); } } return dataMap; }
From source file:Main.java
/** * Returns a new collection containing clones of all the items in the * specified collection./*from ww w .j a va 2 s.c om*/ * * @param collection * the collection (<code>null</code> not permitted). * @return A new collection containing clones of all the items in the * specified collection. * @throws CloneNotSupportedException * if any of the items in the collection cannot be cloned. */ public static Collection deepClone(final Collection collection) throws CloneNotSupportedException { if (collection == null) { throw new IllegalArgumentException("Null 'collection' argument."); } // all JDK-Collections are cloneable ... // and if the collection is not clonable, then we should throw // a CloneNotSupportedException anyway ... final Collection result = (Collection) clone(collection); result.clear(); final Iterator iterator = collection.iterator(); while (iterator.hasNext()) { final Object item = iterator.next(); if (item != null) { result.add(clone(item)); } else { result.add(null); } } return result; }
From source file:com.github.strawberry.guice.config.ConfigLoader.java
private static Collection<?> nestedCollectionOf(Field field, Map properties, Set<String> redisKeys) { Collection collection = collectionImplementationOf(field.getType()); for (String redisKey : redisKeys) { collection.add(properties.get(redisKey)); }/*from w ww .ja va 2 s .c o m*/ return collection; }
From source file:com.googlecode.l10nmavenplugin.model.PropertiesFileUtils.java
/** * Regroup identical values by keys// w w w . ja v a 2 s . c o m * * @param <T> * * @param map * @return */ public static <T> Map<T, Collection<PropertiesFile>> reverseMap(Map<PropertiesFile, T> map) { Map<T, Collection<PropertiesFile>> reverseMap = new HashMap<T, Collection<PropertiesFile>>(); for (Entry<PropertiesFile, T> entry : map.entrySet()) { PropertiesFile propertiesFile = entry.getKey(); T parameters = entry.getValue(); Collection<PropertiesFile> matchedPropertiesFiles = reverseMap.get(parameters); if (matchedPropertiesFiles == null) { matchedPropertiesFiles = new HashSet<PropertiesFile>(); reverseMap.put(parameters, matchedPropertiesFiles); } matchedPropertiesFiles.add(propertiesFile); } return reverseMap; }
From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.ServiceDescriptionTests.java
public static Collection<Object[]> getReferencedUrls(String base) throws IOException, XPathException, ParserConfigurationException, SAXException { Properties setupProps = SetupProperties.setup(null); String userId = setupProps.getProperty("userId"); String pw = setupProps.getProperty("pw"); HttpResponse resp = OSLCUtils.getResponseFromUrl(base, base, new UsernamePasswordCredentials(userId, pw), OSLCConstants.CT_DISC_CAT_XML + ", " + OSLCConstants.CT_DISC_DESC_XML); //If our 'base' is a ServiceDescription we don't need to recurse as this is the only one we can find if (resp.getEntity().getContentType().getValue().contains(OSLCConstants.CT_DISC_DESC_XML)) { Collection<Object[]> data = new ArrayList<Object[]>(); data.add(new Object[] { base }); EntityUtils.consume(resp.getEntity()); return data; }/* w w w. j ava 2 s. c om*/ Document baseDoc = OSLCUtils.createXMLDocFromResponseBody(EntityUtils.toString(resp.getEntity())); //ArrayList to contain the urls from all SPCs Collection<Object[]> data = new ArrayList<Object[]>(); //Get all the ServiceDescriptionDocuments from this ServiceProviderCatalog NodeList sDescs = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_disc:services/@rdf:resource", baseDoc, XPathConstants.NODESET); for (int i = 0; i < sDescs.getLength(); i++) { String uri = sDescs.item(i).getNodeValue(); uri = OSLCUtils.absoluteUrlFromRelative(base, uri); data.add(new Object[] { uri }); } //Get all ServiceProviderCatalog urls from the base document in order to recursively add all the //description documents from them as well. NodeList spcs = (NodeList) OSLCUtils.getXPath().evaluate( "//oslc_disc:entry/oslc_disc:ServiceProviderCatalog/@rdf:about", baseDoc, XPathConstants.NODESET); for (int i = 0; i < spcs.getLength(); i++) { String uri = spcs.item(i).getNodeValue(); uri = OSLCUtils.absoluteUrlFromRelative(base, uri); if (!uri.equals(base)) { Collection<Object[]> subCollection = getReferencedUrls(uri); Iterator<Object[]> iter = subCollection.iterator(); while (iter.hasNext()) { data.add(iter.next()); } } } return data; }