List of usage examples for com.google.common.collect Lists transform
@CheckReturnValue public static <F, T> List<T> transform(List<F> fromList, Function<? super F, ? extends T> function)
From source file:org.gradle.internal.component.AmbiguousConfigurationSelectionException.java
private static String generateMessage(AttributeContainer fromConfigurationAttributes, AttributesSchema consumerSchema, List<ConfigurationMetadata> matches, ComponentResolveMetadata targetComponent) { Set<String> ambiguousConfigurations = Sets.newTreeSet(Lists.transform(matches, CONFIG_NAME)); Set<String> requestedAttributes = Sets .newTreeSet(Iterables.transform(fromConfigurationAttributes.keySet(), ATTRIBUTE_NAME)); StringBuilder sb = new StringBuilder( "Cannot choose between the following configurations on '" + targetComponent + "' : "); JOINER.appendTo(sb, ambiguousConfigurations); sb.append(". All of them match the consumer attributes:"); sb.append("\n"); int maxConfLength = maxLength(ambiguousConfigurations); // We're sorting the names of the configurations and later attributes // to make sure the output is consistently the same between invocations for (final String ambiguousConf : ambiguousConfigurations) { formatConfiguration(sb, fromConfigurationAttributes, consumerSchema, matches, requestedAttributes, maxConfLength, ambiguousConf); }//from w w w . j a va 2s .c o m return sb.toString(); }
From source file:org.sosy_lab.java_smt.basicimpl.AbstractQuantifiedFormulaManager.java
@Override public BooleanFormula mkQuantifier(Quantifier q, List<? extends Formula> pVariables, BooleanFormula pBody) { return wrap(mkQuantifier(q, Lists.transform(pVariables, this::extractInfo), extractInfo(pBody))); }
From source file:org.sonatype.nexus.plugins.siesta.internal.InvalidConfigurationExceptionMapper.java
@Override protected List<ValidationErrorXO> getValidationErrors(final InvalidConfigurationException exception) { ValidationResponse response = exception.getValidationResponse(); if (response != null) { List<ValidationMessage> errors = response.getValidationErrors(); if (errors != null && !errors.isEmpty()) { return Lists.transform(errors, new Function<ValidationMessage, ValidationErrorXO>() { @Nullable/*from w ww .j a v a 2 s . c o m*/ @Override public ValidationErrorXO apply(@Nullable final ValidationMessage message) { if (message != null) { return new ValidationErrorXO(message.getKey(), message.getMessage()); } return null; } }); } } return Lists.newArrayList(new ValidationErrorXO(exception.getMessage())); }
From source file:org.apache.kylin.cube.util.CubingUtils.java
public static Map<Long, HLLCounter> sampling(CubeDesc cubeDesc, IJoinedFlatTableDesc flatDescIn, Iterable<List<String>> streams) { final CubeJoinedFlatTableEnrich flatDesc = new CubeJoinedFlatTableEnrich(flatDescIn, cubeDesc); final int rowkeyLength = cubeDesc.getRowkey().getRowKeyColumns().length; final List<Long> allCuboidIds = new CuboidScheduler(cubeDesc).getAllCuboidIds(); final long baseCuboidId = Cuboid.getBaseCuboidId(cubeDesc); final Map<Long, Integer[]> allCuboidsBitSet = Maps.newHashMap(); Lists.transform(allCuboidIds, new Function<Long, Integer[]>() { @Nullable/* ww w .j av a 2s.co m*/ @Override public Integer[] apply(@Nullable Long cuboidId) { Integer[] result = new Integer[Long.bitCount(cuboidId)]; long mask = Long.highestOneBit(baseCuboidId); int position = 0; for (int i = 0; i < rowkeyLength; i++) { if ((mask & cuboidId) > 0) { result[position] = i; position++; } mask = mask >> 1; } return result; } }); final Map<Long, HLLCounter> result = Maps.newHashMapWithExpectedSize(allCuboidIds.size()); for (Long cuboidId : allCuboidIds) { result.put(cuboidId, new HLLCounter(cubeDesc.getConfig().getCubeStatsHLLPrecision())); Integer[] cuboidBitSet = new Integer[Long.bitCount(cuboidId)]; long mask = Long.highestOneBit(baseCuboidId); int position = 0; for (int i = 0; i < rowkeyLength; i++) { if ((mask & cuboidId) > 0) { cuboidBitSet[position] = i; position++; } mask = mask >> 1; } allCuboidsBitSet.put(cuboidId, cuboidBitSet); } HashFunction hf = Hashing.murmur3_32(); ByteArray[] row_hashcodes = new ByteArray[rowkeyLength]; for (int i = 0; i < rowkeyLength; i++) { row_hashcodes[i] = new ByteArray(); } for (List<String> row : streams) { //generate hash for each row key column for (int i = 0; i < rowkeyLength; i++) { Hasher hc = hf.newHasher(); final String cell = row.get(flatDesc.getRowKeyColumnIndexes()[i]); if (cell != null) { row_hashcodes[i].set(hc.putString(cell).hash().asBytes()); } else { row_hashcodes[i].set(hc.putInt(0).hash().asBytes()); } } for (Map.Entry<Long, HLLCounter> longHyperLogLogPlusCounterNewEntry : result.entrySet()) { Long cuboidId = longHyperLogLogPlusCounterNewEntry.getKey(); HLLCounter counter = longHyperLogLogPlusCounterNewEntry.getValue(); Hasher hc = hf.newHasher(); final Integer[] cuboidBitSet = allCuboidsBitSet.get(cuboidId); for (int position = 0; position < cuboidBitSet.length; position++) { hc.putBytes(row_hashcodes[cuboidBitSet[position]].array()); } counter.add(hc.hash().asBytes()); } } return result; }
From source file:info.archinnov.achilles.clustered.ClusteredEntityFactory.java
private <T> List<T> buildSimpleClusteredEntities(Class<T> entityClass, ThriftPersistenceContext context, List<HColumn<Composite, Object>> hColumns) { Function<HColumn<Composite, Object>, T> function; if (context.isValueless()) { function = transformer.valuelessClusteredEntityTransformer(entityClass, context); } else {/*from w ww. j av a 2 s . co m*/ function = transformer.clusteredEntityTransformer(entityClass, context); } return Lists.transform(hColumns, function); }
From source file:ignitr.couchbase.discovery.EurekaDiscoveryStrategy.java
@Override public List<String> discoverClusterNodes() { String appId = DynamicPropertyFactory.getInstance().getStringProperty(PROP_EUREKA_APP_ID, null).get(); if (appId == null) { throw new IgnitrCouchbaseException( String.format("Discovery strategy 'eureka' specified, but no application " + " identifier is configured in '%s' property!", PROP_EUREKA_APP_ID)); }//from ww w. j a va2 s. c o m Application application = DiscoveryManager.getInstance().getDiscoveryClient().getApplication(appId); return Lists.transform(application.getInstancesAsIsFromEureka(), new Function<InstanceInfo, String>() { @Nullable @Override public String apply(@Nullable InstanceInfo input) { if (input != null) { String localIpAddress = input.getIPAddr(); if (input.getDataCenterInfo() instanceof AmazonInfo) { AmazonInfo amazonInfo = (AmazonInfo) input.getDataCenterInfo(); localIpAddress = amazonInfo.get(AmazonInfo.MetaDataKey.localIpv4); } return localIpAddress; } return null; } }); }
From source file:com.cloudera.oryx.app.rdf.tree.DecisionForest.java
@Override public Prediction predict(Example test) { return WeightedPrediction .voteOnFeature(Lists.transform(Arrays.asList(trees), new TreeToPredictionFunction(test)), weights); }
From source file:org.ow2.play.dsb.wsn.component.TopicAwareService.java
@Override public List<Topic> get() { logger.info("Get topics"); return Lists.transform(management.getTopics(), new Function<org.petalslink.dsb.jbi.se.wsn.api.Topic, Topic>() { public Topic apply(org.petalslink.dsb.jbi.se.wsn.api.Topic t) { Topic result = new Topic(); result.setName(t.name); result.setNs(t.ns);/*from w w w . j a v a 2 s . co m*/ result.setPrefix(t.prefix); return result; } }); }
From source file:com.google.template.soy.data.internal.ListBackedList.java
@Nonnull @Override public final List<SoyValue> asResolvedJavaList() { return Lists.transform(asJavaList(), Transforms.RESOLVE_FUNCTION); }
From source file:net.sourceforge.cilib.pso.crossover.velocityprovider.LovbjergOffspringVelocityProvider.java
@Override public StructuredType f(List<Particle> parent, Particle offspring) { Vector velocity = (Vector) offspring.getVelocity(); return Vectors.sumOf(Lists.transform(parent, new Function<Particle, Vector>() { @Override//from www .ja v a2 s. c om public Vector apply(Particle f) { return (Vector) f.getVelocity(); } })).normalize().multiply(velocity.length()); }