List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:org.asoem.greyfish.core.actions.ContractNetParticipantAction.java
private static MessageTemplate createProposalReplyTemplate(final Iterable<? extends ACLMessage> cfpReplies) { return MessageTemplates .or(Iterables.toArray(Iterables.transform(cfpReplies, new Function<ACLMessage, MessageTemplate>() { @Override/*from w w w. ja v a2 s . c o m*/ public MessageTemplate apply(final ACLMessage aclMessage) { return MessageTemplates.isReplyTo(aclMessage); } }), MessageTemplate.class)); }
From source file:com.google.devtools.build.lib.vfs.WindowsOsPathPolicy.java
@Override public String normalize(String path, int normalizationLevel) { if (normalizationLevel == NORMALIZED) { return path; }// w w w. ja va2 s.com if (normalizationLevel == NEEDS_SHORT_PATH_NORMALIZATION) { String resolvedPath = shortPathResolver.resolveShortPath(path); if (resolvedPath != null) { path = resolvedPath; } } String[] segments = Iterables.toArray(WINDOWS_PATH_SPLITTER.splitToList(path), String.class); int driveStrLength = getDriveStrLength(path); boolean isAbsolute = driveStrLength > 0; int segmentSkipCount = isAbsolute && driveStrLength > 1 ? 1 : 0; StringBuilder sb = new StringBuilder(path.length()); if (isAbsolute) { char c = path.charAt(0); if (isSeparator(c)) { sb.append('/'); } else { sb.append(Character.toUpperCase(c)); sb.append(":/"); } } int segmentCount = Utils.removeRelativePaths(segments, segmentSkipCount, isAbsolute); for (int i = 0; i < segmentCount; ++i) { sb.append(segments[i]); sb.append('/'); } if (segmentCount > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:com.stormpath.beanpole.spring.context.ActiveProfilesInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { String key = ACTIVE_PROFILES_PROPERTY_NAME; String value = getSystemProperty(key); if (value != null) { log.info(/* w ww .ja va 2 s . c o m*/ "The '{}' system property is already set and will be read by Spring as expected. No active " + "profiles will be set by this {} instance", key, ActiveProfilesInitializer.class.getName()); return; } //value is null - no system property was set explicitly. Now try the Beanstalk app environment properties: Map<String, String> props = getBeanstalkEnvironmentProperties(applicationContext); if (props == null || props.isEmpty()) { return; } value = props.get(key); if (value == null) { log.debug("No '{}' Beanstalk environment property set. No Spring active profiles will be configured " + "by this instance.", key); return; } Iterable<String> i = PIPE_DELIMITED.split(value); String[] values = Iterables.toArray(i, String.class); if (values == null || values.length <= 0) { return; } if (log.isDebugEnabled()) { String delimited = Joiner.on(',').skipNulls().join(values); log.debug("Applying discovered configured Spring active profiles: {}", delimited); } applicationContext.getEnvironment().setActiveProfiles(values); }
From source file:chibill.DeobLoader.loader.Remappers.java
public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) { this.classLoader = classLoader; try {/*from w w w .j av a2 s .c o m*/ InputStream classData = getClass().getResourceAsStream(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(classData); CharSource srgSource = zis.asCharSource(Charsets.UTF_8); List<String> srgList = srgSource.readLines(); 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) { } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:edu.cmu.lti.oaqa.baseqa.document.rerank.scorers.LuceneDocumentScorer.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 {//w w w. j a v a 2s . c om 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")); //noinspection unchecked fields = Iterables.toArray((Iterable<String>) getParameterValue("fields"), String.class); uriPrefix = String.class.cast(getParameterValue("uri-prefix")); String index = String.class.cast(getParameterValue("index")); // create lucene analyzer = new StandardAnalyzer(); try { reader = DirectoryReader.open(NIOFSDirectory.open(Paths.get(index))); } catch (IOException e) { throw new ResourceInitializationException(e); } searcher = new IndexSearcher(reader); return true; }
From source file:org.icgc.dcc.submission.validation.primary.report.SummaryPlanElement.java
@Override public Pipe report(Pipe pipe) { pipe = keepStructurallyValidTuples(pipe); ArrayList<AggregateBy> summaries = new ArrayList<AggregateBy>(); for (String fieldName : fieldNames) { Iterables.addAll(summaries, collectAggregateBys(fieldName)); }//www . jav a 2 s.c o m // This is highly inefficient. This adds a constant to every row so we can group on it so that the AggregateBy // instances see all values. // Alternatively, we could set a random number to each row and group on this, each group would then produce // intermediate result (sum, count for average) and another pipe could then process this smaller set as done here. Fields constantField = new Fields("__constant__"); pipe = new Each(pipe, new Insert(constantField, "1"), Fields.ALL); pipe = new AggregateBy(pipe, constantField, Iterables.toArray(summaries, AggregateBy.class)); // only one group // emerges from // grouping on // "__constant__" pipe = new Discard(pipe, constantField); pipe = new Each(pipe, new SummaryFunction(fieldNames, summaryFields()), REPORT_FIELDS); return pipe; }
From source file:org.eclipse.xtext.xbase.ui.navigation.XbaseHyperLinkHelper.java
/** * If multiple links are requested, all ambiguous candidates are provided for feature and constructor calls. *///from w w w. ja v a 2 s. c o m @Override public IHyperlink[] createHyperlinksByOffset(XtextResource resource, int offset, boolean createMultipleHyperlinks) { List<IHyperlink> links = Lists.newArrayList(); IHyperlinkAcceptor acceptor = new XbaseHyperlinkAcceptor(links, createMultipleHyperlinks); super.createHyperlinksByOffset(resource, offset, acceptor); INode crossRefNode = getEObjectAtOffsetHelper().getCrossReferenceNode(resource, new TextRegion(offset, 0)); if (crossRefNode == null) { this.createHyperlinksByOffset(resource, offset, acceptor); } else { this.createHyperlinksForCrossRef(resource, crossRefNode, acceptor); } if (!links.isEmpty()) return Iterables.toArray(links, IHyperlink.class); return null; }
From source file:org.asoem.greyfish.core.space.WalledPointSpace.java
private WalledTile[] getWalledTiles() { return Iterables.toArray(Iterables.filter(getTiles(), new Predicate<WalledTile>() { @Override/*w ww . j a va 2 s . c o m*/ public boolean apply(final WalledTile tileLocation) { return checkNotNull(tileLocation).getWallFlags() != 0; } }), WalledTile.class); }
From source file:org.apache.abdera2.parser.axiom.FOMCollection.java
public Collection setAccept(Iterable<String> mediaRanges) { return setAccept(Iterables.toArray(mediaRanges, String.class)); }
From source file:com.dangdang.ddframe.job.cloud.agent.internal.JobConfigurationContext.java
private JobEventConfiguration[] buildJobEventConfiguration(final Map<String, String> jobConfigurationMap) { List<JobEventConfiguration> result = new ArrayList<>(); if (jobConfigurationMap.containsKey("driverClassName") && jobConfigurationMap.containsKey("url") && jobConfigurationMap.containsKey("username") && jobConfigurationMap.containsKey("password") && jobConfigurationMap.containsKey("logLevel")) { result.add(new JobRdbEventConfiguration(jobConfigurationMap.get("driverClassName"), jobConfigurationMap.get("url"), jobConfigurationMap.get("username"), jobConfigurationMap.get("password"), LogLevel.valueOf(jobConfigurationMap.get("logLevel").toUpperCase()))); } else {/*from w w w. j a va 2 s . c o m*/ result.add(new JobLogEventConfiguration()); } if (jobConfigurationMap.containsKey("logEvent") && result.get(0) instanceof JobRdbEventConfiguration) { result.add(new JobLogEventConfiguration()); } return Iterables.toArray(result, JobEventConfiguration.class); }