@Override public Boolean defaultCase(KvValue<?> value, KvValue<?> other) { return value.equals(other); } }
Stream<ToroDocument> streamByAttRef(String dbName, String colName, AttributeReference attRef, KvValue<?> value) { return getTransaction().streamCollection(dbName, colName) .filter(doc -> { Optional<KvValue<?>> resolved = AttributeRefKvDocResolver.resolve( attRef, doc.getRoot()); return resolved.isPresent() && value.equals(resolved.get()); }); }
void insert(String db, String col, Stream<KvDocument> docs) throws UniqueIndexViolationException { Map<Integer, KvDocument> map = getMap(db, col); List<KvDocument> docList = docs.collect(Collectors.toList()); Optional<KvDocument> repeatedDoc = docList.stream() .filter(doc -> { KvValue<?> mongoId = doc.get(_ID); if (mongoId != null) { Optional<KvDocument> withSameId = map.values().stream() .filter(otherDoc -> mongoId.equals(otherDoc.get(_ID))) .findAny(); return withSameId.isPresent(); } return false; }) .findAny(); if (repeatedDoc.isPresent()) { throw new UniqueIndexViolationException(_ID, repeatedDoc.get()); } docList.forEach(doc -> { int id = idGenerator.getAsInt(); map.put(id, doc); }); }
/** * Two entries are equals if their keys and values are equal. * * @param obj * @return */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (!(obj instanceof DocEntry)) { return false; } DocEntry<?> other = (DocEntry<?>) obj; return this.getKey().equals(other.getKey()) && this.getValue().equals(other.getValue()); }