本文整理汇总了Java中org.apache.commons.collections.Predicate类的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Predicate类属于org.apache.commons.collections包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSelects
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testSelects() {
Record r = new Record();
r.setUserIdentityARN("arn:sample");
List<Record> records = Arrays.asList(r, new Record());
Collection<Record> sample = CollectionUtils.select(records, new Predicate() {
@Override
public boolean evaluate(Object o) {
return o instanceof Record && ((Record) o).getUserIdentityARN() != null && ((Record) o).getUserIdentityARN().contains("sample");
}
});
Assertions.assertThat(sample).hasSize(1);
}
示例2: getRule
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
public IfExpression getRule(final String ruleId) {
if (CollectionUtils.isEmpty(items)) {
return null;
}
return (IfExpression)CollectionUtils.find(items, new Predicate() {
@Override
public boolean evaluate(Object object) {
return ((IfExpression)object).getId().equals(ruleId);
}
});
}
示例3: getFileTypePatterns
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
/**
* Get the list of patterns for a specified filetype.
* You will always get a list. In this order.
* <ul>
* <li>The Configured List</li>
* <li>The Default List</li>
* <li>A single item list of <code>"**/*"</code></li>
* </ul>
*
* @param id the id to lookup.
* @return the list of patterns.
*/
public List<String> getFileTypePatterns( String id )
{
Configuration config = archivaConfiguration.getConfiguration();
Predicate selectedFiletype = new FiletypeSelectionPredicate( id );
RepositoryScanningConfiguration repositoryScanningConfiguration = config.getRepositoryScanning();
if ( repositoryScanningConfiguration != null )
{
FileType filetype =
(FileType) CollectionUtils.find( config.getRepositoryScanning().getFileTypes(), selectedFiletype );
if ( ( filetype != null ) && CollectionUtils.isNotEmpty( filetype.getPatterns() ) )
{
return filetype.getPatterns();
}
}
List<String> defaultPatterns = defaultTypeMap.get( id );
if ( CollectionUtils.isEmpty( defaultPatterns ) )
{
return Collections.singletonList( "**/*" );
}
return defaultPatterns;
}
示例4: getGiftItems
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
/**
* 获取赠品项
*
* @return 赠品项
*/
@Transient
public Set<GiftItem> getGiftItems() {
Set<GiftItem> giftItems = new HashSet<GiftItem>();
for (Promotion promotion : getPromotions()) {
if (promotion.getGiftItems() != null) {
for (final GiftItem giftItem : promotion.getGiftItems()) {
GiftItem target = (GiftItem) CollectionUtils.find(giftItems, new Predicate() {
public boolean evaluate(Object object) {
GiftItem other = (GiftItem) object;
return other != null && other.getGift().equals(giftItem.getGift());
}
});
if (target != null) {
target.setQuantity(target.getQuantity() + giftItem.getQuantity());
} else {
giftItems.add(giftItem);
}
}
}
}
return giftItems;
}
示例5: validateUserProjectDiff
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
/**
* ユーザーが同一プロジェクトに属していない場合はエラー.
* @param users ユーザー
* @throws ServiceAbortException 同一プロジェクトに属していない
*/
private void validateUserProjectDiff(List<User> users) throws ServiceAbortException {
String projectId = getCurrentProjectId();
SearchUserCondition condition = new SearchUserCondition();
condition.setProjectId(projectId);
List<ProjectUser> projectUsers = findProjectUser(condition);
for (final User u : users) {
// プロジェクトに所属するユーザーリストに登録対象ユーザーが存在しなければエラー
Object ret = CollectionUtils.find(projectUsers, new Predicate() {
public boolean evaluate(Object object) {
ProjectUser pu = (ProjectUser) object;
return u.getEmpNo().equals(pu.getUser().getEmpNo());
}
});
if (ret == null) {
throw new ServiceAbortException(
"invalid user",
ApplicationMessageCode.CANNOT_PERFORM_BECAUSE_USER_ALREADY_DELETED,
u.getLabel());
}
}
}
示例6: validateProjectUserExists
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
/**
* 選択されたプロジェクトユーザーのユーザーが同一プロジェクトに属しているかチェックする.
* @param id ID
* @param users ユーザーリスト
* @throws ServiceAbortException プロジェクトに属していない
*/
private void validateProjectUserExists(Long id, List<User> users) throws ServiceAbortException {
SearchUserCondition condition = new SearchUserCondition();
condition.setProjectId(getCurrentProjectId());
UserDao dao = getDao(UserDao.class);
List<ProjectUser> projectUsers = dao.findProjectUser(condition);
for (final User u : users) {
// プロジェクトに所属するユーザーリストに登録対象ユーザーが存在しなければエラー
Object ret = CollectionUtils.find(projectUsers, new Predicate() {
public boolean evaluate(Object object) {
ProjectUser pu = (ProjectUser) object;
return u.getEmpNo().equals(pu.getUser().getEmpNo());
}
});
if (ret == null) {
throw new ServiceAbortException(
"invalid user",
ApplicationMessageCode.CANNOT_PERFORM_BECAUSE_USER_ALREADY_DELETED,
u.getLabel());
}
}
}
示例7: getClustersStat
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
public static int getClustersStat(String clusters) {
Predicate predicate = new Predicate() {
public boolean evaluate(Object object) {
String clustersId = ((ClustersState) object).getClusters();
return clustersId.compareTo(clusters) == 0;
}
};
Iterator iterator = new FilterIterator(stateArray.iterator(), predicate);
ClustersState state = null;
while (iterator.hasNext()) {
state = (ClustersState) iterator.next();
break;
}
return (state != null) ? state.getState() : 0;
}
示例8: selectByClusters
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
public static ConsumerClusters selectByClusters(String clusters) {
Predicate predicate = new Predicate() {
public boolean evaluate(Object object) {
String id = ((ClustersRelation) object).getId();
return id.compareTo(clusters) == 0;
}
};
Iterator iterator = new FilterIterator(relationArray.iterator(), predicate);
ClustersRelation relation = null;
while (iterator.hasNext()) {
relation = (ClustersRelation) iterator.next();
break;
}
return (relation != null) ? relation.getClusters() : null;
}
示例9: getPossibleValuesByParent
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
public Collection<CustomFieldPossibleValue> getPossibleValuesByParent(final CustomFieldPossibleValue parentValue, final Boolean onlyEnabled) {
// When this field has no parent, return all values
if (parent == null) {
return possibleValues;
}
// When there's no parent value, or it don't match this field's parent, return an empty list
if (possibleValues == null || parentValue == null || !parent.equals(parentValue.getField())) {
return Collections.emptyList();
}
// Filter the possible values by parent value
final Collection<CustomFieldPossibleValue> filteredPossibleValues = new ArrayList<CustomFieldPossibleValue>(possibleValues);
CollectionUtils.filter(filteredPossibleValues, new Predicate() {
@Override
public boolean evaluate(final Object object) {
final CustomFieldPossibleValue possibleValue = (CustomFieldPossibleValue) object;
return parentValue.equals(possibleValue.getParent()) && (onlyEnabled ? possibleValue.isEnabled() : true);
}
});
return filteredPossibleValues;
}
示例10: executeQuery
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected List<?> executeQuery(final ActionContext context) {
final MembersReportHandler reportHandler = getReportHandler();
final Pair<MembersTransactionsReportDTO, Iterator<MemberTransactionSummaryReportData>> pair = reportHandler.handleTransactionsSummary(context);
final MembersTransactionsReportDTO dto = pair.getFirst();
final Iterator<MemberTransactionSummaryReportData> reportIterator = pair.getSecond();
final Iterator iterator = IteratorUtils.filteredIterator(reportIterator, new Predicate() {
@Override
public boolean evaluate(final Object element) {
final MemberTransactionSummaryReportData data = (MemberTransactionSummaryReportData) element;
if (dto.isIncludeNoTraders()) {
return true;
}
return data.isHasData();
}
});
return new IteratorListImpl(iterator);
}
示例11: executeQuery
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected List<?> executeQuery(final ActionContext context) {
final MembersReportHandler reportHandler = getReportHandler();
final Pair<MembersTransactionsReportDTO, Iterator<MemberTransactionDetailsReportData>> pair = reportHandler.handleTransactionsDetails(context);
final MembersTransactionsReportDTO dto = pair.getFirst();
final Iterator<MemberTransactionDetailsReportData> reportIterator = pair.getSecond();
final Iterator iterator = IteratorUtils.filteredIterator(reportIterator, new Predicate() {
@Override
public boolean evaluate(final Object element) {
final MemberTransactionDetailsReportData data = (MemberTransactionDetailsReportData) element;
if (dto.isIncludeNoTraders()) {
return true;
}
return data.getAmount() != null;
}
});
return new IteratorListImpl(iterator);
}
示例12: listImages
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
@Nonnull
@Override
public Iterable<MachineImage> listImages(@Nullable final ImageFilterOptions options) throws CloudException, InternalException {
if (options != null && !ImageClass.MACHINE.equals(options.getImageClass())) {
return Collections.emptyList();
}
if(options != null)
options.withAccountNumber(provider.getContext().getAccountNumber());
return getImages(new Predicate() {
@Override
public boolean evaluate(Object object) {
if(options != null)
return options.matches((MachineImage)object);
else
return provider.getContext().getAccountNumber().equals(((MachineImage)object).getProviderOwnerId());
}
});
}
示例13: removeVlan
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
public void removeVlan(final String vlanId) throws CloudException, InternalException {
WAPVMNetworksModel networksModel = new AzurePackRequester(provider,
new AzurePackNetworkRequests(provider).listVMNetworks().build()).withJsonProcessor(WAPVMNetworksModel.class).execute();
WAPVMNetworkModel foundNetwork = (WAPVMNetworkModel)CollectionUtils.find(networksModel.getVirtualMachineNetworks(), new Predicate() {
@Override
public boolean evaluate(Object object) {
return ((WAPVMNetworkModel)object).getId().equalsIgnoreCase(vlanId);
}
});
if(foundNetwork == null)
throw new InternalException("Invalid network id provided for deletion");
new AzurePackRequester(provider, new AzurePackNetworkRequests(provider).deleteVMNetwork(foundNetwork).build()).execute();
}
示例14: getDBProductsFromFile
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
private List<WAPDatabaseProducts.WAPDatabaseProduct> getDBProductsFromFile() throws InternalException {
List<WAPDatabaseProducts> dbProducts = new ArrayList<>();
try {
InputStream inputStream = getDBProductFileStream(this.provider.getDBProductsResource());
dbProducts.addAll(Arrays.asList(new JsonStreamToObjectProcessor<WAPDatabaseProducts[]>().read(inputStream, WAPDatabaseProducts[].class)));
} catch (Exception ex) {
throw new InternalException("Cannot load products from dbproducts.json file");
}
//if there is only one cloud provider in the json file, return all the products as default
if(dbProducts.size() == 1)
return Arrays.asList(dbProducts.get(0).getProducts());
CollectionUtils.filter(dbProducts, new Predicate() {
@Override
public boolean evaluate(Object object) {
WAPDatabaseProducts products = (WAPDatabaseProducts)object;
return provider.getContext().getCloud().getCloudName().equalsIgnoreCase(products.getCloud()) && provider.getContext().getCloud().getProviderName().equalsIgnoreCase(products.getProvider());
}
});
if(dbProducts.size() != 1)
return Arrays.asList();
return Arrays.asList(dbProducts.get(0).getProducts());
}
示例15: findMarshaller
import org.apache.commons.collections.Predicate; //导入依赖的package包/类
private SearchCriterionMarshaller findMarshaller(final SearchCriterion criterion) {
SearchCriterionMarshaller marshaller = cachedMarshallers.get(criterion.getClass());
if (marshaller == null) {
marshaller = (SearchCriterionMarshaller) CollectionUtils.find(marshallers,
new Predicate() {
@Override
public boolean evaluate(Object arg0) {
SearchCriterionMarshaller marshaller = (SearchCriterionMarshaller) arg0;
return marshaller.supports(criterion.getClass());
}
});
// caching here for later use
cachedMarshallers.put(criterion.getClass(), marshaller);
}
return marshaller;
}