本文整理汇总了Java中com.thinkaurelius.titan.core.attribute.Cmp类的典型用法代码示例。如果您正苦于以下问题:Java Cmp类的具体用法?Java Cmp怎么用?Java Cmp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cmp类属于com.thinkaurelius.titan.core.attribute包,在下文中一共展示了Cmp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInstant
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
private void testInstant(Instant firstTimestamp, Instant secondTimestamp, TitanVertex v1, TitanVertex v2) {
assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp)));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices()));
assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp)));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices()));
assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp)));
clopen();//Flush the index
assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp)));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices()));
assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp)));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices()));
assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp)));
}
示例2: convertInternal
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
/**
* Convert Tinkerpop's comparison operators to Titan's
*
* @param p Any predicate
* @return A TitanPredicate equivalent to the given predicate
* @throws IllegalArgumentException if the given Predicate is unknown
*/
public static final TitanPredicate convertInternal(BiPredicate p) {
if (p instanceof TitanPredicate) {
return (TitanPredicate)p;
} else if (p instanceof Compare) {
Compare comp = (Compare)p;
switch(comp) {
case eq: return Cmp.EQUAL;
case neq: return Cmp.NOT_EQUAL;
case gt: return Cmp.GREATER_THAN;
case gte: return Cmp.GREATER_THAN_EQUAL;
case lt: return Cmp.LESS_THAN;
case lte: return Cmp.LESS_THAN_EQUAL;
default: throw new IllegalArgumentException("Unexpected comparator: " + comp);
}
} else if (p instanceof Contains) {
Contains con = (Contains)p;
switch (con) {
case within: return Contain.IN;
case without: return Contain.NOT_IN;
default: throw new IllegalArgumentException("Unexpected container: " + con);
}
} else return null;
}
示例3: addConstraint
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
private Q addConstraint(String type, TitanPredicate rel, Object value) {
Preconditions.checkArgument(type != null && StringUtils.isNotBlank(type) && rel != null);
//Treat special cases
if (type.equals(ImplicitKey.ADJACENT_ID.name())) {
Preconditions.checkArgument(rel == Cmp.EQUAL, "Only equality constraints are supported for %s", type);
long vertexId = ElementUtils.getVertexId(value);
Preconditions.checkArgument(vertexId > 0, "Expected valid vertex id: %s", value);
return adjacent(getVertex(vertexId));
} else if (type.equals(ImplicitKey.ID.name())) {
RelationIdentifier rid = ElementUtils.getEdgeId(value);
Preconditions.checkArgument(rid != null, "Expected valid relation id: %s", value);
return addConstraint(ImplicitKey.TITANID.name(), rel, rid.getRelationId());
} else {
Preconditions.checkArgument(rel.isValidCondition(value), "Invalid condition provided: " + value);
}
if (constraints == NO_CONSTRAINTS) constraints = new ArrayList<PredicateCondition<String, TitanRelation>>(5);
constraints.add(new PredicateCondition<String, TitanRelation>(type, rel, value));
return getThis();
}
示例4: getEqualityConditionValues
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
private static final Map.Entry<Condition,Collection<Object>> getEqualityConditionValues(Condition<TitanElement> condition, RelationType type) {
for (Condition c : condition.getChildren()) {
if (c instanceof Or) {
Map.Entry<RelationType,Collection> orEqual = QueryUtil.extractOrCondition((Or)c);
if (orEqual!=null && orEqual.getKey().equals(type) && !orEqual.getValue().isEmpty()) {
return new AbstractMap.SimpleImmutableEntry(c,orEqual.getValue());
}
} else if (c instanceof PredicateCondition) {
PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition)c;
if (atom.getKey().equals(type) && atom.getPredicate()==Cmp.EQUAL && atom.getValue()!=null) {
return new AbstractMap.SimpleImmutableEntry(c,ImmutableList.of(atom.getValue()));
}
}
}
return null;
}
示例5: getQuery
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
public static GraphCentricQueryBuilder getQuery(CompositeIndexType index, Object[] values, StandardTitanTx tx) {
Preconditions.checkArgument(index != null && values != null && values.length > 0 && tx != null);
Preconditions.checkArgument(values.length==index.getFieldKeys().length);
GraphCentricQueryBuilder gb = tx.query();
IndexField[] fields = index.getFieldKeys();
for (int i = 0; i <fields.length; i++) {
IndexField f = fields[i];
Object value = values[i];
Preconditions.checkNotNull(value);
PropertyKey key = f.getFieldKey();
Preconditions.checkArgument(key.dataType().equals(value.getClass()),"Incompatible data types for: " + value);
gb.has(key, Cmp.EQUAL,value);
}
if (index.hasSchemaTypeConstraint()) {
gb.has(ImplicitKey.LABEL,Cmp.EQUAL,index.getSchemaTypeConstraint().name());
}
return gb;
}
示例6: getEqualityConditionValues
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
private static final Map.Entry<Condition, Collection<Object>> getEqualityConditionValues(Condition<TitanElement> condition, RelationType type) {
for (Condition c : condition.getChildren()) {
if (c instanceof Or) {
Map.Entry<RelationType, Collection> orEqual = QueryUtil.extractOrCondition((Or)c);
if (orEqual!=null && orEqual.getKey().equals(type) && !orEqual.getValue().isEmpty()) {
return new AbstractMap.SimpleImmutableEntry(c, orEqual.getValue());
}
} else if (c instanceof PredicateCondition) {
PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition)c;
if (atom.getKey().equals(type) && atom.getPredicate()==Cmp.EQUAL && atom.getValue()!=null) {
return new AbstractMap.SimpleImmutableEntry(c, ImmutableList.of(atom.getValue()));
}
}
}
return null;
}
示例7: getQuery
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
public static GraphCentricQueryBuilder getQuery(CompositeIndexType index, Object[] values, StandardTitanTx tx) {
Preconditions.checkArgument(index != null && values != null && values.length > 0 && tx != null);
Preconditions.checkArgument(values.length==index.getFieldKeys().length);
GraphCentricQueryBuilder gb = tx.query();
IndexField[] fields = index.getFieldKeys();
for (int i = 0; i <fields.length; i++) {
IndexField f = fields[i];
Object value = values[i];
Preconditions.checkNotNull(value);
PropertyKey key = f.getFieldKey();
Preconditions.checkArgument(key.getDataType().equals(value.getClass()),"Incompatible data types for: " + value);
gb.has(key, Cmp.EQUAL,value);
}
if (index.hasSchemaTypeConstraint()) {
gb.has(ImplicitKey.LABEL,Cmp.EQUAL,index.getSchemaTypeConstraint().getName());
}
return gb;
}
示例8: getVertices
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
/**
* Gets the specified vertices or null if no such vertex is found
*
* @param property name
* @param label vertex type label
* @param value value in property field
* @param limit int value limiting the result. use Integer.MAX_VALUE for unlimited
* @return the specified vertices or null if no such vertex is found
*/
public Set<Vertex> getVertices(String label, String property, Object value, int limit) throws SchemaViolationException {
Integer suffix = s.getVertexTypes().get(label);
Set<Vertex> res = new HashSet<>();
if (suffix == null)
throw new SchemaViolationException(label + " vertex type is not defined in the schema for " + s.getClass().getSimpleName());
Iterable<Vertex> qres;
GraphQuery q = g.query().has("label", label).has(property, Cmp.EQUAL, value);
if (limit == Integer.MAX_VALUE)
qres = q.vertices();
else
qres = q.limit(limit).vertices();
for (Vertex v : qres)
res.add(v);
return res;
}
示例9: getQueryString
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
private final String getQueryString(String family, String key, Cmp relation, Number value) {
String columnName = getColumnName(family, key);
switch (relation) {
case EQUAL:
return columnName + ":" + value;
case NOT_EQUAL:
return "-(" + columnName + ":" + value + ")";
case LESS_THAN:
return columnName + ":[MIN TO " + value + "}";
case LESS_THAN_EQUAL:
return columnName + ":[MIN TO " + value + "]";
case GREATER_THAN:
return columnName + ":{" + value + " TO MAX]";
case GREATER_THAN_EQUAL:
return columnName + ":[" + value + " TO MAX]";
default:
throw new IllegalArgumentException("Unexpected relation: " + relation);
}
}
示例10: testVertexCentricIndexWithNull
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
@Test
public void testVertexCentricIndexWithNull() {
EdgeLabel bought = makeLabel("bought");
PropertyKey time = makeKey("time", Long.class);
mgmt.buildEdgeIndex(bought, "byTimeDesc", BOTH, decr, time);
mgmt.buildEdgeIndex(bought, "byTimeIncr", BOTH, incr, time);
finishSchema();
TitanVertex v1 = tx.addVertex(), v2 = tx.addVertex();
v1.addEdge("bought", v2).property("time", 1);
v1.addEdge("bought", v2).property("time", 2);
v1.addEdge("bought", v2).property("time", 3);
v1.addEdge("bought", v2);
v1.addEdge("bought", v2);
assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
newTx();
v1 = tx.getVertex(v1.longId());
//Queries copied from above
assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
}
示例11: testBooleanIndexing
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
/**
* Tests indexing boolean
*/
@Test
public void testBooleanIndexing() {
PropertyKey name = makeKey("visible", Boolean.class);
mgmt.buildIndex("booleanIndex", Vertex.class).
addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
TitanVertex v1 = graph.addVertex();
v1.property("visible", true);
TitanVertex v2 = graph.addVertex();
v2.property("visible", false);
assertCount(2, graph.vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
clopen();//Flush the index
assertCount(2, graph.vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
}
示例12: testDateIndexing
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
/**
* Tests indexing dates
*/
@Test
public void testDateIndexing() {
PropertyKey name = makeKey("date", Date.class);
mgmt.buildIndex("dateIndex", Vertex.class).
addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
TitanVertex v1 = graph.addVertex();
v1.property("date", new Date(1));
TitanVertex v2 = graph.addVertex();
v2.property("date", new Date(2000));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));
clopen();//Flush the index
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));
}
示例13: testUUIDIndexing
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
/**
* Tests indexing boolean
*/
@Test
public void testUUIDIndexing() {
PropertyKey name = makeKey("uid", UUID.class);
mgmt.buildIndex("uuidIndex", Vertex.class).
addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
UUID uid1 = UUID.randomUUID();
UUID uid2 = UUID.randomUUID();
TitanVertex v1 = graph.addVertex();
v1.property("uid", uid1);
TitanVertex v2 = graph.addVertex();
v2.property("uid", uid2);
assertCount(2, graph.query().vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1)));
assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2)));
assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1)));
assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2)));
clopen();//Flush the index
assertCount(2, graph.query().vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1)));
assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2)));
assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1)));
assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2)));
}
示例14: checkPropertyLockingAndIndex
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
@Test
public void checkPropertyLockingAndIndex() {
PropertyKey uid = makeKey("uid",String.class);
TitanGraphIndex index = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex();
mgmt.setConsistency(index, ConsistencyModifier.LOCK);
mgmt.makePropertyKey("name").dataType(String.class).make();
mgmt.makePropertyKey("age").dataType(Integer.class).make();
finishSchema();
metricsPrefix = "checkPropertyLockingAndIndex";
TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start();
TitanVertex v = tx.addVertex("uid", "v1", "age", 25, "name", "john");
assertEquals(25,v.property("age").value());
tx.commit();
verifyStoreMetrics(EDGESTORE_NAME);
verifyLockingOverwrite(INDEXSTORE_NAME, 1);
verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l));
resetMetrics();
tx = graph.buildTransaction().groupName(metricsPrefix).start();
v = Iterables.getOnlyElement(tx.query().has("uid", Cmp.EQUAL, "v1").vertices());
assertEquals(25,v.property("age").value());
tx.commit();
verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
verifyStoreMetrics(METRICS_STOREMANAGER_NAME);
}
示例15: supports
import com.thinkaurelius.titan.core.attribute.Cmp; //导入依赖的package包/类
@Override
public boolean supports(KeyInformation information, TitanPredicate titanPredicate) {
Class<?> dataType = information.getDataType();
Mapping mapping = getMapping(information);
if (mapping!= DEFAULT && !AttributeUtil.isString(dataType)) return false;
if (Number.class.isAssignableFrom(dataType)) {
return titanPredicate instanceof Cmp;
} else if (dataType == Geoshape.class) {
return titanPredicate == Geo.WITHIN;
} else if (AttributeUtil.isString(dataType)) {
switch(mapping) {
case DEFAULT:
case TEXT:
return titanPredicate == Text.CONTAINS || titanPredicate == Text.CONTAINS_PREFIX || titanPredicate == Text.CONTAINS_REGEX;
case STRING:
return titanPredicate == EQUAL || titanPredicate== NOT_EQUAL || titanPredicate==Text.REGEX || titanPredicate==Text.PREFIX;
// case TEXTSTRING:
// return (titanPredicate instanceof Text) || titanPredicate == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL;
}
} else if (dataType == Date.class) {
if (titanPredicate instanceof Cmp) return true;
} else if (dataType == Boolean.class) {
return titanPredicate == EQUAL || titanPredicate == NOT_EQUAL;
} else if (dataType == UUID.class) {
return titanPredicate == EQUAL || titanPredicate== NOT_EQUAL;
}
return false;
}