Skip to content

Commit

Permalink
Merge branch 'refactoring/update/angulillos-0.7' (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
laughedelic committed May 13, 2016
2 parents 8e41ad2 + 22de2cd commit 91376fc
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 312 deletions.
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ bucketSuffix := "era7.com"
javaVersion := "1.8"

libraryDependencies ++= Seq(
"bio4j" % "angulillos" % "0.6.0",
"bio4j" % "angulillos" % "0.7.0",
"com.thinkaurelius.titan" % "titan-core" % "1.0.0"
)

excludeFilter in unmanagedSources :=
(excludeFilter in unmanagedSources).value ||
"*Index.java"
89 changes: 89 additions & 0 deletions src/main/java/com/bio4j/angulillos/titan/TitanConversions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.bio4j.angulillos.titan;

import com.bio4j.angulillos.QueryPredicate;
import com.bio4j.angulillos.Arity;

import com.thinkaurelius.titan.core.attribute.Cmp;
import com.thinkaurelius.titan.core.attribute.Contain;
import com.thinkaurelius.titan.core.Multiplicity;
import com.thinkaurelius.titan.core.Cardinality;


public final class TitanConversions {

public static final class Predicate {

public static final Cmp asTitanCmp(QueryPredicate.Compare predicate) {
switch(predicate) {
case EQUAL: return Cmp.EQUAL;
case NOT_EQUAL: return Cmp.NOT_EQUAL;
case GREATER_THAN: return Cmp.GREATER_THAN;
case GREATER_THAN_EQUAL: return Cmp.GREATER_THAN_EQUAL;
case LESS_THAN: return Cmp.LESS_THAN;
case LESS_THAN_EQUAL: return Cmp.LESS_THAN_EQUAL;
// NOTE: this shouldn't happen, because we pattern match on all cases of a sealed enum
default: return Cmp.EQUAL;
}
}

public static final Contain asTitanContain(QueryPredicate.Contain predicate) {
switch(predicate) {
case IN: return Contain.IN;
case NOT_IN: return Contain.NOT_IN;
// NOTE: this shouldn't happen, because we pattern match on all cases of a sealed enum
default: return Contain.IN;
}
}

}

public static final class Arities {
// One/AtMostOne -> ONE
// AtLeastOne/Any -> MANY
// default case represents arity Any

// NOTE: we don't support non-single cardinality in the angulillos API
// public static final Cardinality asTitanCardinality(Arity arity) {
// switch(arity) {
// case One: return Cardinality.SINGLE;
// case AtMostOne: return Cardinality.SINGLE;
// default: return Cardinality.LIST;
// }
// }

public static final Multiplicity asTitanMultiplicity(Arity fromArity, Arity toArity) {
switch(fromArity) {

case One: switch (toArity) {
case One: return Multiplicity.ONE2ONE;
case AtMostOne: return Multiplicity.ONE2ONE;
case AtLeastOne: return Multiplicity.ONE2MANY;
default: return Multiplicity.ONE2MANY;
}

case AtMostOne: switch (toArity) {
case One: return Multiplicity.ONE2ONE;
case AtMostOne: return Multiplicity.ONE2ONE;
case AtLeastOne: return Multiplicity.ONE2MANY;
default: return Multiplicity.ONE2MANY;
}

case AtLeastOne: switch (toArity) {
case One: return Multiplicity.MANY2ONE;
case AtMostOne: return Multiplicity.MANY2ONE;
case AtLeastOne: return Multiplicity.MULTI;
default: return Multiplicity.MULTI;
}

default: switch(toArity) {
case One: return Multiplicity.MANY2ONE;
case AtMostOne: return Multiplicity.MANY2ONE;
case AtLeastOne: return Multiplicity.MULTI;
default: return Multiplicity.MULTI;
}
}
}

}

}

This file was deleted.

Loading

0 comments on commit 91376fc

Please sign in to comment.