List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:io.blobkeeper.common.util.Streams.java
private static <T> Stream<ResultWrapper<T>> collect(List<CompletableFuture<ResultWrapper<T>>> results) { // wait for all operations return allOf(Iterables.toArray(results, CompletableFuture.class)) // TODO: use apply async? .thenApply(ignored -> results.stream().map(CompletableFuture::join).collect(toImmutableList())) .exceptionally(throwable -> { log.error("Can't execute task", throwable); return of(); }).join().stream();//from w w w. j a v a2 s.co m }
From source file:see.properties.impl.MethodResolver.java
@Override public VarArgFunction<Object, ?> get(final Object bean, PropertyAccess property) { final String methodName = property.value().leftValue(); return new VarArgFunction<Object, Object>() { @Override/*from w w w.j a va 2s. c o m*/ public Object apply(@Nonnull List<Object> input) { try { return MethodUtils.invokeMethod(bean, methodName, Iterables.toArray(input, Object.class)); } catch (NoSuchMethodException e) { throw new ResolutionException(e); } catch (IllegalAccessException e) { throw new ResolutionException(e); } catch (InvocationTargetException e) { throw new ResolutionException(e); } } }; }
From source file:org.immutables.check.IterableChecker.java
public void isOf(Iterable<?> elements) { verifyUsingMatcher(Matchers.contains(Iterables.toArray(elements, Object.class))); }
From source file:net.pterodactylus.sonitus.data.filter.ExternalFilter.java
@Override public void open(Metadata metadata) throws IOException { process = Runtime.getRuntime() .exec(Iterables.toArray( ImmutableList.<String>builder().add(binary(metadata)).addAll(parameters(metadata)).build(), String.class)); InputStream processError = process.getErrorStream(); new Thread(new InputStreamDrainer(processError)).start(); super.open(metadata); }
From source file:edu.umn.msi.tropix.persistence.service.impl.GalaxyToolServiceImpl.java
public GalaxyTool[] list(final String userId) { return Iterables.toArray(galaxyToolRepository.list(), GalaxyTool.class); }
From source file:com.tvl.util.ImmutablesTestBase.java
protected static <T> void assertEqualSequences(Iterable<? extends T> left, Iterable<? extends T> right) { Object[] leftArray = Iterables.toArray(left, Object.class); Object[] rightArray = Iterables.toArray(right, Object.class); Assert.assertArrayEquals(leftArray, rightArray); }
From source file:co.cask.cdap.hive.ExploreUtils.java
/** * Builds a class loader with the class path provided. *//* ww w.j a v a2s. c o m*/ public static synchronized ClassLoader getExploreClassloader() { if (exploreClassLoader != null) { return exploreClassLoader; } // EXPLORE_CLASSPATH and EXPLORE_CONF_FILES will be defined in startup scripts if Hive is installed. String exploreClassPathStr = System.getProperty(Constants.Explore.EXPLORE_CLASSPATH); LOG.debug("Explore classpath = {}", exploreClassPathStr); if (exploreClassPathStr == null) { throw new RuntimeException("System property " + Constants.Explore.EXPLORE_CLASSPATH + " is not set."); } String exploreConfPathStr = System.getProperty(Constants.Explore.EXPLORE_CONF_FILES); LOG.debug("Explore confPath = {}", exploreConfPathStr); if (exploreConfPathStr == null) { throw new RuntimeException("System property " + Constants.Explore.EXPLORE_CONF_FILES + " is not set."); } Iterable<File> hiveClassPath = getClassPathJarsFiles(exploreClassPathStr); Iterable<File> hiveConfFiles = getClassPathJarsFiles(exploreConfPathStr); ImmutableList.Builder<URL> builder = ImmutableList.builder(); for (File file : Iterables.concat(hiveClassPath, hiveConfFiles)) { try { if (file.getName().matches(".*\\.xml")) { builder.add(file.getParentFile().toURI().toURL()); } else { builder.add(file.toURI().toURL()); } } catch (MalformedURLException e) { LOG.error("Jar URL is malformed", e); throw Throwables.propagate(e); } } exploreClassLoader = new URLClassLoader(Iterables.toArray(builder.build(), URL.class), ClassLoader.getSystemClassLoader()); return exploreClassLoader; }
From source file:eu.interedition.collatex.medite.MediteAlgorithm.java
@Override public void collate(VariantGraph graph, Iterable<Token> witness) { final VariantGraph.Vertex[][] vertices = VariantGraphRanking.of(graph).asArray(); final Token[] tokens = Iterables.toArray(witness, Token.class); final SuffixTree<Token> suffixTree = SuffixTree.build(comparator, tokens); final MatchEvaluatorWrapper matchEvaluator = new MatchEvaluatorWrapper(this.matchEvaluator, tokens); final Matches matchCandidates = Matches.between(vertices, suffixTree, matchEvaluator); final SortedSet<SortedSet<VertexMatch.WithTokenIndex>> matches = Sets .newTreeSet(VertexMatch.<VertexMatch.WithTokenIndex>setComparator()); while (true) { final SortedSet<SortedSet<VertexMatch.WithTokenIndex>> maximalUniqueMatches = matchCandidates .findMaximalUniqueMatches(); if (maximalUniqueMatches.isEmpty()) { break; }//from ww w. j a va 2 s . c o m final IntegerRangeSet rankFilter = new IntegerRangeSet(); final IntegerRangeSet tokenFilter = new IntegerRangeSet(); for (SortedSet<VertexMatch.WithTokenIndex> phrase : AlignmentDecisionGraph.filter(maximalUniqueMatches, matchEvaluator)) { final VertexMatch.WithTokenIndex firstMatch = phrase.first(); final VertexMatch.WithTokenIndex lastMatch = phrase.last(); matches.add(phrase); rankFilter.add(Range.closed(firstMatch.vertexRank, lastMatch.vertexRank)); tokenFilter.add(Range.closed(firstMatch.token, lastMatch.token)); } Iterables.removeIf(matchCandidates, VertexMatch.filter(rankFilter, tokenFilter)); } merge(graph, vertices, tokens, matches); }
From source file:org.erlide.ui.util.ETreeNodeContentProvider.java
@SuppressWarnings("unchecked") @Override/*from ww w .j a v a2 s . com*/ public Object[] getElements(final Object inputElement) { if (inputElement instanceof Iterable<?>) { return Iterables.toArray((Iterable<? extends @NonNull Object>) inputElement, Object.class); } return new Object[0]; }
From source file:edu.umn.msi.tropix.persistence.service.impl.FileTypeServiceImpl.java
public FileType[] listFileTypes(final String userId) { return Iterables.toArray(fileTypeDao.findAll(), FileType.class); }