List of usage examples for org.apache.commons.collections.functors EqualPredicate EqualPredicate
public EqualPredicate(Object object)
From source file:com.doculibre.constellio.utils.EqualityUtils.java
public static <T extends Object> boolean contains(Collection<T> collection, T bean, String propertyName) { Object propertyValue;/* w ww. ja v a 2 s. co m*/ try { propertyValue = PropertyUtils.getProperty(bean, propertyName); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } EqualPredicate equalityPredicate = new EqualPredicate(propertyValue); BeanPredicate beanPredicate = new BeanPredicate(propertyName, equalityPredicate); return CollectionUtils.exists(collection, beanPredicate); }
From source file:eionet.gdem.services.db.dao.SchemaDaoTest.java
@Test public void getSchemasWithRelations() { List<Schema> schemas = schemaDao.getSchemasWithRelations(); Schema schema = (Schema) CollectionUtils.find(schemas, new BeanPredicate("id", new EqualPredicate("1"))); assertEquals("http://dd.eionet.europa.eu/GetSchema?id=TBL4564", schema.getSchema()); assertEquals("Groundwater schema", schema.getDescription()); assertEquals("seed-gw-schema.xsd", schema.getUplSchemaFileName()); assertEquals(2, schema.getCountQaScripts()); assertEquals(2, schema.getCountStylesheets()); }
From source file:com.googelcode.jpractices.Person.java
/** * select's the Person object's from collection of person objects based on arg * @param propertyName - Person's attribute (firstName (or) lastName (or) salary ) * @param value - Value to be compared to propertyName *///w w w . j a va2s.c o m void selectObjectsByName(String propertyName, String value) { EqualPredicate nameEqlPredicate = new EqualPredicate(value); BeanPredicate beanPredicate = new BeanPredicate(propertyName, nameEqlPredicate); Collection<Person> filteredCollection = CollectionUtils.select(personList, beanPredicate); System.out.println("Below are person object(s) whose " + propertyName + " is " + value); System.out .println("Matches for entered criteria " + CollectionUtils.countMatches(personList, beanPredicate)); for (Person person : filteredCollection) { System.out.println(person); } }
From source file:com.googelcode.jpractices.Person.java
/** */*from ww w .j a v a2 s . co m*/ * Here we are adding multiple predicate * filters the collection so that final person object will contain * firstName as "ganesh" & lastName as "gowtham" */ void filterDataUsingMultipleCriteria() { EqualPredicate firstNameEqlPredicate = new EqualPredicate("ganesh"); BeanPredicate firtsNameBeanPredicate = new BeanPredicate("firstName", firstNameEqlPredicate); EqualPredicate lastNameEqlPredicate2 = new EqualPredicate("gowtham"); BeanPredicate lastNameBeanPredicate2 = new BeanPredicate("lastName", lastNameEqlPredicate2); Predicate[] allPredicateArray = { firtsNameBeanPredicate, lastNameBeanPredicate2 }; Predicate allPredicate = PredicateUtils.allPredicate(allPredicateArray); Collection<Person> filteredCollection = CollectionUtils.select(personList, allPredicate); for (Person person : filteredCollection) { System.out.println(person); } }
From source file:eionet.gdem.services.db.dao.StylesheetDaoTest.java
@Test public void getAllStylesheets() { List<Stylesheet> stylesheets = stylesheetDao.getStylesheets(); Stylesheet stylesheet = (Stylesheet) CollectionUtils.find(stylesheets, new BeanPredicate("convId", new EqualPredicate("180"))); assertTrue(stylesheets.size() > 10); assertEquals("stylesheet", stylesheet.getDescription()); assertEquals("HTML", stylesheet.getType()); assertEquals("file.xsl", stylesheet.getXslFileName()); }
From source file:eionet.gdem.services.db.dao.SchemaDaoTest.java
@Test public void getSchemasWithNoRelations() { List<Schema> schemas = schemaDao.getSchemasWithRelations(); Schema schema = (Schema) CollectionUtils.find(schemas, new BeanPredicate("id", new EqualPredicate("6"))); assertEquals("http://dd.eionet.europa.eu/GetSchema?id=TBL112", schema.getSchema()); assertEquals("No relations", schema.getDescription()); assertNull(schema.getUplSchemaFileName()); assertEquals(0, schema.getCountQaScripts()); assertEquals(0, schema.getCountStylesheets()); }
From source file:com.googelcode.jpractices.Person.java
/** * select's the person object from collcetion based on propetyName and value * @param propertyName - Person's attribute (firstName (or) lastName (or) salary ) * @param value - Value to be compared to propertyName *///from w ww. j a v a 2s .com void selectObjectFromCollection(String propertyName, String value) { EqualPredicate nameEqlPredicate = new EqualPredicate(value); BeanPredicate beanPredicate = new BeanPredicate(propertyName, nameEqlPredicate); System.out.println("Below are person object whose " + propertyName + " is " + value); System.out.println(CollectionUtils.find(personList, beanPredicate)); }
From source file:eionet.gdem.web.struts.stylesheet.EditStylesheetFormAction.java
@Override public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { ActionMessages errors = new ActionMessages(); StylesheetForm form = (StylesheetForm) actionForm; String stylesheetId = httpServletRequest.getParameter("stylesheetId"); if (stylesheetId == null || stylesheetId.equals("")) { stylesheetId = (String) httpServletRequest.getAttribute("stylesheetId"); }/* www. jav a 2 s . c o m*/ ConvTypeHolder ctHolder = new ConvTypeHolder(); StylesheetManager stylesheetManager = new StylesheetManager(); try { Stylesheet stylesheet = stylesheetManager.getStylesheet(stylesheetId); if (stylesheet == null) { try { httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); } catch (IOException ex) { LOGGER.error("Failed to set 404 response status", ex); } return actionMapping.findForward(null); } form.setDescription(stylesheet.getDescription()); form.setOutputtype(stylesheet.getType()); form.setStylesheetId(stylesheet.getConvId()); form.setXsl(stylesheet.getXsl()); form.setXslContent(stylesheet.getXslContent()); form.setXslFileName(stylesheet.getXslFileName()); form.setModified(stylesheet.getModified()); form.setChecksum(stylesheet.getChecksum()); form.setSchemas(stylesheet.getSchemas()); // set empty string if dependsOn is null to avoid struts error in define tag: // Define tag cannot set a null value form.setDependsOn(stylesheet.getDependsOn() == null ? "" : stylesheet.getDependsOn()); if (stylesheet.getSchemas().size() > 0) { //set first schema for Run Conversion link form.setSchema(stylesheet.getSchemas().get(0).getSchema()); // check if any related schema has type=EXCEL, if yes, then depends on info should be visible List<Schema> relatedSchemas = new ArrayList<Schema>(stylesheet.getSchemas()); CollectionUtils.filter(relatedSchemas, new BeanPredicate("schemaLang", new EqualPredicate("EXCEL"))); if (relatedSchemas.size() > 0) { form.setShowDependsOnInfo(true); List<Stylesheet> existingStylesheets = new ArrayList<Stylesheet>(); for (Schema relatedSchema : relatedSchemas) { CollectionUtils.addAll(existingStylesheets, stylesheetManager .getSchemaStylesheets(relatedSchema.getId(), stylesheetId).toArray()); } form.setExistingStylesheets(existingStylesheets); } } ctHolder = stylesheetManager.getConvTypes(); /** FIXME - do we need the list of DD XML Schemas on the page StylesheetListHolder stylesheetList = StylesheetListLoader.getGeneratedList(httpServletRequest); List<Schema> schemas = stylesheetList.getDdStylesheets(); httpServletRequest.setAttribute("stylesheet.DDSchemas", schemas); */ /* String schemaId = schema.getSchemaId(stylesheet.getSchema()); if (!Utils.isNullStr(schemaId)) { httpServletRequest.setAttribute("schemaInfo", schema.getSchema(schemaId)); httpServletRequest.setAttribute("existingStylesheets", stylesheetManager.getSchemaStylesheets(schemaId, stylesheetId)); } */ //httpServletRequest.setAttribute(StylesheetListLoader.STYLESHEET_LIST_ATTR, StylesheetListLoader.getStylesheetList(httpServletRequest)); } catch (DCMException e) { e.printStackTrace(); LOGGER.error("Edit stylesheet error", e); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e.getErrorCode())); saveErrors(httpServletRequest, errors); } //TODO why is it needed to update session attribute in each request httpServletRequest.getSession().setAttribute("stylesheet.outputtype", ctHolder); return actionMapping.findForward("success"); }
From source file:eionet.cr.web.util.columns.SubjectPredicateColumn.java
/** * @see eionet.cr.web.util.columns.SearchResultColumn#format(java.lang.Object) * * Gets the collection of objects matching to the given predicate in the given subject. Formats the given collection to * comma-separated string. For literal objects, simply the value of the literal will be used. For resource objects, * clickable factsheet links will be created. *//*from ww w . ja v a 2 s. co m*/ @Override public String format(Object object) { String result = null; if (object != null && object instanceof SubjectDTO && predicateUri != null) { SubjectDTO subjectDTO = (SubjectDTO) object; Collection<ObjectDTO> objects = subjectDTO.getObjectsForSearchResultsDisplay(predicateUri, getLanguages()); if (predicateUri.equals(Predicates.RDFS_LABEL)) { if (objects.isEmpty()) { Collection<String> rdfTypes = subjectDTO.getObjectValues(Predicates.RDF_TYPE); if (CollectionUtils.isEmpty(rdfTypes) && subjectTypes != null) { rdfTypes = Arrays.asList(subjectTypes); } if (CollectionUtils.exists(rdfTypes, new EqualPredicate(Subjects.DATACUBE_OBSERVATION))) { // If type is DataCube observation, then special handling. result = StringUtils.substringAfter(subjectDTO.getUri(), ScoreboardSparqlDAO.OBSERVATION_URI_PREFIX); if (StringUtils.isBlank(result)) { result = subjectDTO.getUri(); } } else { result = URIUtil.extractURILabel(subjectDTO.getUri(), SubjectDTO.NO_LABEL); } } else { result = objectValuesToCSV(objects); } logger.debug(result); result = buildFactsheetLink(subjectDTO.getUri(), StringEscapeUtils.escapeXml(result), false); } else if (!objects.isEmpty()) { StringBuffer buf = new StringBuffer(); for (ObjectDTO o : objects) { if (buf.length() > 0) { buf.append(", "); } if (o.isLiteral()) { buf.append(o.getValue()); } else { String label = o.getDerviedLiteralValue(); if (label == null) { label = URIUtil.extractURILabel(o.getValue(), SubjectDTO.NO_LABEL); } buf.append(buildFactsheetLink(o.getValue(), StringEscapeUtils.escapeXml(label), true)); } } result = buf.toString(); } } return StringUtils.isBlank(result) ? " " : result; }
From source file:com.mindquarry.persistence.mock.SessionMock.java
private Map<String, Predicate> properties(String queryPredicate) { Map<String, Predicate> result = new HashMap<String, Predicate>(); for (String simplePredicate : queryPredicate.split("and")) { String comparator = comparator(simplePredicate); String[] nameValue = simplePredicate.trim().split(comparator); Predicate predicate = new EqualPredicate(nameValue[1].trim().replace("'", "")); if (isNotEquals(comparator)) predicate = new NotPredicate(predicate); result.put(nameValue[0], predicate); }//from w w w . jav a 2s. co m return result; }