private Predicate getPredicate(ExtendedProperties properties, List<Predicate> predicates, String keyPreffix) { String key = keyPreffix + ".predicate.join"; String operator = properties.getString(key, "all"); String[] operators = new String[]{"all", "any", "none", "one"}; int i = ArrayUtils.indexOf(operators, operator.toLowerCase()); switch (i) { case 1: return PredicateUtils.anyPredicate(predicates); case 2: return PredicateUtils.nonePredicate(predicates); case 3: return PredicateUtils.onePredicate(predicates); default: return PredicateUtils.allPredicate(predicates); } }
@SuppressWarnings("unchecked") public static DescribableList<GhprcExtension, GhprcExtensionDescriptor> getJobExtensions(GhprcTrigger trigger, Class<?> ...types) { // First get all global extensions DescribableList<GhprcExtension, GhprcExtensionDescriptor> copied = copyExtensions(trigger.getDescriptor().getExtensions()); // Remove extensions that are specified by job filterList(copied, PredicateUtils.notPredicate(InstanceofPredicate.getInstance(GhprcProjectExtension.class))); // Then get the rest of the extensions from the job copied = copyExtensions(copied, trigger.getExtensions()); // Filter extensions by desired interface filterList(copied, PredicateUtils.anyPredicate(createPredicate(types))); return copied; }
@Override public Set<AgentInfo> getAgentsByApplicationNameWithoutStatus(String applicationName, long timestamp) { if (applicationName == null) { throw new NullPointerException("applicationName must not be null"); } if (timestamp < 0) { throw new IllegalArgumentException("timestamp must not be less than 0"); } List<String> agentIds = this.applicationIndexDao.selectAgentIds(applicationName); List<AgentInfo> agentInfos = this.agentInfoDao.getAgentInfos(agentIds, timestamp); CollectionUtils.filter(agentInfos, PredicateUtils.notNullPredicate()); if (CollectionUtils.isEmpty(agentInfos)) { return Collections.emptySet(); } return new HashSet<>(agentInfos); }
/** * A naive "search" that lists the objects, then filters them. * This is not an efficient search technique and should be avoided * in favor of the solr-base search method * @deprecated */ private String searchList(String query) throws Exception { JSONObject results = new JSONObject(); String annotationsContent = this.index(); JSONArray annotations = (JSONArray) JSONValue.parse(annotationsContent); Collection<Predicate> predicates = new ArrayList<Predicate>(); List<NameValuePair> criteria = URLEncodedUtils.parse(query, Charset.forName(DEFAULT_ENCODING)); for (NameValuePair pair: criteria) { if (pair.getName().equals("limit") || pair.getName().equals("offset")) { continue; } // otherwise add the criteria predicates.add(new AnnotationPredicate(pair.getName(), pair.getValue())); } Predicate allPredicate = PredicateUtils.allPredicate(predicates); CollectionUtils.filter(annotations, allPredicate); results.put("total", annotations.size()); results.put("rows", annotations); return results.toJSONString(); }
public static <T> Collection<T> allFilter(Collection<T> collection, Predicate... predicates) { if (collection == null || collection.isEmpty() || predicates == null) { return collection; } else { // Collection<T> list = new ArrayList<T>(); // list.addAll(collection); Collection<T> list = new ArrayList<>(collection); Predicate predicate = PredicateUtils.allPredicate(predicates); CollectionUtils.filter(list, predicate); return list; } }
public static <T> Collection<T> anyFilter(Collection<T> collection, Predicate... predicates) { if (collection == null || collection.isEmpty() || predicates == null) { return collection; } else { // Collection<T> list = new ArrayList<T>(); // list.addAll(collection); Collection<T> list = new ArrayList<>(collection); Predicate predicate = PredicateUtils.anyPredicate(predicates); CollectionUtils.filter(list, predicate); return list; } }
public static <T> Collection<T> oneFilter(Collection<T> collection, Predicate... predicates) { if (collection == null || collection.isEmpty() || predicates == null) { return collection; } else { // Collection<T> list = new ArrayList<T>(); // list.addAll(collection); Collection<T> list = new ArrayList<>(collection); Predicate predicate = PredicateUtils.onePredicate(predicates); CollectionUtils.filter(list, predicate); return list; } }
public static <T> Collection<T> noneFilter(Collection<T> collection, Predicate... predicates) { if (collection == null || collection.isEmpty() || predicates == null) { return collection; } else { // Collection<T> list = new ArrayList<T>(); // list.addAll(collection); Collection<T> list = new ArrayList<>(collection); Predicate predicate = PredicateUtils.nonePredicate(predicates); CollectionUtils.filter(list, predicate); return list; } }
public static Predicate getPredicateFromSearchFilter(SearchFilter searchFilter) { List<Predicate> predicates = new ArrayList<>(); final String type = searchFilter.getParam(SearchFilter.PARAM_TYPE); final String name = searchFilter.getParam(SearchFilter.PARAM_NAME); final String supertype = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE); final String notSupertype = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE); // Add filter for the type/category if (StringUtils.isNotBlank(type)) { predicates.add(getTypePredicate(type)); } // Add filter for the name if (StringUtils.isNotBlank(name)) { predicates.add(getNamePredicate(name)); } // Add filter for the supertype if (StringUtils.isNotBlank(supertype)) { predicates.add(getSuperTypePredicate(supertype)); } // Add filter for the supertype negation if (StringUtils.isNotBlank(notSupertype)) { predicates.add(new NotPredicate(getSuperTypePredicate(notSupertype))); } return PredicateUtils.allPredicate(predicates); }
public boolean evaluate(Object arg0) { Predicate judgement = new NullPredicate(); if (predicates.size() == 1) { judgement = predicates.get(0); } else { if (conj == Conjunction.AND) { judgement = PredicateUtils.allPredicate(predicates); } else if (conj == Conjunction.OR) { judgement = PredicateUtils.anyPredicate(predicates); } } return judgement.evaluate(arg0); }
private static void filterExtensions(DescriptorExtensionList<GhprcExtension, GhprcExtensionDescriptor> descriptors, Class<? extends GhprcExtensionType>... types) { List<Predicate> predicates = new ArrayList<Predicate>(types.length); for (Class<? extends GhprcExtensionType> type : types) { predicates.add(InstanceofPredicate.getInstance(type)); } Predicate anyPredicate = PredicateUtils.anyPredicate(predicates); for (GhprcExtensionDescriptor descriptor : descriptors) { if (!anyPredicate.evaluate(descriptor)) { descriptors.remove(descriptor); } } }
private MemberFilter(Predicate memberPredicate) { this.memberPredicate = memberPredicate == null ? PredicateUtils.truePredicate() : memberPredicate; }
public TaskFlowState() { tasks = PredicatedList.decorate(Lists.newArrayList(), PredicateUtils.notNullPredicate()); }
/** * * @param predicate * @return */ public static Predicate not(Predicate predicate){ Assert.notNull(predicate); return PredicateUtils.notPredicate(predicate); }
/** * * @param predicates * @return */ public static Predicate and(Predicate... predicates){ Assert.notNull(predicates); return PredicateUtils.allPredicate(predicates); }
/** * * @param predicates * @return */ public static Predicate or(Predicate... predicates){ Assert.notNull(predicates); return PredicateUtils.anyPredicate(predicates); }
/** * @param writer * @param includeHistory * @param session * @throws DataAccessException * @throws HibernateException */ private void writeObjects(final Writer writer, final boolean includeHistory, final Session session, final boolean preserveIds) throws DataAccessException, HibernateException { // Container für die Objekte final List<Object> all = new ArrayList<Object>(); final XStream stream = initXStream(session, true); final XStream defaultXStream = initXStream(session, false); session.flush(); // Alles laden final List<Class< ? >> entities = new ArrayList<Class< ? >>(); entities.addAll(HibernateEntities.instance().getOrderedEntities()); entities.addAll(HibernateEntities.instance().getOrderedHistoryEntities()); for (final Class< ? > entityClass : entities) { final String entitySimpleName = entityClass.getSimpleName(); final String entityType = entityClass.getName(); if (includeHistory == false && entityType.startsWith("de.micromata.hibernate.history.") == true) { // Skip history entries. continue; } List< ? > list = session.createQuery("select o from " + entityType + " o").setReadOnly(true).list(); list = (List< ? >) CollectionUtils.select(list, PredicateUtils.uniquePredicate()); final int size = list.size(); log.info("Writing " + size + " objects"); for (final Iterator< ? > it = list.iterator(); it.hasNext();) { final Object obj = it.next(); if (log.isDebugEnabled()) { log.debug("loaded object " + obj); } Hibernate.initialize(obj); final Class< ? > targetClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj); final ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(targetClass); if (classMetadata == null) { log.fatal("Can't init " + obj + " of type " + targetClass); continue; } // initalisierung des Objekts... defaultXStream.marshal(obj, new CompactWriter(new NullWriter())); if (preserveIds == false) { // Nun kann die ID gelöscht werden classMetadata.setIdentifier(obj, null, EntityMode.POJO); } if (log.isDebugEnabled()) { log.debug("loading evicted object " + obj); } if (this.ignoreFromTopLevelListing.contains(targetClass) == false) { all.add(obj); } } } // und schreiben try { writer.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); } catch (final IOException ex) { // ignore, will fail on stream.marshal() } log.info("Wrote " + all.size() + " objects"); final MarshallingStrategy marshallingStrategy = new ProxyIdRefMarshallingStrategy(); stream.setMarshallingStrategy(marshallingStrategy); stream.marshal(all, new PrettyPrintWriter(writer)); }
protected List< ? > selectUnique(final List< ? > list) { final List< ? > result = (List< ? >) CollectionUtils.select(list, PredicateUtils.uniquePredicate()); return result; }
protected List<O> selectUnique(final List<O> list) { @SuppressWarnings("unchecked") final List<O> result = (List<O>) CollectionUtils.select(list, PredicateUtils.uniquePredicate()); return result; }