List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:com.marklogic.entityservices.tests.TestEntityTypes.java
@Test public void testInvalidEntityTypes() throws URISyntaxException { URL sourcesFilesUrl = client.getClass().getResource("/invalid-models"); @SuppressWarnings("unchecked") Collection<File> invalidEntityTypeFiles = FileUtils.listFiles(new File(sourcesFilesUrl.getPath()), FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter()); Set<String> invalidEntityTypes = new HashSet<String>(); JSONDocumentManager docMgr = client.newJSONDocumentManager(); DocumentWriteSet writeSet = docMgr.newWriteSet(); for (File f : invalidEntityTypeFiles) { if (f.getName().startsWith(".")) { continue; }//from ww w. j av a 2s. c o m ; if (!(f.getName().endsWith(".json") || f.getName().endsWith(".xml"))) { continue; } ; logger.info("Loading " + f.getName()); writeSet.add(f.getName(), new FileHandle(f)); invalidEntityTypes.add(f.getName()); } docMgr.write(writeSet); for (String entityType : invalidEntityTypes) { logger.info("Checking invalid: " + entityType); @SuppressWarnings("unused") JacksonHandle handle = null; try { handle = evalOneResult("es:model-validate(fn:doc('" + entityType.toString() + "'))", new JacksonHandle()); fail("eval should throw an exception for invalid cases." + entityType); } catch (TestEvalException e) { assertTrue("Must contain invalidity message. Message was " + e.getMessage(), e.getMessage().contains("ES-MODEL-INVALID")); assertTrue("Message must be expected one for " + entityType.toString() + ". Was " + e.getMessage(), e.getMessage().contains(invalidMessages.get(entityType))); // check once more for validating map representation if (entityType.endsWith(".json")) { try { handle = evalOneResult( "es:model-validate(xdmp:fron-json(fn:doc('" + entityType.toString() + "')))", new JacksonHandle()); fail("eval should throw an exception for invalid cases." + entityType); } catch (TestEvalException e1) { // pass } } } } logger.info("Cleaning up invalid types"); Collection<String> names = new ArrayList<String>(); invalidEntityTypeFiles.forEach(f -> { names.add(f.getName()); }); docMgr.delete(names.toArray(new String[] {})); }
From source file:io.mindmaps.engine.loader.DistributedLoader.java
public DistributedLoader(String graphNameInit, Collection<String> hosts) { ConfigProperties prop = ConfigProperties.getInstance(); batchSize = prop.getPropertyAsInt(ConfigProperties.BATCH_SIZE_PROPERTY); graphName = graphNameInit;// w w w. j av a 2 s . c om batch = new HashSet<>(); hostsArray = hosts.toArray(new String[hosts.size()]); currentHost = 0; pollingFrequency = 30000; threadsNumber = prop.getAvailableThreads() * 3; // create availability map availability = new HashMap<>(); hosts.forEach(h -> availability.put(h, new Semaphore(threadsNumber))); jobsTerminated = new HashMap<>(); hosts.forEach(h -> jobsTerminated.put(h, 0)); }
From source file:io.mindmaps.loader.DistributedLoader.java
public DistributedLoader(String graphNameInit, Collection<String> hosts) { ConfigProperties prop = ConfigProperties.getInstance(); batchSize = prop.getPropertyAsInt(ConfigProperties.BATCH_SIZE_PROPERTY); graphName = graphNameInit;//from w w w . j a v a2 s. c o m batch = new HashSet<>(); hostsArray = hosts.toArray(new String[hosts.size()]); currentHost = 0; pollingFrequency = 30000; threadsNumber = prop.getPropertyAsInt(ConfigProperties.NUM_THREADS_PROPERTY) * 3; // create availability map availability = new HashMap<>(); hosts.forEach(h -> availability.put(h, new Semaphore(threadsNumber))); jobsTerminated = new HashMap<>(); hosts.forEach(h -> jobsTerminated.put(h, 0)); }
From source file:com.nextep.designer.synch.model.impl.ReverseSynchronizationContext.java
/** * Builds a new {@link ReverseSynchronizationContext} from the current state of a * {@link ISynchronizationResult}./* www . j av a 2 s.co m*/ * * @param synchronizationResult */ @SuppressWarnings("unchecked") public ReverseSynchronizationContext(ISynchronizationResult synchronizationResult) { this.synchResult = synchronizationResult; final Collection<IComparisonItem> items = synchronizationResult.getComparedItems(); // Building external references map sourceRefMap = SynchronizationHelper .buildSourceReferenceMapping(items.toArray(new IComparisonItem[items.size()])); // Building the list of versionable to import / remove, hashing them versionsToImport = new ArrayList<IVersionable<?>>(); versionsToRemove = new ArrayList<IVersionable<?>>(); versionsToUpdateOrDelete = new ArrayList<IVersionable<?>>(); versionableItemsMap = new HashMap<IVersionable<?>, IComparisonItem>(); for (final IComparisonItem item : items) { if (item.getDifferenceType() != DifferenceType.EQUALS) { if (shouldImport(item)) { if (item.getDifferenceType() != DifferenceType.MISSING_SOURCE) { final IVersionable<?> v = (IVersionable<?>) item.getSource(); versionsToImport.add(v); versionableItemsMap.put(v, item); if (item.getDifferenceType() == DifferenceType.DIFFER) { versionsToUpdateOrDelete.add((IVersionable<?>) item.getTarget()); } } else { final IVersionable<?> v = (IVersionable<?>) item.getTarget(); versionsToRemove.add(v); versionableItemsMap.put(v, item); // Deleted item we need to monitor versionsToUpdateOrDelete.add(v); } } } } itemsToSynchronize = new ArrayList<IComparisonItem>(versionableItemsMap.values()); // Checking external references which would be created by the removal of one item deletedReferencers = new ArrayList<IReferencer>(); fillDeletedReferencersList(itemsToSynchronize, deletedReferencers); // Retrieving reverse references map revDependencyMap = CorePlugin.getService(IReferenceManager.class).getReverseDependenciesMap(); // Hashing items by their target value Map<Object, IComparisonItem> itemsTargetMap = hashItemsByTarget(new HashMap<Object, IComparisonItem>(), itemsToSynchronize); // Processing reverse dependencies for (Object o : new ArrayList<IReferencer>(revDependencyMap.keySet())) { @SuppressWarnings("rawtypes") final Collection invRefs = revDependencyMap.getCollection(o); for (IReferencer referencer : new ArrayList<IReferencer>(invRefs)) { // If the referencer is not a database object we don't want to consider it (=> // Diagram ?) if (!(referencer instanceof IDatabaseObject<?>)) { revDependencyMap.remove(o, referencer); } else { // Locating our referencer as a comparison item IComparisonItem correspondingItem = itemsTargetMap.get(referencer); if (correspondingItem != null) { // Retrieving corresponding proposal final Object proposal = correspondingItem.getMergeInfo().getMergeProposal(); if (correspondingItem.getDifferenceType() != DifferenceType.DIFFER && proposal == null) { // The referencer will be removed, we remove dependency revDependencyMap.remove(o, referencer); } else if (proposal != referencer) { // The referencer is not the proposal, so the dependency is valid only // if the reference (o) is a merge proposal, if not we remove dependency if (!isMergeProposal(correspondingItem, o)) { revDependencyMap.remove(o, referencer); } } } } } } // Checking if we are importing in an empty view final IWorkspace workspace = VCSPlugin.getService(IWorkspaceService.class).getCurrentWorkspace(); final Collection<IReferenceable> contents = workspace.getReferenceMap().values(); if (!synchronizationResult.isDataSynchronization()) { // We do not check external references when importing into an empty workspace or into a // workspace with a unique database module if (contents.isEmpty() || (contents.size() == 1 && contents.iterator().next() instanceof IVersionContainer)) { externalCheck = false; importPolicy = new ImportPolicyEmptyView(); initialImport = true; } else { externalCheck = true; importPolicy = ImportPolicyAddOnly.getInstance(); } } else { // A specific policy to import datasets externalCheck = false; importPolicy = new ImportPolicyAddDataSet(); } }
From source file:at.ac.tuwien.infosys.jcloudscale.test.unit.TestReflectionUtil.java
@Test public void testGetClassesFromNames() throws ClassNotFoundException { Set<Class<?>> types = new HashSet<>(Primitives.allPrimitiveTypes()); types.addAll(Primitives.allWrapperTypes()); Collection<String> typeNames = transform(types, new Function<Class<?>, String>() { @Override/* ww w .j ava 2 s.c o m*/ public String apply(Class<?> input) { return input.getName(); } }); List<Class<?>> classes = Arrays.asList( getClassesFromNames(typeNames.toArray(new String[typeNames.size()]), getSystemClassLoader())); assertEquals(types.size(), classes.size()); assertEquals(true, classes.containsAll(Primitives.allPrimitiveTypes())); assertEquals(true, classes.containsAll(Primitives.allWrapperTypes())); }
From source file:de.fau.cs.osr.hddiff.perfsuite.RunFcDiff.java
private boolean compareAttributes(Collection<Wom3Attribute> a, Collection<Wom3Attribute> b) { final int size = a.size(); Wom3Attribute[] aa = a.toArray(new Wom3Attribute[size]); Wom3Attribute[] ba = b.toArray(new Wom3Attribute[b.size()]); Comparator<Wom3Attribute> cmp = new Comparator<Wom3Attribute>() { @Override// w w w .jav a 2 s. c o m public int compare(Wom3Attribute o1, Wom3Attribute o2) { return o1.getName().compareTo(o2.getName()); } }; Arrays.sort(aa, cmp); Arrays.sort(ba, cmp); for (int i = 0, j = 0; i < aa.length && j < ba.length;) { Wom3Attribute attrA = aa[i]; Wom3Attribute attrB = ba[i]; if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attrA.getNamespaceURI()) && XMLConstants.XMLNS_ATTRIBUTE.equals(attrA.getName())) { ++i; continue; } if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attrB.getNamespaceURI()) && XMLConstants.XMLNS_ATTRIBUTE.equals(attrB.getName())) { ++j; continue; } if (!cmpStr(attrA.getName(), attrB.getName())) { return false; } if (!cmpStr(attrA.getValue(), attrB.getValue())) { return false; } ++i; ++j; } return true; }
From source file:io.fabric8.vertx.maven.plugin.mojos.AbstractRunMojo.java
/** * This will build the {@link URLClassLoader} object from the collection of classpath URLS * * @param classPathUrls - the classpath urls which will be used to build the {@link URLClassLoader} * @return an instance of {@link URLClassLoader} *//*ww w .jav a2s . c o m*/ protected ClassLoader buildClassLoader(Collection<URL> classPathUrls) { return new URLClassLoader(classPathUrls.toArray(new URL[classPathUrls.size()])); }
From source file:com.opengamma.engine.calcnode.CalculationJobItem.java
public CalculationJobItem(String functionUniqueIdentifier, FunctionParameters functionParameters, ComputationTargetSpecification computationTargetSpecification, Collection<ValueSpecification> inputs, Collection<ValueSpecification> outputs, ExecutionLogMode logMode) { ArgumentChecker.notNull(logMode, "logMode"); _functionUniqueIdentifier = functionUniqueIdentifier; _functionParameters = functionParameters; _computationTargetSpecification = computationTargetSpecification; _inputSpecifications = inputs.toArray(new ValueSpecification[inputs.size()]); _outputSpecifications = outputs.toArray(new ValueSpecification[outputs.size()]); _logMode = logMode;/* w ww. ja v a2s.co m*/ }
From source file:com.microsoft.tfs.client.common.repository.cache.pendingchange.PendingChangeCollection.java
/** * @return all of the pending changes currently held by this collection *//* w ww .ja v a2 s.c om*/ public PendingChange[] getValues() { /* * The conversion to an array must happen inside the lock because the * lock covers the values in the map. */ synchronized (lock) { final Collection<PendingChange> values = changesByServerPath.values(); if (values == null) { return new PendingChange[0]; } return values.toArray(new PendingChange[values.size()]); } }
From source file:com.sunchenbin.store.feilong.core.bean.ConvertUtil.java
/** * ??.// w ww. ja va 2s. com * * @param <T> * the generic type * @param collection * collection * @param arrayComponentType * Class * @return ,if null == collection or arrayClass == null,return NullPointerException * @see java.lang.reflect.Array#newInstance(Class, int) * @see java.lang.reflect.Array#newInstance(Class, int...) * @see java.util.Collection#toArray() * @see java.util.Collection#toArray(Object[]) * @see java.util.List#toArray() * @see java.util.List#toArray(Object[]) * @see java.util.Vector#toArray() * @see java.util.Vector#toArray(Object[]) * @see java.util.LinkedList#toArray() * @see java.util.LinkedList#toArray(Object[]) * @see java.util.ArrayList#toArray() * @see java.util.ArrayList#toArray(Object[]) * @see org.apache.commons.collections4.IteratorUtils#toArray(Iterator,Class) * @since 1.2.2 */ public static <T> T[] toArray(Collection<T> collection, Class<T> arrayComponentType) { if (null == collection) { throw new NullPointerException("collection must not be null"); } if (arrayComponentType == null) { throw new NullPointerException("Array ComponentType must not be null"); } // alength0,???API??size,?. // ?alengthCollectionsize????API?. @SuppressWarnings("unchecked") T[] array = (T[]) Array.newInstance(arrayComponentType, collection.size()); //?,toArray(new Object[0]) toArray() ?. return collection.toArray(array); }