List of usage examples for com.google.common.collect Collections2 transform
public static <F, T> Collection<T> transform(Collection<F> fromCollection, Function<? super F, T> function)
From source file:org.caleydo.view.domino.api.model.typed.MultiTypedSet.java
public TypedList sliceList(IDType idType) { int index = index(idType); if (index < 0) return new TypedList(RepeatingList.repeat(INVALID_ID, size()), idType); return new TypedList(ImmutableList.copyOf(Collections2.transform(ids, slice(index))), idType); }
From source file:de.cosmocode.palava.store.MemoryStore.java
@Override public Set<String> list() throws IOException { return Sets.newHashSet(Collections2.transform(map.keySet(), Functions.toStringFunction())); }
From source file:org.fao.geonet.services.harvesting.HistoryDelete.java
public Element exec(Element params, ServiceContext context) throws Exception { long nrRecs = 0; final HarvestHistoryRepository historyRepository = context.getBean(HarvestHistoryRepository.class); String uuid = Util.getParam(params, "uuid"); if (uuid != null) { final Specification<HarvestHistory> hasHarvesterUuid = HarvestHistorySpecs.hasHarvesterUuid(uuid); nrRecs = historyRepository.count(hasHarvesterUuid); historyRepository.deleteAll(hasHarvesterUuid); } else {/*from www. j a v a2 s .c o m*/ Collection<Integer> ids = Collections2.transform(params.getChildren("id"), new Function<Object, Integer>() { @Nullable @Override public Integer apply(@Nonnull Object input) { return Integer.valueOf(((Element) input).getText()); } }); List<Element> files = params.getChildren("file"); for (Element file : files) { try { File f = new File(file.getTextTrim()); if (f.exists() && f.canWrite()) { if (!f.delete()) { org.fao.geonet.utils.Log.warning(Geonet.HARVESTER, "Removing history. Failed to delete file: " + f.getCanonicalPath()); } } } catch (Exception e) { e.printStackTrace(); } } if (!ids.isEmpty()) { nrRecs = historyRepository.deleteAllById(ids); } } return new Element(Jeeves.Elem.RESPONSE).setText(nrRecs + ""); }
From source file:de.cosmocode.palava.workqueue.ConfigurableDelayQueue.java
@Override public Object[] toArray() { return Collections2.transform(queue, extractor).toArray(); }
From source file:com.textocat.textokit.commons.cpe.XmiCollectionReader.java
@Override protected Iterable<Resource> getResources(UimaContext ctx) throws IOException, ResourceInitializationException { // if input directory does not exist or is not a directory, throw exception if (!inputDir.isDirectory()) { throw new ResourceInitializationException(ResourceConfigurationException.DIRECTORY_NOT_FOUND, new Object[] { PARAM_INPUTDIR, this.getMetaData().getName(), inputDir.getPath() }); }/*from w w w . ja va2 s . c o m*/ // get list of .xmi files in the specified directory Collection<File> mFiles = FileUtils.listFiles(inputDir, suffixFileFilter(".xmi"), trueFileFilter()); xmiResources = Collections2.transform(mFiles, PUtils.file2Resource); return xmiResources; }
From source file:org.csstudio.domain.common.strings.Strings.java
/** * Splits a string into substring on a separating character. Ignores those separators in * within the ignore char (typically a quote '"') and those separators following on each other. * Result strings are trimmed, which may result in empty strings. * * @param source//from w w w. ja v a 2 s .co m * @param sep * @param trim * @return */ public static Collection<String> splitIgnoreWithinQuotesTrimmed(final String source, final char sep, final char trim) { return Collections2.transform(splitIgnoreWithinQuotes(source, sep), new Function<String, String>() { @Override public String apply(final String input) { return Strings.trim(input, trim); } }); }
From source file:com.hortonworks.registries.schemaregistry.webservice.SchemaRegistryModule.java
private Collection<? extends SchemaProvider> getSchemaProviders() { Collection<Map<String, Object>> schemaProviders = (Collection<Map<String, Object>>) config .get(SCHEMA_PROVIDERS);//w w w .ja v a 2 s. co m if (schemaProviders == null || schemaProviders.isEmpty()) { throw new IllegalArgumentException( "No [" + SCHEMA_PROVIDERS + "] property is configured in schema registry configuration file."); } return Collections2.transform(schemaProviders, new Function<Map<String, Object>, SchemaProvider>() { @Nullable @Override public SchemaProvider apply(@Nullable Map<String, Object> schemaProviderConfig) { String className = (String) schemaProviderConfig.get("providerClass"); if (className == null || className.isEmpty()) { throw new IllegalArgumentException( "Schema provider class name must be non empty, Invalid provider class name [" + className + "]"); } try { SchemaProvider schemaProvider = (SchemaProvider) Class .forName(className, true, Thread.currentThread().getContextClassLoader()).newInstance(); schemaProvider.init(schemaProviderConfig); return schemaProvider; } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { LOG.error("Error encountered while loading SchemaProvider [{}] ", className, e); throw new IllegalArgumentException(e); } } }); }
From source file:org.eclipse.emf.compare.uml2.ide.tests.util.ProfileTestUtil.java
/** * Creates a {@link StorageTraversal} holding the {@link IStorage}s that are pointed by the parameter. * //from www . ja v a2 s . c om * @param stringURIs * String uri of the resouce that need to be wrapped in {@link IStorage}s. * @return {@link StorageTraversal}. */ public static StorageTraversal createStorageTraversal(String... stringURIs) { Collection<IStorage> storages = Collections2.transform(Lists.newArrayList(stringURIs), toStorage(new ExtensibleURIConverterImpl())); StorageTraversal storageTraversal = new StorageTraversal(Sets.newHashSet(storages)); return storageTraversal; }
From source file:org.terasology.assets.AbstractFragmentDataProducer.java
@Override public Set<Name> getModulesProviding(Name resourceName) { if (resolveModuleFromRoot) { return ImmutableSet .copyOf(Collections2.transform(assetManager.resolve(resourceName.toString(), rootAssetType), new Function<ResourceUrn, Name>() { @Nullable//w w w .j a va2s . c o m @Override public Name apply(ResourceUrn input) { return input.getModuleName(); } })); } else { return Collections.emptySet(); } }
From source file:fr.inria.astor.core.loop.evolutionary.JUnitRunner.java
@Override public Result call() throws Exception { JUnitCore runner = new JUnitCore(); for (RunListener listener : this.listeners) { runner.addListener(listener);//from ww w .j a v a 2s. co m } System.err.println("Thread id " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); Class<?>[] testClasses = Collections2.transform(asList(this.classes), StringToClass.INSTANCE) .toArray(new Class<?>[this.classes.length]); return runner.run(testClasses); }