List of usage examples for com.google.common.collect FluentIterable from
@Deprecated @CheckReturnValue public static <E> FluentIterable<E> from(FluentIterable<E> iterable)
From source file:com.spectralogic.ds3cli.command.CliCommandFactory.java
public static String listAllCommands() { final StringBuilder commandHelp = new StringBuilder("Installed Commands: "); final FluentIterable<String> commands = FluentIterable.from(getAllCommands()) .transform(new Function<CliCommand, String>() { @Nullable//ww w . j a v a 2 s . c om @Override public String apply(@Nullable final CliCommand input) { return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, input.getClass().getSimpleName()); } }); final Joiner joiner = Joiner.on(", "); commandHelp.append(joiner.join(commands)); return commandHelp.toString(); }
From source file:com.facebook.buck.rules.keys.StringifyAlterRuleKey.java
@VisibleForTesting static Iterable<Path> findAbsolutePaths(Object val) { if (val instanceof Path) { Path path = (Path) val; if (path.isAbsolute()) { return Collections.singleton(path); }/*from www . j a va 2 s . com*/ } else if (val instanceof PathSourcePath) { return findAbsolutePaths(((PathSourcePath) val).getRelativePath()); } else if (val instanceof Iterable) { return FluentIterable.from((Iterable<?>) val) .transformAndConcat(StringifyAlterRuleKey::findAbsolutePaths); } else if (val instanceof Map) { Map<?, ?> map = (Map<?, ?>) val; Iterable<?> allSubValues = Iterables.concat(map.keySet(), map.values()); return FluentIterable.from(allSubValues).transformAndConcat(StringifyAlterRuleKey::findAbsolutePaths); } else if (val instanceof Optional) { Optional<?> optional = (Optional<?>) val; if (optional.isPresent()) { return findAbsolutePaths(optional.get()); } } return ImmutableList.of(); }
From source file:org.immutables.value.processor.meta.ExtensionLoader.java
static ImmutableSet<String> findExtensions(String resource) { List<String> annotations = Lists.newArrayList(); ClassLoader classLoader = ExtensionLoader.class.getClassLoader(); try {/* w w w.j av a2 s. c o m*/ Enumeration<URL> resources = classLoader.getResources(resource); while (resources.hasMoreElements()) { URL nextElement = resources.nextElement(); String lines = Resources.toString(nextElement, StandardCharsets.UTF_8); annotations.addAll(RESOURCE_SPLITTER.splitToList(lines)); } } catch (IOException cannotReadFromClasspath) { // we ignore this as we did or best effort // and there are no plans to halt whole compilation } return FluentIterable.from(annotations).toSet(); }
From source file:com.arpnetworking.utility.SampleUtils.java
/** * Converts all of the samples to a single unit. * * @param samples samples to convert//from ww w. j a va 2 s. c o m * @return list of samples with a unified unit */ public static List<Quantity> unifyUnits(final List<Quantity> samples) { //This is a 2-pass operation: //First pass is to grab the smallest unit in the samples //Second pass is to convert everything to that unit Optional<Unit> smallestUnit = Optional.absent(); for (final Quantity sample : samples) { if (!smallestUnit.isPresent()) { smallestUnit = sample.getUnit(); } else if (sample.getUnit().isPresent() && smallestUnit.get().getSmallerUnit(sample.getUnit().get()) != smallestUnit.get()) { smallestUnit = sample.getUnit(); } } if (smallestUnit.isPresent()) { return FluentIterable.from(samples).transform(new SampleConverter(smallestUnit.get())).toList(); } return samples; }
From source file:org.sfs.util.ConfigHelper.java
public static Iterable<String> getArrayFieldOrEnv(JsonObject config, String name, Iterable<String> defaultValue) { String envVar = formatEnvVariable(name); //USED_ENV_VARS.add(envVar); if (config.containsKey(name)) { JsonArray values = config.getJsonArray(name); if (values != null) { Iterable<String> iterable = FluentIterable.from(values).filter(Predicates.notNull()) .filter(input -> input instanceof String).transform(input -> input.toString()); log(name, envVar, name, iterable); return iterable; }//from ww w . j av a2s .co m } else { String value = System.getenv(envVar); if (value != null) { log(name, envVar, envVar, value); return Splitter.on(',').split(value); } } log(name, envVar, null, defaultValue); return defaultValue; }
From source file:org.eclipse.buildship.core.configuration.GradleProjectBuilder.java
/** * Configures the builder on the target project if it was not added previously. * <p/>//from www . j a v a 2 s.c om * This method requires the {@link org.eclipse.core.resources.IWorkspaceRoot} scheduling rule. * * @param project the target project */ public static void configureOnProject(IProject project) { try { Preconditions.checkState(project.isOpen()); // check if the builder is already registered with the project IProjectDescription description = project.getDescription(); List<ICommand> buildSpecs = Arrays.asList(description.getBuildSpec()); boolean exists = FluentIterable.from(buildSpecs).anyMatch(new Predicate<ICommand>() { @Override public boolean apply(ICommand command) { return command.getBuilderName().equals(ID); } }); // register the builder with the project if it is not already registered if (!exists) { ICommand buildSpec = description.newCommand(); buildSpec.setBuilderName(ID); ImmutableList<ICommand> newBuildSpecs = ImmutableList.<ICommand>builder().addAll(buildSpecs) .add(buildSpec).build(); description.setBuildSpec(newBuildSpecs.toArray(new ICommand[newBuildSpecs.size()])); project.setDescription(description, new NullProgressMonitor()); } } catch (CoreException e) { CorePlugin.logger() .error(String.format("Failed to add Gradle Project Builder to project %s.", project.getName())); } }
From source file:google.registry.export.ExportConstants.java
/** Returns the names of kinds to import into reporting tools (e.g. BigQuery). */ public static ImmutableSet<String> getReportingKinds() { return FluentIterable.from(EntityClasses.ALL_CLASSES).filter(hasAnnotation(ReportedOn.class)) .filter(not(hasAnnotation(VirtualEntity.class))).transform(CLASS_TO_KIND_FUNCTION) .toSortedSet(Ordering.natural()); }
From source file:org.androidtransfuse.model.r.RResourceComposite.java
public RResourceComposite(RResource... resources) { this.resources = FluentIterable.from(Arrays.asList(resources)).filter(Predicates.notNull()).toList(); }
From source file:ec.nbdemetra.ui.nodes.Nodes.java
@Nonnull public static FluentIterable<Node> breadthFirstIterable(@Nonnull Node root) { return FluentIterable.from(root.isLeaf() ? Collections.singleton(root) : new BreadthFirstIterable(root)); }
From source file:com.brighttag.agathon.resources.ServiceUnavailableExceptionMapper.java
private static String getMessage(Throwable exception) { String name = NAME_JOINER//from w ww .ja va 2 s . com .join(FluentIterable.from(Throwables.getCausalChain(exception)).transform(EXCEPTION_NAME).toList()); Throwable rootCause = Throwables.getRootCause(exception); return String.format("%s: %s", name, rootCause.getMessage()); }