List of usage examples for com.google.common.collect Iterables transform
@CheckReturnValue public static <F, T> Iterable<T> transform(final Iterable<F> fromIterable, final Function<? super F, ? extends T> function)
From source file:ratpack.file.internal.ActivationBackedMimeTypes.java
private static Set<String> extractKnownMimeTypes() { try {/*from www .j a v a 2 s . c om*/ Function<Object, String> getMimeTypeFunction = new GetMimeTypeFunction(); Field typeHashField = makeFieldAccessible(Class.forName("com.sun.activation.registries.MimeTypeFile"), "type_hash"); Field mimeTypeFilesField = makeFieldAccessible(MimetypesFileTypeMap.class, "DB"); Object mimeTypeFiles = mimeTypeFilesField.get(MIME_TYPES_MAP); Set<String> mimeTypes = Sets.newHashSet(); for (int i = 0; i < Array.getLength(mimeTypeFiles); i++) { Object mimeTypeFile = Array.get(mimeTypeFiles, i); if (mimeTypeFile != null) { Map<?, ?> typeHash = (Map) typeHashField.get(mimeTypeFile); Iterables.addAll(mimeTypes, Iterables.transform(typeHash.values(), getMimeTypeFunction)); } } return ImmutableSet.copyOf(mimeTypes); } catch (ReflectiveOperationException | NullPointerException ex) { return ImmutableSet.of(); } }
From source file:io.druid.server.http.InventoryViewUtils.java
public static Set<DruidDataSource> getDataSources(InventoryView serverInventoryView) { TreeSet<DruidDataSource> dataSources = Sets.newTreeSet(new Comparator<DruidDataSource>() { @Override// w w w . j ava 2 s. c o m public int compare(DruidDataSource druidDataSource, DruidDataSource druidDataSource1) { return druidDataSource.getName().compareTo(druidDataSource1.getName()); } }); dataSources .addAll(Lists.newArrayList(Iterables.concat(Iterables.transform(serverInventoryView.getInventory(), new Function<DruidServer, Iterable<DruidDataSource>>() { @Override public Iterable<DruidDataSource> apply(DruidServer input) { return input.getDataSources(); } })))); return dataSources; }
From source file:edu.umn.msi.tropix.webgui.server.CatalogUtils.java
public static String[] getServiceIDsFromSHBeanList(final Iterable<SearchHit> shBeans) { return Iterables.toArray(Iterables.transform(shBeans, ENTRY_ID_FUNCTION), String.class); }
From source file:com.flaptor.indextank.IndexTankTestCase.java
public static Iterable<String> toDocIds(TopMatches result) { return Iterables.transform(result, GET_ID_FUNCTION); }
From source file:com.facebook.buck.rules.args.StringArg.java
public static Iterable<Arg> from(Iterable<String> args) { return Iterables.transform(args, StringArg::new); }
From source file:com.google.errorprone.ErrorPronePlugins.java
public static ScannerSupplier loadPlugins(ScannerSupplier scannerSupplier, Context context) { JavaFileManager fileManager = context.get(JavaFileManager.class); // Search ANNOTATION_PROCESSOR_PATH if it's available. Unlike in annotation processor // discovery, we never search CLASS_PATH. if (!fileManager.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) { return scannerSupplier; }//from w w w. ja v a 2 s . com ClassLoader loader = fileManager.getClassLoader(StandardLocation.ANNOTATION_PROCESSOR_PATH); Iterable<BugChecker> extraBugCheckers = ServiceLoader.load(BugChecker.class, loader); if (Iterables.isEmpty(extraBugCheckers)) { return scannerSupplier; } return scannerSupplier .plus(ScannerSupplier.fromBugCheckerClasses(Iterables.transform(extraBugCheckers, GET_CLASS))); }
From source file:org.onos.yangtools.yang.data.impl.schema.transform.base.serializer.LeafSetNodeBaseSerializer.java
@Override public final Iterable<E> serialize(final LeafListSchemaNode schema, final LeafSetNode<?> node) { return Iterables .concat(Iterables.transform(node.getValue(), new Function<LeafSetEntryNode<?>, Iterable<E>>() { @Override//from w ww.j ava 2 s.co m public Iterable<E> apply(final LeafSetEntryNode<?> input) { final Iterable<E> serializedChild = getLeafSetEntryNodeSerializer().serialize(schema, input); final int size = Iterables.size(serializedChild); Preconditions.checkState(size == 1, "Unexpected count of elements for leaf-list entry serialized from: %s, should be 1, was: %s", input, size); return serializedChild; } })); }
From source file:com.google.devtools.build.lib.analysis.AnalysisPhaseStartedEvent.java
/** * Construct the event./*from w w w . j av a2 s . c o m*/ * @param targets The set of active targets that remain. */ public AnalysisPhaseStartedEvent(Collection<Target> targets) { this.labels = Iterables.transform(targets, new Function<Target, Label>() { @Override public Label apply(Target input) { return input.getLabel(); } }); }
From source file:com.google.gcloud.storage.StorageServiceImpl.java
@Override public Iterable<Bucket> listBuckets() { try {/* w w w.ja v a 2 s . c om*/ return Iterables.transform(storageRpc.buckets(), new Function<com.google.api.services.storage.model.Bucket, Bucket>() { @Override public Bucket apply(com.google.api.services.storage.model.Bucket model) { return new BucketImpl(StorageServiceImpl.this, model); } }); } catch (IOException ex) { throw new StorageServiceException(ex); } }
From source file:com.allogy.mime.MimeGeneratingInputStream.java
public MimeGeneratingInputStream(Iterable<Header> headers, InputStream bodyInputStream) { Iterable<InputStream> inputStreamHeaders = Iterables.transform(headers, new Function<Header, InputStream>() { public InputStream apply(@Nullable Header s) { InputStream headerStream = new ByteArrayInputStream(s.toString().getBytes()); return new SequenceInputStream(headerStream, new ByteArrayInputStream(MimeUtilities.CRLFEnding.getBytes())); }/*from w w w . j a v a2 s .c o m*/ }); InputStream givenHeadersInputStream = new SequenceInputStream( new IteratorEnumeration(inputStreamHeaders.iterator())); InputStream headerInputStream = new SequenceInputStream(givenHeadersInputStream, new ByteArrayInputStream(MimeUtilities.CRLFEnding.getBytes())); innerInputStream = new SequenceInputStream(headerInputStream, bodyInputStream); }