Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1856ae7
commit 1db4ba8
Showing
5 changed files
with
68 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
titan-core/src/main/java/com/thinkaurelius/titan/graphdb/tinkerpop/TitanGraphVariables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.thinkaurelius.titan.graphdb.tinkerpop; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration; | ||
import com.tinkerpop.gremlin.structure.Graph; | ||
import com.tinkerpop.gremlin.structure.util.StringFactory; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Matthias Broecheler (me@matthiasb.com) | ||
*/ | ||
public class TitanGraphVariables implements Graph.Variables { | ||
|
||
private final WriteConfiguration config; | ||
|
||
public TitanGraphVariables(WriteConfiguration config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public Set<String> keys() { | ||
return Sets.newHashSet(config.getKeys("")); | ||
} | ||
|
||
@Override | ||
public <R> Optional<R> get(String s) { | ||
if (s==null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull(); | ||
if (StringUtils.isEmpty(s)) throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty(); | ||
Object value = config.get(s,Object.class); | ||
if (value==null) return Optional.empty(); | ||
else return Optional.of((R)value); | ||
} | ||
|
||
@Override | ||
public void set(String s, Object o) { | ||
if (s==null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull(); | ||
if (StringUtils.isEmpty(s)) throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty(); | ||
if (o==null) throw Graph.Variables.Exceptions.variableValueCanNotBeNull(); | ||
config.set(s,o); | ||
} | ||
|
||
@Override | ||
public void remove(String s) { | ||
if (s==null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull(); | ||
if (StringUtils.isEmpty(s)) throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty(); | ||
config.remove(s); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return StringFactory.graphVariablesString(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters