本文整理了Java中org.apache.commons.collections.CollectionUtils.collect()
方法的一些代码示例,展示了CollectionUtils.collect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CollectionUtils.collect()
方法的具体详情如下:
包路径:org.apache.commons.collections.CollectionUtils
类名称:CollectionUtils
方法名:collect
[英]Returns a new Collection consisting of the elements of inputCollection transformed by the given transformer.
If the input transformer is null, the result is an empty list.
[中]返回由给定转换器转换的inputCollection元素组成的新集合。
如果输入转换器为空,则结果为空列表。
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
* Delegates to {@link CollectionUtils#collect(Collection, Transformer)}, but performs the necessary type coercion
* to allow the returned collection to be correctly casted based on the TypedTransformer.
*
* @param inputCollection
* @param transformer
* @return the typed, collected Collection
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> Collection<T> collect(Collection inputCollection, TypedTransformer<T> transformer) {
return CollectionUtils.collect(inputCollection, transformer);
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Transforms all elements from the inputIterator with the given transformer
* and adds them to the outputCollection.
* <p>
* If the input iterator or transformer is null, the result is an empty list.
*
* @param inputIterator the iterator to get the input from, may be null
* @param transformer the transformer to use, may be null
* @return the transformed result (new list)
*/
public static Collection collect(Iterator inputIterator, Transformer transformer) {
ArrayList answer = new ArrayList();
collect(inputIterator, transformer, answer);
return answer;
}
代码示例来源:origin: wildfly/wildfly
/**
* Transforms all elements from the inputIterator with the given transformer
* and adds them to the outputCollection.
* <p>
* If the input iterator or transformer is null, the result is an empty list.
*
* @param inputIterator the iterator to get the input from, may be null
* @param transformer the transformer to use, may be null
* @return the transformed result (new list)
*/
public static Collection collect(Iterator inputIterator, Transformer transformer) {
ArrayList answer = new ArrayList();
collect(inputIterator, transformer, answer);
return answer;
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Transforms all elements from inputCollection with the given transformer
* and adds them to the outputCollection.
* <p>
* If the input collection or transformer is null, there is no change to the
* output collection.
*
* @param inputCollection the collection to get the input from, may be null
* @param transformer the transformer to use, may be null
* @param outputCollection the collection to output into, may not be null
* @return the outputCollection with the transformed input added
* @throws NullPointerException if the output collection is null
*/
public static Collection collect(Collection inputCollection, final Transformer transformer, final Collection outputCollection) {
if (inputCollection != null) {
return collect(inputCollection.iterator(), transformer, outputCollection);
}
return outputCollection;
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Returns a new Collection consisting of the elements of inputCollection transformed
* by the given transformer.
* <p>
* If the input transformer is null, the result is an empty list.
*
* @param inputCollection the collection to get the input from, may not be null
* @param transformer the transformer to use, may be null
* @return the transformed result (new list)
* @throws NullPointerException if the input collection is null
*/
public static Collection collect(Collection inputCollection, Transformer transformer) {
ArrayList answer = new ArrayList(inputCollection.size());
collect(inputCollection, transformer, answer);
return answer;
}
代码示例来源:origin: wildfly/wildfly
/**
* Transforms all elements from inputCollection with the given transformer
* and adds them to the outputCollection.
* <p>
* If the input collection or transformer is null, there is no change to the
* output collection.
*
* @param inputCollection the collection to get the input from, may be null
* @param transformer the transformer to use, may be null
* @param outputCollection the collection to output into, may not be null
* @return the outputCollection with the transformed input added
* @throws NullPointerException if the output collection is null
*/
public static Collection collect(Collection inputCollection, final Transformer transformer, final Collection outputCollection) {
if (inputCollection != null) {
return collect(inputCollection.iterator(), transformer, outputCollection);
}
return outputCollection;
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns a new Collection consisting of the elements of inputCollection transformed
* by the given transformer.
* <p>
* If the input transformer is null, the result is an empty list.
*
* @param inputCollection the collection to get the input from, may not be null
* @param transformer the transformer to use, may be null
* @return the transformed result (new list)
* @throws NullPointerException if the input collection is null
*/
public static Collection collect(Collection inputCollection, Transformer transformer) {
ArrayList answer = new ArrayList(inputCollection.size());
collect(inputCollection, transformer, answer);
return answer;
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Transform the collection by applying a Transformer to each element.
* <p>
* If the input collection or transformer is null, there is no change made.
* <p>
* This routine is best for Lists, for which set() is used to do the
* transformations "in place." For other Collections, clear() and addAll()
* are used to replace elements.
* <p>
* If the input collection controls its input, such as a Set, and the
* Transformer creates duplicates (or are otherwise invalid), the
* collection may reduce in size due to calling this method.
*
* @param collection the collection to get the input from, may be null
* @param transformer the transformer to perform, may be null
*/
public static void transform(Collection collection, Transformer transformer) {
if (collection != null && transformer != null) {
if (collection instanceof List) {
List list = (List) collection;
for (ListIterator it = list.listIterator(); it.hasNext();) {
it.set(transformer.transform(it.next()));
}
} else {
Collection resultCollection = collect(collection, transformer);
collection.clear();
collection.addAll(resultCollection);
}
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Transform the collection by applying a Transformer to each element.
* <p>
* If the input collection or transformer is null, there is no change made.
* <p>
* This routine is best for Lists, for which set() is used to do the
* transformations "in place." For other Collections, clear() and addAll()
* are used to replace elements.
* <p>
* If the input collection controls its input, such as a Set, and the
* Transformer creates duplicates (or are otherwise invalid), the
* collection may reduce in size due to calling this method.
*
* @param collection the collection to get the input from, may be null
* @param transformer the transformer to perform, may be null
*/
public static void transform(Collection collection, Transformer transformer) {
if (collection != null && transformer != null) {
if (collection instanceof List) {
List list = (List) collection;
for (ListIterator it = list.listIterator(); it.hasNext();) {
it.set(transformer.transform(it.next()));
}
} else {
Collection resultCollection = collect(collection, transformer);
collection.clear();
collection.addAll(resultCollection);
}
}
}
代码示例来源:origin: internetarchive/heritrix3
@SuppressWarnings("unchecked")
@Override
protected int calculatePrecedence(WorkQueue wq) {
// FIXME: it's ridiculously inefficient to do this every time,
// and optimizing will probably require inserting stateful policy
// helper object into WorkQueue -- expected when URI-precedence is
// also supported
int precedence = getBasePrecedence() - 1;
Collection<Integer> increments = CollectionUtils.collect(
Arrays.asList(getIncrementCounts().split(",")),
new Transformer() {
public Object transform(final Object string) {
return Integer.parseInt((String)string);
}});
Iterator<Integer> iter = increments.iterator();
int increment = iter.next();
long successes = wq.getSubstats().getFetchSuccesses();
while(successes>=0) {
successes -= increment;
precedence++;
increment = iter.hasNext() ? iter.next() : increment;
}
return precedence;
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
Collections.sort(returnCategoryFacets, facetPositionComparator);
final Collection<SearchFacet> facets = CollectionUtils.collect(returnCategoryFacets, new Transformer() {
@Override
public Object transform(Object input) {
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
result.addAll(CollectionUtils.collect(order.getOrderAdjustments(), adjustmentToOfferTransformer));
result.addAll(CollectionUtils.collect(item.getOrderItemAdjustments(), adjustmentToOfferTransformer));
result.addAll(CollectionUtils.collect(detail.getOrderItemPriceDetailAdjustments(), adjustmentToOfferTransformer));
result.addAll(CollectionUtils.collect(fg.getFulfillmentGroupAdjustments(), adjustmentToOfferTransformer));
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
CollectionUtils.collect(values, new Transformer() {
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
message.append("The final ordering of activities for the " + getBeanName() + " workflow is: \n");
ArrayList<String> activityNames = new ArrayList<>();
CollectionUtils.collect(activities, new Transformer() {
代码示例来源:origin: commons-collections/commons-collections
public void testCollect() {
Transformer transformer = TransformerUtils.constantTransformer("z");
Collection collection = CollectionUtils.collect(collectionA, transformer);
assertTrue(collection.size() == collectionA.size());
assertTrue(collectionA.contains("a") && ! collectionA.contains("z"));
CollectionUtils.collect(collectionA, transformer, collection);
assertTrue(collection.size() == collectionA.size());
assertTrue(collectionA.contains("a") && ! collectionA.contains("z"));
CollectionUtils.collect(iterator, transformer, collection);
CollectionUtils.collect(iterator, transformer, collection);
assertTrue(collection.size() == collectionA.size());
assertTrue(collectionA.contains("a") && ! collectionA.contains("z"));
collection = CollectionUtils.collect(iterator, transformer);
assertTrue(collection.size() == collectionA.size());
assertTrue(collection.contains("z") && !collection.contains("a"));
collection = CollectionUtils.collect((Iterator) null, (Transformer) null);
assertTrue(collection.size() == 0);
CollectionUtils.collect((Collection) null, transformer, collectionA);
assertTrue(collectionA.size() == size && collectionA.contains("a"));
CollectionUtils.collect(collectionB, null, collectionA);
assertTrue(collectionA.size() == size && collectionA.contains("a"));
代码示例来源:origin: pentaho/mondrian
/**
* Returns a collection of strings corresponding to the name
* or uniqueName of each OlapElement in olapElements, based on the
* flag uniqueName.
*/
private Collection<String> getOlapElementNames(
OlapElement[] olapElements, final boolean uniqueName)
{
return CollectionUtils.collect(
Arrays.asList(olapElements),
new Transformer() {
public Object transform(Object o) {
return uniqueName ? ((OlapElement)o).getUniqueName()
: ((OlapElement)o).getName();
}
});
}
代码示例来源:origin: mulesoft/mule
@Override
public boolean isUpdatedZombieArtifact(String artifactName) {
@SuppressWarnings("rawtypes")
Collection<String> deployedAppNames = collect(artifacts, new BeanToPropertyValueTransformer(ARTIFACT_NAME_PROPERTY));
if (deployedAppNames.contains(artifactName) && (!artifactZombieMap.containsKey(artifactName))) {
return false;
}
// First get saved zombieFile
ZombieArtifact zombieArtifact = artifactZombieMap.get(artifactName);
if ((zombieArtifact != null) && (!zombieArtifact.updatedZombieApp())) {
return false;
}
return true;
}
代码示例来源:origin: pentaho/mondrian
/**
* Filters the children list to those that contain identifiers
* we think we can batch resolve, then transforms the Id list
* to the corresponding NameSegment.
*/
private List<Id.NameSegment> collectChildrenNameSegments(
final Member parentMember, List<Id> children)
{
filter(
children, new Predicate() {
// remove children we can't support
public boolean evaluate(Object theId)
{
Id id = (Id)theId;
return !Util.matches(parentMember, id.getSegments())
&& supportedIdentifier(id);
}
});
return new ArrayList(
CollectionUtils.collect(
children, new Transformer()
{
// convert the collection to a list of NameSegments
public Object transform(Object theId) {
Id id = (Id)theId;
return getLastSegment(id);
}
}));
}
代码示例来源:origin: com.atlassian.jira/jira-core
@SuppressWarnings ( { "unchecked" })
public Collection<String> getOptionIds()
{
return CollectionUtils.collect(lazyConstants, new Transformer()
{
public Object transform(Object input)
{
return ((LazyIssueConstant) input).getId();
}
});
}
代码示例来源:origin: com.atlassian.jira/jira-core
@Override
public long reIndexIssueObjects(final Collection<? extends Issue> issueObjects, final IssueIndexingParams issueIndexingParams)
throws IndexException
{
// We would like to transform the Issue object to GenericValues before re-indexing to ensure that there
// are no discrepancies between them. Once we move the entire system to Issue objects this will be unnecessary.
// Until then, please do *not* change this behaviour.
@SuppressWarnings ({ "unchecked" })
final Collection<GenericValue> genericValues = CollectionUtils.collect(issueObjects, IssueFactory.TO_GENERIC_VALUE);
return reIndexIssues(genericValues, issueIndexingParams);
}
内容来源于网络,如有侵权,请联系作者删除!