下面列出了怎么用com.google.common.collect.Collections2的API类实例代码及写法,或者点击链接到github查看源代码。
private File getBaseApFile(Project project, TBuildType tBuildType) {
File apBaseFile;
File buildTypeBaseApFile = tBuildType.getBaseApFile();
if (null != buildTypeBaseApFile && buildTypeBaseApFile.exists()) {
apBaseFile = buildTypeBaseApFile;
} else if (!isNullOrEmpty(tBuildType.getBaseApDependency())) {
String apDependency = tBuildType.getBaseApDependency();
// Preconditions.checkNotNull(apDependency,
// "You have to specify the baseApFile property or the baseApDependency
// dependency");
Dependency dependency = project.getDependencies().create(apDependency);
Configuration configuration = project.getConfigurations().detachedConfiguration(dependency);
configuration.setTransitive(false);
apBaseFile = Iterables.getOnlyElement(Collections2.filter(configuration.getFiles(), new Predicate<File>() {
@Override
public boolean apply(@Nullable File file) {
return file.getName().endsWith(".ap");
}
}));
} else {
throw new IllegalStateException("AP is missing");
}
return apBaseFile;
}
private boolean waitTillStdoutIsPopulated(ByteArrayOutputStream baos, int timeout) throws InterruptedException,
IOException
{
long now = System.currentTimeMillis();
Collection<String> filter = Lists.newArrayList();
while (System.currentTimeMillis() - now < timeout) {
baos.flush();
String[] sout = baos.toString().split(System.lineSeparator());
filter = Collections2.filter(Arrays.asList(sout), Predicates.containsPattern("Delta Record:"));
if (filter.size() != 0) {
break;
}
Thread.sleep(500);
}
return (filter.size() != 0);
}
public MapContextImpl(MapInfo info, MapSource source, Collection<MapModule> modules) {
super(info);
this.source = checkNotNull(source);
this.modules = ImmutableList.copyOf(checkNotNull(modules));
for (MapModule module : this.modules) {
this.tags.addAll(module.getTags());
if (module instanceof TeamModule) {
this.players.clear();
this.players.addAll(
Collections2.transform(((TeamModule) module).getTeams(), TeamFactory::getMaxPlayers));
}
if (module instanceof FreeForAllModule) {
this.players.clear();
this.players.add(((FreeForAllModule) module).getOptions().maxPlayers);
}
}
if (getWorld().hasTerrain()) {
this.tags.add(TERRAIN);
}
}
/**
* Get {@link TestCaseStep} which are using an other {@link TestCaseStep}
* from the given {@link Test} but which are NOT included into this
* {@link Test}
*
* @param test the {@link Test} from which getting externally used
* {@link TestCaseStep}s
* @return a {@link Collection} of {@link TestCaseStep} which are using an
* other {@link TestCaseStep} from the given {@link Test} but which are NOT
* included into this {@link Test}
* @throws CerberusException if an unexpected error occurred
*/
private Collection<TestCaseStep> externallyUsedTestCaseSteps(final Test test) throws CerberusException {
// Get the associated ApplicationContext to this servlet
final ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
// Get all TestCaseSteps which are using an other TestCaseSteps from given Test
final ITestCaseStepService testCaseStepService = applicationContext.getBean(ITestCaseStepService.class);
final List<TestCaseStep> stepsInUse = testCaseStepService.getTestCaseStepsUsingTestInParameter(test.getTest());
// Filter the retrieved list to only retain those which are not included from the given Test
return Collections2.filter(stepsInUse, new Predicate<TestCaseStep>() {
@Override
public boolean apply(@Nullable final TestCaseStep input) {
return !input.getTest().equals(test.getTest());
}
@Override
public boolean test(TestCaseStep t) {
return Predicate.super.test(t); //To change body of generated methods, choose Tools | Templates.
}
});
}
@Override
public String getDataSourceId() {
String res = dataSourceId;
if (res == null) {
Object dataSourceIds = header.get("dataSourceIds");
if (dataSourceIds instanceof List) {
res = Joiner.on(",").join(Collections2.filter((List) dataSourceIds, new Predicate() {
@Override
public boolean apply(Object input) {
return input != null;
}
}));
}
}
return res;
}
private Dictionary<String> buildDictionary(TblColRef dim, List<Object> inputValues) throws IOException {
Stopwatch stopwatch = new Stopwatch();
stopwatch.start();
final Collection<String> values = Collections2.transform(Sets.newHashSet(inputValues),
new Function<Object, String>() {
@Nullable
@Override
public String apply(Object input) {
String value = (String) input;
return value;
}
});
final Dictionary<String> dict = DictionaryGenerator.buildDictionary(dim.getType(),
new IterableDictionaryValueEnumerator(values));
stopwatch.stop();
if (logger.isDebugEnabled()) {
logger.debug("BuildDictionary for column : " + dim.getName() + " took : " + stopwatch.elapsedMillis()
+ " ms ");
}
return dict;
}
@Override
public Void visit(OWLEquivalentObjectPropertiesAxiom axiom) {
Set<OWLObjectPropertyExpression> properties = axiom.getProperties();
boolean anonymousPropertyExists = false;
for (OWLObjectPropertyExpression property : properties) {
anonymousPropertyExists = anonymousPropertyExists || property.isAnonymous();
}
// #217 - in case of EquivalentObjectProperties(:p ObjectInverseOf(:q))
if (!anonymousPropertyExists) {
Collection<Long> nodes = Collections2.transform(axiom.getObjectPropertiesInSignature(),
new Function<OWLObjectProperty, Long>() {
@Override
public Long apply(OWLObjectProperty objectProperty) {
return getOrCreateNode(getIri(objectProperty));
}
});
getOrCreateRelationshipPairwise(nodes, OwlRelationships.OWL_EQUIVALENT_OBJECT_PROPERTY);
}
return null;
}
@Override
protected List<MergedAnomalyResultDTO> retrieveAnomaliesFromDatabase(List<MergedAnomalyResultDTO> generated) {
List<MergedAnomalyResultDTO> retrieved = super.retrieveAnomaliesFromDatabase(generated);
Collection<MergedAnomalyResultDTO> anomalies =
Collections2.filter(retrieved,
mergedAnomaly -> mergedAnomaly != null &&
!mergedAnomaly.isChild() &&
mergedAnomaly.getAnomalyResultSource().equals(AnomalyResultSource.DEFAULT_ANOMALY_DETECTION) &&
// merge if only the anomaly generated by the same detector
this.detectorComponentName.equals(mergedAnomaly.getProperties().getOrDefault(PROP_DETECTOR_COMPONENT_NAME, "")) &&
// merge if only the anomaly is in the same dimension
this.metricUrn.equals(mergedAnomaly.getMetricUrn())
);
for (MergedAnomalyResultDTO anomaly : anomalies) {
if(anomaly.getId() != null) this.existingAnomalies.put(anomaly.getId(), copyAnomalyInfo(anomaly, new MergedAnomalyResultDTO()));
}
return new ArrayList<>(anomalies);
}
/**
* Creates a query for inserting a collection of records of the specified type
* @param ds name of datastore
* @param collection name of collection
* @param records a collection of records that are to be inserted
* @param recordType the @link {@link RecordType} indicating the format engine to use for data
* @return the generated query in JSON format
*/
public Query insertQuery(final String ds, final String collection, List<Record> records, final RecordType recordType) {
queryJson.put(QueryParams.QUERY.getParam(), QueryType.INSERT.getQueryCode());
queryJson.put(QueryParams.DATASTORE.getParam(), ds);
queryJson.put(QueryParams.COLLECTION.getParam(), collection);
JSONObject payloadJson = new JSONObject();
payloadJson.put(QueryParams.TYPE.getParam(), recordType.getTypeCode());
payloadJson.put(QueryParams.DATA.getParam(), new JSONArray(Collections2.transform(records, new Function<Record, JSONObject>() {
public JSONObject apply(Record record) {
return record.asJson();
}
})));
queryJson.put(QueryParams.PAYLOAD.getParam(), payloadJson);
return this;
}
private List<TupleExpr> getPlans(final TupleExpr te) {
final NodeCollector nc = new NodeCollector();
te.visit(nc);
final Set<QueryModelNode> nodeSet = nc.getNodeSet();
final List<Filter> filterList = nc.getFilterSet();
final Projection projection = nc.getProjection().clone();
final List<TupleExpr> queryPlans = Lists.newArrayList();
final Collection<List<QueryModelNode>> plans = Collections2.permutations(nodeSet);
for (final List<QueryModelNode> p : plans) {
if (p.size() == 0) {
throw new IllegalArgumentException("Tuple must contain at least one node!");
} else if (p.size() == 1) {
queryPlans.add(te);
} else {
queryPlans.add(buildTuple(p, filterList, projection));
}
}
return queryPlans;
}
/**
* Helper to convert a collection of email strings into {@code InternetAddress} instances, filtering
* out invalid addresses and nulls.
*
* @param emailCollection collection of email address strings
* @return filtered collection of InternetAddress objects
*/
public static Collection<InternetAddress> toAddress(Collection<String> emailCollection) {
if (CollectionUtils.isEmpty(emailCollection)) {
return Collections.emptySet();
}
return Collections2.filter(Collections2.transform(emailCollection,
new Function<String, InternetAddress>() {
@Override
public InternetAddress apply(String s) {
try {
return InternetAddress.parse(s)[0];
} catch (Exception e) {
return null;
}
}
}),
new Predicate<InternetAddress>() {
@Override
public boolean apply(InternetAddress internetAddress) {
return internetAddress != null;
}
});
}
private Collection<TopologyProcessor> fillProcessorStreams(Collection<TopologyProcessor> processors) {
if (processors != null) {
for (TopologyProcessor processor : processors) {
List<TopologyStream> topologyStreams = getOutputStreams(processor);
processor.setOutputStreams(topologyStreams);
processor.setOutputStreamIds(new ArrayList<>(Collections2.transform(topologyStreams, new Function<TopologyStream, Long>() {
@Nullable
@Override
public Long apply(@Nullable TopologyStream input) {
return input.getId();
}
})));
}
}
return processors;
}