List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:com.mycila.event.MycilaEvent.java
public Publisher createPublisher(final Iterable<Topic> topics) { return createPublisher(Iterables.toArray(checkNotNull(topics, "Missing topics"), Topic.class)); }
From source file:edu.umn.msi.tropix.persistence.service.impl.RequestServiceImpl.java
public InternalRequest[] getOutgoingRequests(final String gridId) { final Iterable<InternalRequest> requests = getTropixObjectDao().getInternalRequests(gridId); return Iterables.toArray(requests, InternalRequest.class); }
From source file:edu.umn.msi.tropix.storage.core.impl.StorageManagerImpl.java
public List<FileMetadata> getFileMetadata(List<String> ids, String gridId) { final ImmutableList.Builder<FileMetadata> fileMetadataList = ImmutableList.builder(); LOG.debug("About to call canDownloadAll"); if (!authorizationProvider.canDownloadAll(Iterables.toArray(ids, String.class), gridId)) { throw new RuntimeException("User " + gridId + " cannot access one of files " + Iterables.toString(ids)); }// w w w. j a v a 2 s .co m LOG.debug("About to fetch file metadata"); // TODO: Last bottle neck for SFTP server? for (final String id : ids) { fileMetadataList.add(getFileMetadata(id)); } LOG.debug("Returning file metadata"); return fileMetadataList.build(); }
From source file:co.cask.cdap.shell.CLIMain.java
/** * Starts shell mode, which provides a shell to enter multiple commands and use autocompletion. * * @param output {@link PrintStream} to write to * @throws Exception/*from w w w . j av a 2 s . c om*/ */ public void startShellMode(PrintStream output) throws Exception { this.reader.setPrompt("cdap (" + cliConfig.getURI() + ")> "); this.reader.setHandleUserInterrupt(true); for (Completer completer : commands.getCompleters(null)) { reader.addCompleter(completer); } while (true) { String line; try { line = reader.readLine(); } catch (UserInterruptException e) { continue; } if (line == null) { output.println(); break; } if (line.length() > 0) { String command = line.trim(); String[] commandArgs = Iterables.toArray(Splitter.on(" ").split(command), String.class); try { processArgs(commandArgs, output); } catch (InvalidCommandException e) { output.println( "Invalid command: " + command + " (enter 'help' to list all available commands)"); } catch (SSLHandshakeException e) { output.println("Error: " + e.getMessage()); output.println(String.format("To ignore this error, set -D%s=false when starting the CLI", CLIConfig.PROP_VERIFY_SSL_CERT)); } catch (Exception e) { output.println("Error: " + e.getMessage()); e.printStackTrace(); } output.println(); } } }
From source file:io.prestosql.plugin.accumulo.conf.AccumuloTableProperties.java
/** * Gets the value of the column_mapping property, or Optional.empty() if not set. * <p>/* w w w . j ava2 s .c o m*/ * Parses the value into a map of Presto column name to a pair of strings, the Accumulo column family and qualifier. * * @param tableProperties The map of table properties * @return The column mapping, presto name to (accumulo column family, qualifier) */ public static Optional<Map<String, Pair<String, String>>> getColumnMapping( Map<String, Object> tableProperties) { requireNonNull(tableProperties); @SuppressWarnings("unchecked") String strMapping = (String) tableProperties.get(COLUMN_MAPPING); if (strMapping == null) { return Optional.empty(); } // Parse out the column mapping // This is a comma-delimited list of "(presto, column:accumulo, fam:accumulo qualifier)" triplets ImmutableMap.Builder<String, Pair<String, String>> mapping = ImmutableMap.builder(); for (String m : COMMA_SPLITTER.split(strMapping)) { String[] tokens = Iterables.toArray(COLON_SPLITTER.split(m), String.class); checkState(tokens.length == 3, format("Mapping of %s contains %d tokens instead of 3", m, tokens.length)); mapping.put(tokens[0], Pair.of(tokens[1], tokens[2])); } return Optional.of(mapping.build()); }
From source file:com.jaxio.celerio.model.support.jpa.JpaToOneRelation.java
private String getJoinColumnsAnnotation(List<AttributePair> attributePairs) { addImport("javax.persistence.JoinColumns"); addImport("javax.persistence.JoinColumn"); List<String> ab = newArrayList(); for (AttributePair pair : attributePairs) { AttributeBuilder joinBuilder = getJoinColumnAttributes(pair.getFromAttribute(), pair.getToAttribute()); joinBuilder.bindAttributesTo("@JoinColumn"); ab.add(joinBuilder.bindAttributesTo("@JoinColumn")); }/*from ww w .j ava 2 s . co m*/ AttributeBuilder joinsBuilder = new AttributeBuilder(); joinsBuilder.add("value", Iterables.toArray(ab, String.class)); return joinsBuilder.bindAttributesTo("@JoinColumns"); }
From source file:net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.java
public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) { this.classLoader = classLoader; try {/*from ww w. j a v a 2 s.c om*/ List<String> srgList; final String gradleStartProp = System.getProperty("net.minecraftforge.gradle.GradleStart.srg.srg-mcp"); if (Strings.isNullOrEmpty(gradleStartProp)) { // get as a resource InputStream classData = getClass().getResourceAsStream(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(classData); CharSource srgSource = zis.asCharSource(Charsets.UTF_8); srgList = srgSource.readLines(); } else { srgList = Files.readLines(new File(gradleStartProp), Charsets.UTF_8); } rawMethodMaps = Maps.newHashMap(); rawFieldMaps = Maps.newHashMap(); Builder<String, String> builder = ImmutableBiMap.<String, String>builder(); Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults(); for (String line : srgList) { String[] parts = Iterables.toArray(splitter.split(line), String.class); String typ = parts[0]; if ("CL".equals(typ)) { parseClass(builder, parts); } else if ("MD".equals(typ)) { parseMethod(parts); } else if ("FD".equals(typ)) { parseField(parts); } } classNameBiMap = builder.build(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, ioe, "An error occurred loading the deobfuscation map data"); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:edu.cmu.lti.oaqa.baseqa.concept.rerank.scorers.LuceneConceptScorer.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { super.initialize(aSpecifier, aAdditionalParams); hits = Integer.class.cast(getParameterValue("hits")); // query constructor String stoplistPath = String.class.cast(getParameterValue("stoplist-path")); try {//from w w w. j a va 2s. co m stoplist = Resources.readLines(getClass().getResource(stoplistPath), UTF_8).stream().map(String::trim) .collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } // load index parameters idFieldName = String.class.cast(getParameterValue("id-field")); sourceFieldName = String.class.cast(getParameterValue("source-field")); //noinspection unchecked fields = Iterables.toArray((Iterable<String>) getParameterValue("fields"), String.class); String uriPrefixPath = String.class.cast(getParameterValue("uri-prefix")); try { uriPrefix = Resources.readLines(getClass().getResource(uriPrefixPath), UTF_8).stream() .map(line -> line.split("\t")).collect(toMap(segs -> segs[0], segs -> segs[1])); } catch (IOException e) { throw new ResourceInitializationException(e); } String index = String.class.cast(getParameterValue("index")); // create lucene Analyzer analyzer = new StandardAnalyzer(); parser = new MultiFieldQueryParser(fields, analyzer); try { reader = DirectoryReader.open(FSDirectory.open(Paths.get(index))); } catch (IOException e) { throw new ResourceInitializationException(e); } searcher = new IndexSearcher(reader); return true; }
From source file:io.druid.segment.IndexBuilder.java
public QueryableIndex buildMMappedMergedIndex() { Preconditions.checkNotNull(indexMerger, "indexMerger"); Preconditions.checkNotNull(tmpDir, "tmpDir"); final List<QueryableIndex> persisted = Lists.newArrayList(); try {//ww w. j a v a2 s .c om for (int i = 0; i < rows.size(); i += ROWS_PER_INDEX_FOR_MERGING) { persisted .add(TestHelper.getTestIndexIO() .loadIndex( indexMerger.persist( buildIncrementalIndexWithRows(schema, maxRows, rows.subList(i, Math.min(rows.size(), i + ROWS_PER_INDEX_FOR_MERGING))), new File(tmpDir, String.format("testIndex-%s", UUID.randomUUID().toString())), indexSpec))); } final QueryableIndex merged = TestHelper.getTestIndexIO().loadIndex( indexMerger.merge(Lists.transform(persisted, new Function<QueryableIndex, IndexableAdapter>() { @Override public IndexableAdapter apply(QueryableIndex input) { return new QueryableIndexIndexableAdapter(input); } }), true, Iterables.toArray(Iterables.transform(Arrays.asList(schema.getMetrics()), new Function<AggregatorFactory, AggregatorFactory>() { @Override public AggregatorFactory apply(AggregatorFactory input) { return input.getCombiningFactory(); } }), AggregatorFactory.class), new File(tmpDir, String.format("testIndex-%s", UUID.randomUUID())), indexSpec)); for (QueryableIndex index : persisted) { index.close(); } return merged; } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:com.android.build.gradle.integration.common.fixture.RunGradleTasks.java
public GradleBuildResult run(@NonNull List<String> tasksList) { assertThat(tasksList).named("tasks list").isNotEmpty(); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); syncFileSystem();//from www.j a v a 2 s . com List<String> args = Lists.newArrayList(); if (enableInfoLogging) { args.add("-i"); // -i, --info Set log level to info. } args.add("-u"); // -u, --no-search-upward Don't search in parent folders for a // settings.gradle file. args.add("-Pcom.android.build.gradle.integratonTest.useJack=" + Boolean.toString(isUseJack)); args.add("-Pcom.android.build.gradle.integratonTest.minifyEnabled=" + Boolean.toString(isMinifyEnabled)); if (mPackaging != null) { args.add(String.format("-P%s=%s", AndroidGradleOptions.PROPERTY_USE_OLD_PACKAGING, mPackaging.mFlagValue)); } args.addAll(mArguments); System.out.println("[GradleTestProject] Executing tasks: gradle " + Joiner.on(' ').join(args) + " " + Joiner.on(' ').join(tasksList)); BuildLauncher launcher = mProjectConnection.newBuild().forTasks(Iterables.toArray(tasksList, String.class)) .withArguments(Iterables.toArray(args, String.class)); setJvmArguments(launcher); launcher.setStandardOutput(new TeeOutputStream(stdout, System.out)); launcher.setStandardError(new TeeOutputStream(stderr, System.err)); WaitingResultHandler handler = new WaitingResultHandler(); launcher.run(handler); GradleConnectionException failure = handler.waitForResult(); if (mExpectingFailure && failure == null) { throw new AssertionError("Expecting build to fail"); } else if (!mExpectingFailure && failure != null) { throw failure; } return new GradleBuildResult(stdout, stderr, failure); }