@Override public final String toString() { // TODO: Consider using @AutoValue toString return getValue(); } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Label) { Label that = (Label) o; return (this.value.equals(that.getValue())); } return false; }
/** * Rename a {@link Label} (does not modify the original {@link Label}) * @param mapper a function to apply to the underlying type label * @return the new type label */ @CheckReturnValue public Label map(Function<String, String> mapper) { return Label.of(mapper.apply(getValue())); }
private Stream<AttributeType> attributes(Schema.ImplicitType implicitType){ //TODO: Make this less convoluted String [] implicitIdentifiers = implicitType.getLabel("").getValue().split("--"); String prefix = implicitIdentifiers[0] + "-"; String suffix = "-" + implicitIdentifiers[1]; //A traversal is not used in this so that caching can be taken advantage of. return playing().map(role -> role.label().getValue()). filter(roleLabel -> roleLabel.startsWith(prefix) && roleLabel.endsWith(suffix)). map(roleLabel -> { String attributeTypeLabel = roleLabel.replace(prefix, "").replace(suffix, ""); return vertex().tx().getAttributeType(attributeTypeLabel); }); }
@Override public boolean containsKeyspace(Keyspace keyspace){ //Check the local cache to see which keyspaces we already have open if(existingKeyspaces.contains(keyspace)){ return true; } try (GraknTx tx = systemKeyspaceSession.transaction(GraknTxType.READ)) { boolean keyspaceExists = (tx.getAttributeType(KEYSPACE_RESOURCE.getValue()).attribute(keyspace) != null); if(keyspaceExists) existingKeyspaces.add(keyspace); return keyspaceExists; } }
/** * Thrown when trying to create something using a label reserved by the system */ public static GraknTxOperationException reservedLabel(Label label){ return create(RESERVED_WORD.getMessage(label.getValue())); }
private String summaryFormat(Object object) { if (object instanceof SchemaConcept) { return ((SchemaConcept) object).label().getValue().replaceAll("-", "_"); } else if (object instanceof Thing) { Thing thing = (Thing) object; return summaryFormat(thing.type()) + thing.id().getValue(); } else if (object instanceof Label) { return valueToString(((Label) object).getValue()); } else { return object.toString(); } }
@Override public void checkValid(){ super.checkValid(); getRoleLabels().stream() .filter(label -> tx().getRole(label.getValue()) == null) .findFirst() .ifPresent(label -> { throw GraqlQueryException.labelNotFound(label); }); }
public Stream<IdPredicate> getRolePredicates(){ return getRelationPlayers().stream() .map(RelationPlayer::getRole) .flatMap(CommonUtil::optionalToStream) .filter(var -> var.var().isUserDefinedName()) .filter(vp -> vp.getTypeLabel().isPresent()) .map(vp -> { Label label = vp.getTypeLabel().orElse(null); return IdPredicate.create(vp.var(), tx().getRole(label.getValue()), getParentQuery()); }); }
@Override public String toString(){ String typeString = getSchemaConcept() != null? getSchemaConcept().label().getValue() : "{" + inferPossibleTypes(new ConceptMapImpl()).stream().map(rt -> rt.label().getValue()).collect(Collectors.joining(", ")) + "}"; String relationString = (isUserDefined()? getVarName() + " ": "") + typeString + (getPredicateVariable().isUserDefinedName()? "(" + getPredicateVariable() + ")" : "") + (isDirect()? "!" : "") + getRelationPlayers().toString(); return relationString + getPredicates(Predicate.class).map(Predicate::toString).collect(Collectors.joining("")); }
/** * Adds a new type vertex which occupies a grakn id. This result in the grakn id count on the meta concept to be * incremented. * * @param label The label of the new type vertex * @param baseType The base type of the new type * @return The new type vertex */ private VertexElement addTypeVertex(LabelId id, Label label, Schema.BaseType baseType) { VertexElement vertexElement = addVertexElement(baseType); vertexElement.property(Schema.VertexProperty.SCHEMA_LABEL, label.getValue()); vertexElement.property(Schema.VertexProperty.LABEL_ID, id.getValue()); return vertexElement; }
public static SessionProto.Transaction.Req putRule(Label label, Pattern when, Pattern then) { SessionProto.Transaction.PutRule.Req request = SessionProto.Transaction.PutRule.Req.newBuilder() .setLabel(label.getValue()) .setWhen(when.toString()) .setThen(then.toString()) .build(); return SessionProto.Transaction.Req.newBuilder().setPutRuleReq(request).build(); }
public static SessionProto.Transaction.Req getSchemaConcept(Label label) { return SessionProto.Transaction.Req.newBuilder() .setGetSchemaConceptReq(SessionProto.Transaction.GetSchemaConcept.Req.newBuilder().setLabel(label.getValue())) .build(); }
public static SessionProto.Transaction.Req putRole(Label label) { SessionProto.Transaction.PutRole.Req request = SessionProto.Transaction.PutRole.Req.newBuilder() .setLabel(label.getValue()) .build(); return SessionProto.Transaction.Req.newBuilder().setPutRoleReq(request).build(); }
@Override protected Pattern createCombinedPattern(){ if (getPredicateVariable().isUserDefinedName()) return super.createCombinedPattern(); return getSchemaConcept() == null? relationPattern() : isDirect()? relationPattern().isaExplicit(getSchemaConcept().label().getValue()): relationPattern().isa(getSchemaConcept().label().getValue()); }
@Override public final SomeSchemaConcept label(Label label) { ConceptProto.Method.Req method = ConceptProto.Method.Req.newBuilder() .setSchemaConceptSetLabelReq(ConceptProto.SchemaConcept.SetLabel.Req.newBuilder() .setLabel(label.getValue())).build(); runMethod(method); return asCurrentBaseType(this); }
public static SessionProto.Transaction.Req putAttributeType(Label label, AttributeType.DataType<?> dataType) { SessionProto.Transaction.PutAttributeType.Req request = SessionProto.Transaction.PutAttributeType.Req.newBuilder() .setLabel(label.getValue()) .setDataType(Concept.dataType(dataType)) .build(); return SessionProto.Transaction.Req.newBuilder().setPutAttributeTypeReq(request).build(); }
@Override protected Pattern createCombinedPattern(){ if (getPredicateVariable().isUserDefinedName()) return super.createCombinedPattern(); return getSchemaConcept() == null? getVarName().isa(getPredicateVariable()) : isDirect()? getVarName().isaExplicit(getSchemaConcept().label().getValue()) : getVarName().isa(getSchemaConcept().label().getValue()) ; }
public T label(Label label){ try { vertex().tx().txCache().remove(this); vertex().propertyUnique(Schema.VertexProperty.SCHEMA_LABEL, label.getValue()); cachedLabel.set(label); vertex().tx().txCache().cacheConcept(this); return getThis(); } catch (PropertyNotUniqueException exception){ vertex().tx().txCache().cacheConcept(this); throw GraknTxOperationException.labelTaken(label); } }