private static TxType convert(GraknTxType txType) { switch (txType) { case READ: return TxType.Read; case WRITE: return TxType.Write; case BATCH: return TxType.Batch; default: throw CommonUtil.unreachableStatement("Unrecognised " + txType); } }
@SuppressWarnings("unchecked") @Override public MapReduce<Serializable, T, Serializable, T, Map<Serializable, T>> clone() { try { return (GraknMapReduce) super.clone(); } catch (final CloneNotSupportedException e) { throw CommonUtil.unreachableStatement(e); } }
@SuppressWarnings("unchecked") @Override public GraknVertexProgram<T> clone() { try { return (GraknVertexProgram) super.clone(); } catch (final CloneNotSupportedException e) { throw CommonUtil.unreachableStatement(e); } }
@CheckReturnValue public static RuntimeException unreachableStatement(String message) { return unreachableStatement(message, null); }
@CheckReturnValue public static RuntimeException unreachableStatement(Throwable cause) { return unreachableStatement(null, cause); }
private static URL mapQuadZeroRouteToLocalhost(URL originalUrl) { final String QUAD_ZERO_ROUTE = "http://0.0.0.0"; URL mappedUrl; if ((originalUrl.getProtocol() + originalUrl.getHost()).equals(QUAD_ZERO_ROUTE)) { try { mappedUrl = new URL(originalUrl.getProtocol(), "localhost", originalUrl.getPort(), REST.WebPath.KB); } catch (MalformedURLException e) { throw CommonUtil.unreachableStatement( "This will never throw because the protocol is valid (because it came from another URL)", e ); } } else { mappedUrl = originalUrl; } return mappedUrl; }
@Nullable public static Optional<Pattern> convert(OptionalPattern pattern) { switch (pattern.getValueCase()) { case PRESENT: return Optional.of(convert(pattern.getPresent())); case ABSENT: return Optional.empty(); case VALUE_NOT_SET: default: throw CommonUtil.unreachableStatement("Unrecognised " + pattern); } }
@Override protected final T computeNext() { SessionProto.Transaction.Iter.Res response = tx.iterate(iteratorId); switch (response.getResCase()) { case DONE: return endOfData(); case RES_NOT_SET: throw CommonUtil.unreachableStatement("Unexpected " + response); default: return responseReader.apply(response); } } }
@Override public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { switch (memory.getIteration()) { case 0: degreeMessagePassing(messenger); break; case 1: degreeMessageCounting(messenger, vertex); break; default: throw CommonUtil.unreachableStatement("Exceeded expected maximum number of iterations"); } }
@Override protected final T computeNext() { GrpcGrakn.TxResponse response = grpcClient.next(iteratorId); switch (response.getResponseCase()) { case DONE: return endOfData(); case RESPONSE_NOT_SET: throw CommonUtil.unreachableStatement("Unexpected " + response); default: return getNextFromResponse(response); } }
@Override public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { switch (memory.getIteration()) { case 0: messenger.sendMessage(messageScopeOut, 1L); break; case 1: if (messenger.receiveMessages().hasNext()) { vertex.property(EDGE_COUNT, getMessageCount(messenger)); } break; default: throw CommonUtil.unreachableStatement("Exceeded expected maximum number of iterations"); } }
@Override public AttributeType.DataType<?> visitDatatype(GraqlParser.DatatypeContext datatype) { if (datatype.BOOLEAN_TYPE() != null) { return AttributeType.DataType.BOOLEAN; } else if (datatype.DATE_TYPE() != null) { return AttributeType.DataType.DATE; } else if (datatype.DOUBLE_TYPE() != null) { return AttributeType.DataType.DOUBLE; } else if (datatype.LONG_TYPE() != null) { return AttributeType.DataType.LONG; } else if (datatype.STRING_TYPE() != null) { return AttributeType.DataType.STRING; } else { throw CommonUtil.unreachableStatement("Unrecognised " + datatype); } }
@Nullable @Override public final AttributeType.DataType<D> dataType() { ConceptProto.Method.Req method = ConceptProto.Method.Req.newBuilder() .setAttributeTypeDataTypeReq(ConceptProto.AttributeType.DataType.Req.getDefaultInstance()).build(); ConceptProto.AttributeType.DataType.Res response = runMethod(method).getAttributeTypeDataTypeRes(); switch (response.getResCase()) { case NULL: return null; case DATATYPE: return (AttributeType.DataType<D>) RequestBuilder.Concept.dataType(response.getDataType()); default: throw CommonUtil.unreachableStatement("Unexpected response " + response); } }
@Nullable @Override public final Pattern when() { ConceptProto.Method.Req method = ConceptProto.Method.Req.newBuilder() .setRuleWhenReq(ConceptProto.Rule.When.Req.getDefaultInstance()).build(); ConceptProto.Rule.When.Res response = runMethod(method).getRuleWhenRes(); switch (response.getResCase()) { case NULL: return null; case PATTERN: return Graql.parser().parsePattern(response.getPattern()); default: throw CommonUtil.unreachableStatement("Unexpected response " + response); } }
@Nullable @Override public final Pattern then() { ConceptProto.Method.Req method = ConceptProto.Method.Req.newBuilder() .setRuleThenReq(ConceptProto.Rule.Then.Req.getDefaultInstance()).build(); ConceptProto.Rule.Then.Res response = runMethod(method).getRuleThenRes(); switch (response.getResCase()) { case NULL: return null; case PATTERN: return Graql.parser().parsePattern(response.getPattern()); default: throw CommonUtil.unreachableStatement("Unexpected response " + response); } }
@Nullable @Override public final SomeSchemaConcept sup() { ConceptProto.Method.Req method = ConceptProto.Method.Req.newBuilder() .setSchemaConceptGetSupReq(ConceptProto.SchemaConcept.GetSup.Req.getDefaultInstance()).build(); ConceptProto.SchemaConcept.GetSup.Res response = runMethod(method).getSchemaConceptGetSupRes(); switch (response.getResCase()) { case NULL: return null; case SCHEMACONCEPT: Concept concept = RemoteConcept.of(response.getSchemaConcept(), tx()); return equalsCurrentBaseType(concept) ? asCurrentBaseType(concept) : null; default: throw CommonUtil.unreachableStatement("Unexpected response " + response); } }
@Nullable @Override public final Attribute<D> attribute(D value) { ConceptProto.Method.Req method = ConceptProto.Method.Req.newBuilder() .setAttributeTypeAttributeReq(ConceptProto.AttributeType.Attribute.Req.newBuilder() .setValue(RequestBuilder.Concept.attributeValue(value))).build(); ConceptProto.AttributeType.Attribute.Res response = runMethod(method).getAttributeTypeAttributeRes(); switch (response.getResCase()) { case NULL: return null; case ATTRIBUTE: return RemoteConcept.of(response.getAttribute(), tx()).asAttribute(); default: throw CommonUtil.unreachableStatement("Unexpected response " + response); } }
/** * Map an Thing to the equivalent Graql representation * @param thing thing to be mapped * @return Graql representation of given thing */ public static VarPattern map(Thing thing){ if(thing.isEntity()){ return map(thing.asEntity()); } else if(thing.isAttribute()){ return map(thing.asAttribute()); } else if(thing.isRelationship()){ return map(thing.asRelationship()); } else { throw CommonUtil.unreachableStatement("Unrecognised thing " + thing); } }
private Thing putInstance() { Type type = use(TYPE); if (type.isEntityType()) { return type.asEntityType().create(); } else if (type.isRelationshipType()) { return type.asRelationshipType().create(); } else if (type.isAttributeType()) { return type.asAttributeType().create(use(VALUE)); } else if (type.label().equals(Schema.MetaSchema.THING.getLabel())) { throw GraqlQueryException.createInstanceOfMetaConcept(var, type); } else { throw CommonUtil.unreachableStatement("Can't recognize type " + type); } }
static Pattern toPattern(Concept concept) { if (!concept.isThing()){ throw GraqlQueryException.conceptNotAThing(concept); } if (concept.isEntity()) { return new EntityConverter().pattern(concept.asEntity()); } else if (concept.isRelationship()) { return new RelationshipConverter().pattern(concept.asRelationship()); } else if (concept.isAttribute()) { return new AttributeConverter().pattern(concept.asAttribute()); } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } }