public Stream<VarAdmin.Casting> getCastings() { return castings.stream(); }
@Override public Stream<VarAdmin> getTypes() { return castings.stream().map(VarAdmin.Casting::getRoleType).flatMap(CommonUtil::optionalToStream); }
@Override public void buildString(StringBuilder builder) { builder.append("(").append(castings.stream().map(Object::toString).collect(joining(", "))).append(")"); }
@Override public Stream<VarPatternAdmin> getTypes() { return relationPlayers().stream().map(RelationPlayer::getRole).flatMap(CommonUtil::optionalToStream); }
private List<String> getDuplicateKeys(ImmutableMultimap<String, String> immutableMultimap) { ImmutableMultiset<String> keys = immutableMultimap.keys(); LOG.debug("keys: {}", keys); Set<String> uniques = Sets.newHashSet(); return keys.stream() .filter(key -> !uniques.add(key)).distinct() .collect(toList()); } }
@Override public void buildString(StringBuilder builder) { builder.append("(").append(relationPlayers().stream().map(Object::toString).collect(joining(", "))).append(")"); }
@Override public Collection<EquivalentFragmentSet> match(String start) { Collection<String> castingNames = new HashSet<>(); ImmutableSet<EquivalentFragmentSet> traversals = castings.stream().flatMap(casting -> { String castingName = UUID.randomUUID().toString(); castingNames.add(castingName); return equivalentFragmentSetFromCasting(start, castingName, casting); }).collect(toImmutableSet()); ImmutableSet<EquivalentFragmentSet> distinctCastingTraversals = castingNames.stream().flatMap( castingName -> castingNames.stream() .filter(otherName -> !otherName.equals(castingName)) .map(otherName -> makeDistinctCastingPattern(castingName, otherName) ) ).collect(toImmutableSet()); return Sets.union(traversals, distinctCastingTraversals); }
private VarPattern addCasting(RelationPlayer relationPlayer) { Optional<RelationshipProperty> relationProperty = getProperty(RelationshipProperty.class); ImmutableMultiset<RelationPlayer> oldCastings = relationProperty .map(RelationshipProperty::relationPlayers) .orElse(ImmutableMultiset.of()); ImmutableMultiset<RelationPlayer> relationPlayers = Stream.concat(oldCastings.stream(), Stream.of(relationPlayer)).collect(CommonUtil.toImmutableMultiset()); RelationshipProperty newProperty = RelationshipProperty.of(relationPlayers); return relationProperty.map(this::removeProperty).orElse(this).addProperty(newProperty); }
private Set<Var> requiredVars(Var var) { Stream<Var> relationPlayers = this.relationPlayers().stream() .flatMap(relationPlayer -> Stream.of(relationPlayer.getRolePlayer(), getRole(relationPlayer))) .map(VarPatternAdmin::var); return Stream.concat(relationPlayers, Stream.of(var)).collect(toImmutableSet()); }
public static RelationshipAtom create(VarPattern pattern, Var predicateVar, @Nullable ConceptId predicateId, ReasonerQuery parent) { List<RelationPlayer> rps = new ArrayList<>(); pattern.admin() .getProperty(RelationshipProperty.class) .ifPresent(prop -> prop.relationPlayers().stream() .sorted(Comparator.comparing(Object::hashCode)) .forEach(rps::add) ); ImmutableList<RelationPlayer> relationPlayers = ImmutableList.copyOf(rps); ImmutableSet<Label> roleLabels = ImmutableSet.<Label>builder().addAll( relationPlayers.stream() .map(RelationPlayer::getRole) .flatMap(CommonUtil::optionalToStream) .map(VarPatternAdmin::getTypeLabel) .flatMap(CommonUtil::optionalToStream) .iterator() ).build(); return new AutoValue_RelationshipAtom(pattern.admin().var(), pattern, parent, predicateVar, predicateId, relationPlayers, roleLabels); }
@Override public Collection<EquivalentFragmentSet> match(Var start) { Collection<Var> castingNames = new HashSet<>(); ImmutableSet<EquivalentFragmentSet> traversals = relationPlayers().stream().flatMap(relationPlayer -> { Var castingName = Graql.var(); castingNames.add(castingName); return equivalentFragmentSetFromCasting(start, castingName, relationPlayer); }).collect(toImmutableSet()); ImmutableSet<EquivalentFragmentSet> distinctCastingTraversals = castingNames.stream().flatMap( castingName -> castingNames.stream() .filter(otherName -> !otherName.equals(castingName)) .map(otherName -> EquivalentFragmentSets.neq(this, castingName, otherName)) ).collect(toImmutableSet()); return Sets.union(traversals, distinctCastingTraversals); }
@Override public void checkValidProperty(MindmapsGraph graph, VarAdmin var) throws IllegalStateException { Set<String> roleTypes = castings.stream() .map(VarAdmin.Casting::getRoleType).flatMap(CommonUtil::optionalToStream) .map(VarAdmin::getIdOnly).flatMap(CommonUtil::optionalToStream)
@Override public Stream<VarAdmin> getInnerVars() { return castings.stream().flatMap(casting -> { Stream.Builder<VarAdmin> builder = Stream.builder(); builder.add(casting.getRolePlayer()); casting.getRoleType().ifPresent(builder::add); return builder.build(); }); }
@Override public void checkValidProperty(GraknTx graph, VarPatternAdmin var) throws GraqlQueryException { Set<Label> roleTypes = relationPlayers().stream() .map(RelationPlayer::getRole).flatMap(CommonUtil::optionalToStream) .map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream) .collect(toSet()); Optional<Label> maybeLabel = var.getProperty(IsaProperty.class).map(IsaProperty::type).flatMap(VarPatternAdmin::getTypeLabel); maybeLabel.ifPresent(label -> { SchemaConcept schemaConcept = graph.getSchemaConcept(label); if (schemaConcept == null || !schemaConcept.isRelationshipType()) { throw GraqlQueryException.notARelationType(label); } }); // Check all role types exist roleTypes.forEach(roleId -> { SchemaConcept schemaConcept = graph.getSchemaConcept(roleId); if (schemaConcept == null || !schemaConcept.isRole()) { throw GraqlQueryException.notARoleType(roleId); } }); }
@Override public Stream<VarPatternAdmin> innerVarPatterns() { return relationPlayers().stream().flatMap(relationPlayer -> { Stream.Builder<VarPatternAdmin> builder = Stream.builder(); builder.add(relationPlayer.getRolePlayer()); relationPlayer.getRole().ifPresent(builder::add); return builder.build(); }); }
HttpServiceAttemptImpl(Set<URI> attempted) Multiset<URI> httpUris = HttpServiceBalancerImpl.this.httpUris.get().stream() .filter(uri -> !attemptedCopy.contains(uri)) .collect(Collectors.toCollection(HashMultiset::create));