本文整理汇总了Java中com.thinkaurelius.titan.core.Cardinality类的典型用法代码示例。如果您正苦于以下问题:Java Cardinality类的具体用法?Java Cardinality怎么用?Java Cardinality使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cardinality类属于com.thinkaurelius.titan.core包,在下文中一共展示了Cardinality类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMapping
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
public static final Map<String,KeyInformation> getMapping(final IndexFeatures indexFeatures) {
Preconditions.checkArgument(indexFeatures.supportsStringMapping(Mapping.TEXTSTRING) ||
(indexFeatures.supportsStringMapping(Mapping.TEXT) && indexFeatures.supportsStringMapping(Mapping.STRING)),
"Index must support string and text mapping");
return new HashMap<String,KeyInformation>() {{
put(TEXT,new StandardKeyInformation(String.class, Cardinality.SINGLE, new Parameter("mapping",
indexFeatures.supportsStringMapping(Mapping.TEXT)?Mapping.TEXT:Mapping.TEXTSTRING)));
put(TIME,new StandardKeyInformation(Long.class, Cardinality.SINGLE));
put(WEIGHT,new StandardKeyInformation(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT)));
put(LOCATION,new StandardKeyInformation(Geoshape.class, Cardinality.SINGLE));
put(NAME,new StandardKeyInformation(String.class, Cardinality.SINGLE, new Parameter("mapping",
indexFeatures.supportsStringMapping(Mapping.STRING)?Mapping.STRING:Mapping.TEXTSTRING)));
if(indexFeatures.supportsCardinality(Cardinality.LIST)) {
put(PHONE_LIST, new StandardKeyInformation(String.class, Cardinality.LIST, new Parameter("mapping",
indexFeatures.supportsStringMapping(Mapping.STRING) ? Mapping.STRING : Mapping.TEXTSTRING)));
}
if(indexFeatures.supportsCardinality(Cardinality.SET)) {
put(PHONE_SET, new StandardKeyInformation(String.class, Cardinality.SET, new Parameter("mapping",
indexFeatures.supportsStringMapping(Mapping.STRING) ? Mapping.STRING : Mapping.TEXTSTRING)));
}
put(DATE,new StandardKeyInformation(Instant.class, Cardinality.SINGLE));
}};
}
示例2: testTinkerPopCardinality
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Test
public void testTinkerPopCardinality() {
PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make();
PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.SINGLE).dataType(String.class).make();
PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make();
mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex();
finishSchema();
GraphTraversalSource gts;
Vertex v;
v = graph.addVertex("id", 1);
v.property(single, "name", "t1");
graph.addVertex("id", 2, "names", "n1", "names", "n2");
graph.tx().commit();
gts = graph.traversal();
v = gts.V().has("id", 1).next();
v.property(single, "name", "t2");
v = gts.V().has("id", 1).next();
v.property(single, "name", "t3");
assertCount(1, gts.V(v).properties("name"));
assertCount(2, gts.V().has("id", 2).properties("names"));
assertCount(2, gts.V().hasLabel("vertex"));
}
示例3: testMultiplicityCardinality
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Test
public void testMultiplicityCardinality() {
assertEquals(Multiplicity.MULTI,Multiplicity.convert(Cardinality.LIST));
assertEquals(Multiplicity.SIMPLE,Multiplicity.convert(Cardinality.SET));
assertEquals(Multiplicity.MANY2ONE,Multiplicity.convert(Cardinality.SINGLE));
assertEquals(Multiplicity.MULTI.getCardinality(),Cardinality.LIST);
assertEquals(Multiplicity.SIMPLE.getCardinality(),Cardinality.SET);
assertEquals(Multiplicity.MANY2ONE.getCardinality(),Cardinality.SINGLE);
assertFalse(Multiplicity.MULTI.isConstrained());
assertTrue(Multiplicity.SIMPLE.isConstrained());
assertTrue(Multiplicity.ONE2ONE.isConstrained());
assertTrue(Multiplicity.ONE2ONE.isConstrained(Direction.BOTH));
assertTrue(Multiplicity.SIMPLE.isConstrained(Direction.BOTH));
assertFalse(Multiplicity.MULTI.isUnique(Direction.OUT));
assertTrue(Multiplicity.MANY2ONE.isUnique(Direction.OUT));
}
示例4: testSupport
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Test
public void testSupport() {
assertTrue(index.supports(of(String.class, Cardinality.SINGLE), Text.CONTAINS));
assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_PREFIX));
assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_REGEX));
assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.REGEX));
assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Text.CONTAINS));
assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.PREFIX));
assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.REGEX));
assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.EQUAL));
assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.NOT_EQUAL));
assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.EQUAL));
assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN_EQUAL));
assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN));
assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN));
assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));
assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.EQUAL));
assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));
assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.EQUAL));
assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));
}
示例5: supports
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Override
public boolean supports(KeyInformation information, TitanPredicate titanPredicate) {
if (information.getCardinality()!= Cardinality.SINGLE) return false;
Class<?> dataType = information.getDataType();
Mapping mapping = Mapping.getMapping(information);
if (mapping!=Mapping.DEFAULT && !AttributeUtil.isString(dataType)) return false;
if (Number.class.isAssignableFrom(dataType)) {
if (titanPredicate instanceof Cmp) return true;
} 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 == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL || titanPredicate==Text.PREFIX || titanPredicate==Text.REGEX;
}
}
return false;
}
示例6: Titan1Graph
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
public Titan1Graph() {
//determine multi-properties once at startup
TitanManagement mgmt = null;
try {
mgmt = Titan1GraphDatabase.getGraphInstance().openManagement();
Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
multiProperties = new HashSet<>();
for (PropertyKey key : keys) {
if (key.cardinality() != Cardinality.SINGLE) {
multiProperties.add(key.name());
}
}
} finally {
if (mgmt != null) {
mgmt.rollback();
}
}
}
示例7: Titan0Graph
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
public Titan0Graph() {
//determine multi-properties once at startup
TitanManagement mgmt = null;
try {
mgmt = Titan0GraphDatabase.getGraphInstance().getManagementSystem();
Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
multiProperties = Collections.synchronizedSet(new HashSet<String>());
for(PropertyKey key : keys) {
if (key.getCardinality() != Cardinality.SINGLE) {
multiProperties.add(key.getName());
}
}
} finally {
if (mgmt != null) {
mgmt.rollback();
}
}
}
示例8: makePropertyKey
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Override
public AtlasPropertyKey makePropertyKey(String propertyName, Class propertyClass, AtlasCardinality cardinality) {
if (cardinality.isMany()) {
newMultProperties.add(propertyName);
}
PropertyKeyMaker propertyKeyBuilder = management.makePropertyKey(propertyName).dataType(propertyClass);
if (cardinality != null) {
Cardinality titanCardinality = TitanObjectFactory.createCardinality(cardinality);
propertyKeyBuilder.cardinality(titanCardinality);
}
PropertyKey propertyKey = propertyKeyBuilder.make();
return GraphDbObjectFactory.createPropertyKey(propertyKey);
}
示例9: getProperty
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Override
public <O> O getProperty(PropertyKey key) {
if (!((InternalRelationType)key).isHiddenType() && tx().getConfiguration().hasPropertyPrefetching()) {
getProperties().iterator().hasNext();
}
Iterator<TitanProperty> iter = query().type(key).properties().iterator();
if (key.getCardinality()== Cardinality.SINGLE) {
if (iter.hasNext()) return (O)iter.next().getValue();
else return null;
} else {
List<Object> result = new ArrayList<Object>();
while (iter.hasNext()) {
result.add(iter.next().getValue());
}
return (O)result;
}
}
示例10: createMixedIndex
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
private TitanGraphIndex createMixedIndex(String indexName, ElementCategory elementCategory,
TitanSchemaType constraint, String backingIndex) {
Preconditions.checkArgument(graph.getIndexSerializer().containsIndex(backingIndex), "Unknown external index backend: %s", backingIndex);
checkIndexName(indexName);
TypeDefinitionMap def = new TypeDefinitionMap();
def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, false);
def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
def.setValue(TypeDefinitionCategory.BACKING_INDEX, backingIndex);
def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, Cardinality.LIST);
def.setValue(TypeDefinitionCategory.STATUS, SchemaStatus.ENABLED);
TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX, indexName, def);
Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
if (constraint != null) {
addSchemaEdge(indexVertex, (TitanSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
}
updateSchemaVertex(indexVertex);
return new TitanGraphIndexWrapper(indexVertex.asIndexType());
}
示例11: supports
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Override
public boolean supports(KeyInformation information, TitanPredicate titanPredicate) {
if (information.getCardinality()!= Cardinality.SINGLE) return false;
Class<?> dataType = information.getDataType();
Mapping mapping = Mapping.getMapping(information);
if (mapping!=Mapping.DEFAULT && !AttributeUtil.isString(dataType)) return false;
if (Number.class.isAssignableFrom(dataType)) {
if (titanPredicate instanceof Cmp) return true;
} 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 == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL || titanPredicate==Text.PREFIX || titanPredicate==Text.REGEX;
}
} else if (dataType == Date.class || dataType == Instant.class) {
if (titanPredicate instanceof Cmp) return true;
} else if (dataType == Boolean.class) {
return titanPredicate == Cmp.EQUAL || titanPredicate == Cmp.NOT_EQUAL;
} else if (dataType == UUID.class) {
return titanPredicate == Cmp.EQUAL || titanPredicate == Cmp.NOT_EQUAL;
}
return false;
}
示例12: supports
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Override
public boolean supports(KeyInformation information, TitanPredicate titanPredicate) {
Class<?> dataType = information.getDataType();
Mapping mapping = Mapping.getMapping(information);
if (mapping!=Mapping.DEFAULT && !AttributeUtil.isString(dataType)) return false;
if(information.getCardinality() != Cardinality.SINGLE) {
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 == Cmp.EQUAL || titanPredicate==Cmp.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 || dataType == Instant.class) {
if (titanPredicate instanceof Cmp) return true;
} else if (dataType == Boolean.class) {
return titanPredicate == Cmp.EQUAL || titanPredicate == Cmp.NOT_EQUAL;
} else if (dataType == UUID.class) {
return titanPredicate == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL;
}
return false;
}
示例13: testPropertyCardinality
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
/**
* This test exercises different types of updates against cardinality restricted properties
* to ensure that the resulting behavior is fully consistent.
*/
@Test
public void testPropertyCardinality() {
PropertyKey uid = mgmt.makePropertyKey("uid").dataType(Long.class).cardinality(Cardinality.SINGLE).make();
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
mgmt.buildIndex("byUid", Vertex.class).addKey(uid).unique().buildCompositeIndex();
mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex();
finishSchema();
TitanVertex v1 = tx.addVertex();
v1.property("name", "name1");
TitanVertex v2 = tx.addVertex();
v2.property("uid", 512);
newTx();
v1 = tx.getVertex(v1.longId());
v1.property("name", "name2"); //Ensure that the old index record gets removed
v2 = tx.getVertex(v2.longId());
v2.property("uid", 512); //Ensure that replacement is allowed
newTx();
assertCount(0, tx.query().has("name", "name1").vertices());
assertCount(1, tx.query().has("name", "name2").vertices());
assertCount(1, tx.query().has("uid", 512).vertices());
}
示例14: testReadWideVertexWithManyProperties
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
@Test
public void testReadWideVertexWithManyProperties() {
int numProps = 1 << 16;
long numV = 1;
mgmt.makePropertyKey("p").cardinality(Cardinality.LIST).dataType(Integer.class).make();
mgmt.commit();
finishSchema();
for (int j = 0; j < numV; j++) {
Vertex v = graph.addVertex();
for (int i = 0; i < numProps; i++) {
v.property("p", i);
}
}
graph.tx().commit();
assertEquals(numV, (long) graph.traversal().V().count().next());
Map<String, Object> propertiesOnVertex = graph.traversal().V().valueMap().next();
List<?> valuesOnP = (List)propertiesOnVertex.values().iterator().next();
assertEquals(numProps, valuesOnP.size());
Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties");
GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class));
assertEquals(numV, (long) t.V().count().next());
propertiesOnVertex = t.V().valueMap().next();
valuesOnP = (List)propertiesOnVertex.values().iterator().next();
assertEquals(numProps, valuesOnP.size());
}
示例15: IndexFeatures
import com.thinkaurelius.titan.core.Cardinality; //导入依赖的package包/类
public IndexFeatures(boolean supportsDocumentTTL,
Mapping defaultMap,
ImmutableSet<Mapping> supportedMap, String wildcardField, ImmutableSet<Cardinality> supportedCardinaities, boolean supportsNanoseconds) {
Preconditions.checkArgument(defaultMap!=null || defaultMap!=Mapping.DEFAULT);
Preconditions.checkArgument(supportedMap!=null && !supportedMap.isEmpty()
&& supportedMap.contains(defaultMap));
this.supportsDocumentTTL = supportsDocumentTTL;
this.defaultStringMapping = defaultMap;
this.supportedStringMappings = supportedMap;
this.wildcardField = wildcardField;
this.supportedCardinaities = supportedCardinaities;
this.supportsNanoseconds = supportsNanoseconds;
}