/** * Returns true if the given iterable contains at least an item that matches the given hamcrest Matcher * 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 to be filtered * @param matcher The hamcrest Matcher used to filter the given iterable * @return True if the given iterable contains at least an item that matches the given hamcrest Matcher false otherwise */ public static boolean exists(Object iterable, Matcher<?> matcher) { return selectFirst(iterable, matcher) != null; }
/** * Selects the first object in this iterable that matches the given hamcrest Matcher * @param matcher The hamcrest Matcher used to retain the given iterable * @return The first object in the given iterable that matches the given hamcrest Matcher or null if there is no such object */ public T first(Matcher<?> matcher) { return (T)Lambda.selectFirst(getInner(), matcher); }
protected Artifact getDependency( Matcher<? extends Artifact>... matchers ) { return selectFirst(getDependencies(), allOf(matchers)); }
private LanguageEventData selectByEventType(List<LanguageEventData> data, String eventType) { return selectFirst(data, having(on(LanguageEventData.class).getEventType(), equalTo(eventType))); }
@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 long getCurrentId(Map<String, Long> stepReferences, Deque<Step> steps) { Long currentId; long max = Lambda.max(stepReferences); Map.Entry maxEntry = selectFirst(stepReferences.entrySet(), having(on(Map.Entry.class).getValue(), equalTo(max))); String referenceKey = (String) (maxEntry).getKey(); Step step = null; for (Step stepItem : steps) { if (stepItem.getName().equals(referenceKey)) { step = stepItem; break; } } if (step == null || !step.isParallelLoop()) { // the reference is not a step or is not a parallel loop step currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS; } else { //async step currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS + NUMBER_OF_PARALLEL_LOOP_EXECUTION_STEPS; } return currentId; }
private long getCurrentId(Map<String, Long> stepReferences, Deque<Step> steps) { Long currentId; long max = Lambda.max(stepReferences); Map.Entry maxEntry = selectFirst(stepReferences.entrySet(), having(on(Map.Entry.class).getValue(), equalTo(max))); String referenceKey = (String) (maxEntry).getKey(); Step step = null; for (Step stepItem : steps) { if (stepItem.getName().equals(referenceKey)) { step = stepItem; break; } } if (step == null || !step.isParallelLoop()) { // the reference is not a step or is not a parallel loop step currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS; } else { //async step currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS + NUMBER_OF_PARALLEL_LOOP_EXECUTION_STEPS; } return currentId; }
@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 Map<String, Executable> fetchFlowReferences(Executable executable, Collection<Executable> availableDependencies, Map<String, Executable> resolvedDependencies) { for (String refId : executable.getDependencies()) { //if it is already in the references we do nothing if (resolvedDependencies.get(refId) == null) { Executable matchingRef = Lambda.selectFirst(availableDependencies, having(on(Executable.class).getId(), equalTo(refId))); if (matchingRef == null) { throw new RuntimeException("Reference: \'" + refId + "\' in executable: \'" + executable.getName() + "\', wasn't found in path"); } //first we put the reference on the map resolvedDependencies.put(matchingRef.getId(), matchingRef); if (matchingRef.getType().equals(SlangTextualKeys.FLOW_TYPE)) { //if it is a flow we recursively resolvedDependencies.putAll(fetchFlowReferences(matchingRef, availableDependencies, resolvedDependencies)); } } } return resolvedDependencies; }
private SelectiveMatcher findSelectiveMatcherByConnectionIdentifier( SelectiveMatcher[] selectiveMatchers) { return selectFirst( selectiveMatchers, having(on(SelectiveMatcher.class).identifier(), equalTo(identifier)).and( having(on(SelectiveMatcher.class).location(), notNullValue()))); }
public ManagedMongoDbLifecycleManager getStartedServer(int port) { return selectFirst( this.servers, having(on(ManagedMongoDbLifecycleManager.class).getPort(), is(port)).and(having(on(ManagedMongoDbLifecycleManager.class).isReady(), is(true)))); }
private SelectiveMatcher findSelectiveMatcherByConnectionIdentifier( SelectiveMatcher[] selectiveMatchers) { return selectFirst( selectiveMatchers, having(on(SelectiveMatcher.class).identifier(), equalTo(identifier)).and( having(on(SelectiveMatcher.class).location(), notNullValue()))); }
public ManagedMongoDbLifecycleManager getStoppedServer(int port) { return selectFirst( this.servers, having(on(ManagedMongoDbLifecycleManager.class).getPort(), is(port)).and(having(on(ManagedMongoDbLifecycleManager.class).isReady(), is(false)))); }
public ManagedMongoDbLifecycleManager getStartedServer(int port) { return selectFirst( this.servers, having(on(ManagedMongoDbLifecycleManager.class).getPort(), is(port)).and(having(on(ManagedMongoDbLifecycleManager.class).isReady(), is(true)))); }
private Map<String, Executable> fetchFlowReferences(Executable executable, Collection<Executable> availableDependencies, Map<String, Executable> resolvedDependencies) { for (String refId : executable.getExecutableDependencies()) { //if it is already in the references we do nothing if (resolvedDependencies.get(refId) == null) { Executable matchingRef = selectFirst(availableDependencies, having(on(Executable.class).getId(), equalTo(refId))); if (matchingRef == null) { throw new RuntimeException("Reference: \'" + refId + "\' in executable: \'" + executable.getName() + "\', wasn't found in path"); } //first we put the reference on the map resolvedDependencies.put(matchingRef.getId(), matchingRef); if (matchingRef.getType().equals(SlangTextualKeys.FLOW_TYPE)) { //if it is a flow we recursively resolvedDependencies .putAll(fetchFlowReferences(matchingRef, availableDependencies, resolvedDependencies)); } } } return resolvedDependencies; }
public ManagedMongoDbLifecycleManager getStoppedServer(int port) { return selectFirst( this.servers, having(on(ManagedMongoDbLifecycleManager.class).getPort(), is(port)).and(having(on(ManagedMongoDbLifecycleManager.class).isReady(), is(false)))); }
public ManagedRedisLifecycleManager getStartedServer(int port) { if(this.master.getPort() == port && this.master.isReady()) { return this.master; } return selectFirst( this.slaveServers, having(on(ManagedRedisLifecycleManager.class).getPort(), is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(true)))); }
public ManagedRedisLifecycleManager getStoppedServer(int port) { if(this.master.getPort() == port && !this.master.isReady()) { return this.master; } return selectFirst( this.slaveServers, having(on(ManagedRedisLifecycleManager.class).getPort(), is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(false)))); }
public ManagedRedisLifecycleManager getStartedServer(int port) { if(this.master.getPort() == port && this.master.isReady()) { return this.master; } return selectFirst( this.slaveServers, having(on(ManagedRedisLifecycleManager.class).getPort(), is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(true)))); }
public ManagedRedisLifecycleManager getStoppedServer(int port) { if(this.master.getPort() == port && !this.master.isReady()) { return this.master; } return selectFirst( this.slaveServers, having(on(ManagedRedisLifecycleManager.class).getPort(), is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(false)))); }