Refine search
public void addDependantObservation(MRSObservation mrsObservation) { List<? extends MRSObservation> existingObservationList = Lambda.filter(having(on(CouchObservation.class).getConceptName(), is(equalTo(mrsObservation.getConceptName()))), dependantObservations); if (!existingObservationList.isEmpty()) { dependantObservations.remove(existingObservationList.get(0)); } dependantObservations.add(convertObservationToCouchObservation(mrsObservation)); }
/** * Counts the number of occurrencies of the argument's value in the objects of the given iterable * Actually it handles also Maps, Arrays and Iterator by collecting their values. * Note that this method accepts an Object in order to be used in conjunction with the {@link Lambda#forEach(Iterable)}. * @param iterable The iterable of objects' arguments to be counted * @param argument An argument defined using the {@link Lambda#on(Class)} method * @return A map having as values the number of occurrencies of the corresponding object's argument in the given iterable */ public static <A> Map<A, Integer> count(Object iterable, A argument) { return count(extract(iterable, argument)); }
private static PersonName getFirstName(Set<PersonName> names) { List<PersonName> personNames = filter(having(on(PersonName.class).isPreferred(), is(false)), names); if (CollectionUtils.isEmpty(personNames)) { personNames = filter(having(on(PersonName.class).isPreferred(), is(true)), names); } return (!personNames.isEmpty()) ? personNames.get(0) : null; }
private LanguageEventData selectByEventType(List<LanguageEventData> data, String eventType) { return selectFirst(data, having(on(LanguageEventData.class).getEventType(), equalTo(eventType))); }
private SelectiveMatcher findSelectiveMatcherByConnectionIdentifier( SelectiveMatcher[] selectiveMatchers) { return selectFirst( selectiveMatchers, having(on(SelectiveMatcher.class).identifier(), equalTo(identifier)).and( having(on(SelectiveMatcher.class).location(), notNullValue()))); }
private static ColumnFamilyDefinition checkColumnFamilyName(List<ColumnFamilyDefinition> columnFamilyDefinitions, ColumnFamilyModel expectedColumnFamilyModel) throws Error { ColumnFamilyDefinition columnFamily = selectUnique(columnFamilyDefinitions, having(on(ColumnFamilyDefinition.class).getName(), equalTo(expectedColumnFamilyModel.getName()))); if (columnFamily == null) { throw FailureHandler.createFailure("Expected name of column family is %s but was not found.", expectedColumnFamilyModel.getName()); } return columnFamily; }
@Override public boolean compare(Neo4jConnectionCallback connection, InputStream dataset) throws NoSqlAssertionError, Throwable { DataParser dataParser = new DataParser(); List<Object> expectedObjects = dataParser.readValues(dataset); Multimap<Class<?>, Object> expectedGroupByClass = groupByClass(expectedObjects); Set<Class<?>> expectedClasses = expectedGroupByClass.keySet(); for (Class<?> expectedClass : expectedClasses) { Collection<Object> expectedObjectsByClass = expectedGroupByClass.get(expectedClass); List<Object> insertedObjects = findAndFetchAllEntitiesByClass(neo4jTemplate(connection), expectedClass); for (Object expectedObject : expectedObjectsByClass) { Object selectFirst = selectFirst(insertedObjects, equalTo(expectedObject)); if(selectFirst == null) { throw new NoSqlAssertionError(String.format("Object %s is not found in graph.", expectedObject.toString())); } } } return true; }
private void setPersonAttributes(MRSPatient patient, Patient openMRSPatient, List<PersonAttributeType> allPersonAttributeTypes) { MRSPerson mrsPerson = patient.getPerson(); if (CollectionUtils.isNotEmpty(mrsPerson.getAttributes())) { for (MRSAttribute attribute : mrsPerson.getAttributes()) { PersonAttributeType attributeType = (PersonAttributeType) selectUnique(allPersonAttributeTypes, having(on(PersonAttributeType.class).getName(), equalTo(attribute.getName()))); openMRSPatient.addAttribute(new PersonAttribute(attributeType, attribute.getValue())); } } } }
private <T extends Serializable> void dispatch(List<? extends Serializable> messages, Class<T> messageClass, Handler<T> handler){ @SuppressWarnings("unchecked") List<T> filteredMessages = (List<T>) filter(Matchers.instanceOf(messageClass), messages); if (!messages.isEmpty()){ handler.handle(filteredMessages); } }
@Override public List<Alert> filter(List<Alert> alerts, AlertCriteria alertCriteria) { List<Alert> greaterThanFromDateAlerts = Lambda.filter(having(on(Alert.class).getDateTimeInMillis(), greaterThanOrEqualTo(alertCriteria.fromDate().getMillis())), alerts); return Lambda.filter(having(on(Alert.class).getDateTimeInMillis(), lessThanOrEqualTo(alertCriteria.toDate().getMillis())), greaterThanFromDateAlerts); } };
@Override public CompilationArtifact compile(SlangSource source, Set<SlangSource> dependencies) { Validate.notNull(source, "Source can not be null"); Set<SlangSource> dependencySources = new HashSet<>(filter(notNullValue(), dependencies)); try { return compiler.compile(source, dependencySources); } catch (Exception e) { logger.error("Failed compilation for source : " + source.getName() + " ,Exception is : " + e.getMessage()); throw new RuntimeException(e); } }
public static List<AttributePathHelper> prepareAttributePathHelpers(final List<AttributePathHelper> attributePaths, final int level) { // only relevant attribute paths final List<AttributePathHelper> filteredAttributePaths = Lambda.filter( Lambda.having(Lambda.on(AttributePathHelper.class).length(), Matchers.greaterThanOrEqualTo(level)), attributePaths); if (filteredAttributePaths == null || filteredAttributePaths.isEmpty()) { return null; } // sort return Lambda.sort(filteredAttributePaths, Lambda.on(AttributePathHelper.class).length()); }
public static List<AttributePathHelper> getNextAttributePathHelpersForLevelRootAttributePath(final List<AttributePathHelper> attributePaths, final String levelRootAttributePath, final int level) { // only attribute paths for level root attribute path final List<AttributePathHelper> levelRootAttributePaths = Lambda.filter( Lambda.having(Lambda.on(AttributePathHelper.class).toString(), Matchers.startsWith(levelRootAttributePath)), attributePaths); if (levelRootAttributePaths == null || levelRootAttributePaths.isEmpty()) { return null; } // only level attribute paths for next level return AttributePathHelperHelper.prepareAttributePathHelpers(levelRootAttributePaths, level + 1); }
private void addCustomPropertiesTo(Map<String, String> buildProperties) { List<String> sysInfoKeys = filter(startsWith("sysinfo."), environmentVariables.getKeys()); for(String key : sysInfoKeys) { String simplifiedKey = key.replace("sysinfo.", ""); String expression = environmentVariables.getProperty(key); String value = (isGroovyExpression(expression)) ? evaluateGroovyExpression(key, expression) : expression; buildProperties.put(humanizedFormOf(simplifiedKey), value); } }