List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:com.cloudmine.api.rest.JsonUtilities.java
public static <CMOBJECT extends CMObject> String cmobjectsToJson(Collection<CMOBJECT> objects) throws ConversionException { if (objects == null || objects.size() == 0) { return EMPTY_JSON; }/*from w w w . j a va2 s . c o m*/ return cmobjectsToJson(objects.toArray(new CMObject[objects.size()])); }
From source file:com.l2jfree.util.L2Collections.java
public static <T> T[] toArray(Collection<? extends T> c, Class<T> clazz) { return c.toArray((T[]) Array.newInstance(clazz, c.size())); }
From source file:com.unboundid.scim2.common.utils.SchemaUtils.java
/** * Gets SCIM schema attributes for a class. * * @param classesProcessed a stack containing the classes processed prior * to this class. This is used for cycle detection. * @param cls the class to get the attributes for. * @return a collection of SCIM schema attributes for the class. * @throws IntrospectionException thrown if an error occurs during * Introspection.//from ww w . j ava 2s. co m */ private static Collection<AttributeDefinition> getAttributes(final Stack<String> classesProcessed, final Class<?> cls) throws IntrospectionException { String className = cls.getCanonicalName(); if (!cls.isAssignableFrom(AttributeDefinition.class) && classesProcessed.contains(className)) { throw new RuntimeException("Cycles detected in Schema"); } Collection<PropertyDescriptor> propertyDescriptors = getPropertyDescriptors(cls); Collection<AttributeDefinition> attributes = new ArrayList<AttributeDefinition>(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (propertyDescriptor.getName().equals("subAttributes") && cls.isAssignableFrom(AttributeDefinition.class) && classesProcessed.contains(className)) { // Skip second nesting of subAttributes the second time around // since there is no subAttributes of subAttributes in SCIM. continue; } AttributeDefinition.Builder attributeBuilder = new AttributeDefinition.Builder(); Field field = findField(cls, propertyDescriptor.getName()); if (field == null) { continue; } Attribute schemaProperty = null; JsonProperty jsonProperty = null; if (field.isAnnotationPresent(Attribute.class)) { schemaProperty = field.getAnnotation(Attribute.class); } if (field.isAnnotationPresent(JsonProperty.class)) { jsonProperty = field.getAnnotation(JsonProperty.class); } // Only generate schema for annotated fields. if (schemaProperty == null) { continue; } addName(attributeBuilder, propertyDescriptor, jsonProperty); addDescription(attributeBuilder, schemaProperty); addCaseExact(attributeBuilder, schemaProperty); addRequired(attributeBuilder, schemaProperty); addReturned(attributeBuilder, schemaProperty); addUniqueness(attributeBuilder, schemaProperty); addReferenceTypes(attributeBuilder, schemaProperty); addMutability(attributeBuilder, schemaProperty); addMultiValued(attributeBuilder, propertyDescriptor, schemaProperty); addCanonicalValues(attributeBuilder, schemaProperty); Class propertyCls = propertyDescriptor.getPropertyType(); // if this is a multivalued attribute the real sub attribute class is the // the one specified in the annotation, not the list, set, array, etc. if ((schemaProperty.multiValueClass() != NullType.class)) { propertyCls = schemaProperty.multiValueClass(); } AttributeDefinition.Type type = getAttributeType(propertyCls); attributeBuilder.setType(type); if (type == AttributeDefinition.Type.COMPLEX) { // Add this class to the list to allow cycle detection classesProcessed.push(cls.getCanonicalName()); Collection<AttributeDefinition> subAttributes = getAttributes(classesProcessed, propertyCls); attributeBuilder .addSubAttributes(subAttributes.toArray(new AttributeDefinition[subAttributes.size()])); classesProcessed.pop(); } attributes.add(attributeBuilder.build()); } return attributes; }
From source file:com.l2jfree.util.L2Collections.java
public static <T> T[] toArraySynchronized(Collection<? extends T> c, Class<T> clazz) { synchronized (c) { return c.toArray((T[]) Array.newInstance(clazz, c.size())); }/*from w ww . j av a 2 s .c o m*/ }
From source file:com.microsoft.tfs.core.clients.framework.location.internal.LocationCacheManager.java
/** * Convert the specified AccessMapping HashMap to an array of * AccessMappings./*from w w w .j a va 2 s . co m*/ * * @param accessMappingsMap * The HashMap containing the AccessMappings. * * @return An array containing each AccessMapping value from the map. */ private static AccessMapping[] accessMappingMapToArray(final Map<String, AccessMapping> accessMappingsMap) { final Collection<AccessMapping> values = accessMappingsMap.values(); return values.toArray(new AccessMapping[values.size()]); }
From source file:edu.stanford.muse.index.EmailDocument.java
/** recompute own email addrs, and then all the contacts. to be done after fetching all messages */ public static AddressBook buildAddressBook(Collection<EmailDocument> docs, Collection<String> ownAddrs, Collection<String> ownNames) { String[] ownAddrsArray = new String[ownAddrs.size()]; ownAddrs.toArray(ownAddrsArray); String[] ownNamesArray = new String[ownNames.size()]; ownNames.toArray(ownNamesArray);//from w w w.jav a 2 s.c o m AddressBook addressBook = new AddressBook(ownAddrsArray, ownNamesArray); // log.info("Own addresses: " + EmailUtils.emailAddrsToString(ownAddrs)); EmailFetcherThread.log.debug("First pass processing contacts for " + docs.size() + " messages"); // 2 passes here: first pass just to unify and find all own email addrs for (EmailDocument ed : docs) addressBook.processContactsFromMessage(ed); addressBook.organizeContacts(); // ownAddrs = addressBook.computeAllAddrsFor(ownAddrs); // log.info ("All my email addrs: "); // for (String s: ownAddrs) // log.info (s); // now look for the real contacts, creating a new contacts set object // reporcess all messages because we may have misclassified messages wrt sent/received in the first round EmailFetcherThread.log.debug("Second pass processing contacts for " + docs.size() + " messages"); // AddressBook newCS = addressBook.deepClone(); addressBook.resetCounts(); for (EmailDocument ed : docs) addressBook.processContactsFromMessage(ed); addressBook.organizeContacts(); return addressBook; }
From source file:org.opencredo.demos.twityourl.TwitYourl.java
private static TwitterStreamConfiguration parseCommandLine(String[] args) { try {/*w w w .j a va2s . co m*/ Collection<String> followIds = null; Collection<String> trackKeywords = null; String[] credentials = args[0].split(":"); Collection<String> list = null; for (int i = 1; i < args.length; i++) { String arg = args[i]; if (arg.equals("-f")) { followIds = new ArrayList<String>(); list = followIds; } else if (arg.equals("-t")) { trackKeywords = new ArrayList<String>(); list = trackKeywords; } else { list.add(arg); } } if (followIds != null) { return new FilterTwitterStreamConfiguration(new TwitterCredentials(credentials[0], credentials[1]), followIds.toArray(new String[followIds.size()]), (trackKeywords == null) ? null : trackKeywords.toArray(new String[trackKeywords.size()]), 0); } else { return new TwitterStreamConfiguration(new TwitterCredentials(credentials[0], credentials[1])); } } catch (Exception e) { System.err.println("Usage: Example username:password ... [-f twitter_id ...] [-t keyword]"); System.exit(1); return null; } }
From source file:com.opendoorlogistics.core.utils.strings.Strings.java
public static String toCommas(Collection<String> strs) { return toCommas(strs.toArray(new String[strs.size()])); }
From source file:edu.cuny.cat.Game.java
public static void startTraders(final Collection<? extends TraderClient> traderColl) { if (traderColl == null) { return;//from ww w . j av a 2 s . co m } Game.logger.info("\n"); Game.logger.info("starting traders ..."); Game.logger.info("\n"); final TraderClient traders[] = traderColl.toArray(new TraderClient[0]); for (final TraderClient trader : traders) { if ((Galaxy.getInstance().getTyped(Game.P_CAT, CatpInfrastructure.class)).isSynchronous()) { Game.clientSynchronizer.countMe(); trader.run(); Game.clientSynchronizer.waitForClients(); } else { /* start a separate thread only when communication is asynchronous */ new Thread(trader).start(); } } }
From source file:edu.cuny.cat.Game.java
public static void startMarkets(final Collection<? extends MarketClient> marketColl) { if (marketColl == null) { return;/* w w w .ja v a 2s. c o m*/ } Game.logger.info("\n"); Game.logger.info("starting markets ..."); Game.logger.info("\n"); final MarketClient markets[] = marketColl.toArray(new MarketClient[0]); for (final MarketClient market : markets) { if (Galaxy.getInstance().getTyped(Game.P_CAT, CatpInfrastructure.class).isSynchronous()) { Game.clientSynchronizer.countMe(); market.run(); Game.clientSynchronizer.waitForClients(); } else { /* start a separate thread only when communication is asynchronous */ new Thread(market).start(); } } }