Permalink
Browse files

some tidying and refactoring

  • Loading branch information...
1 parent d25cfce commit 81ddcb2fe43ee456c2c15f766a0590213adabba7 @technige technige committed Jan 20, 2012
@@ -322,10 +322,9 @@ public void apply(Iterable<Rule> rules)
*
* @param a node token
* @param properties
- * @throws RuleApplicationException if node is undefined
*/
public void deleteNodes(NodeToken a, Map<String, Object> properties)
- throws RuleApplicationException {
+ {
for (Node node : nodeStore.remove(a)) {
node.delete();
}
@@ -338,7 +337,6 @@ public void deleteNodes(NodeToken a, Map<String, Object> properties)
* @param r relationship token
* @param b end node token
* @param properties
- * @throws RuleApplicationException if start node, end node or type are invalid
*/
public void deleteRelationships(NodeToken a, RelationshipToken r, NodeToken b, Map<String, Object> properties) {
Set<Relationship> relationships;
@@ -359,10 +357,9 @@ public void deleteRelationships(NodeToken a, RelationshipToken r, NodeToken b, M
*
* @param r relationship token
* @param properties
- * @throws RuleApplicationException if type is invalid
*/
public void deleteRelationships(RelationshipToken r, Map<String, Object> properties)
- throws RuleApplicationException {
+ {
deleteRelationships(NodeToken.anon(), r, NodeToken.anon(), properties);
}
@@ -55,9 +55,9 @@ public static Rule from(String text) throws RuleFormatException {
return new Rule(new Descriptor(bits[0]), JSON.toObject(bits[1]));
}
} catch (SyntaxError e) {
- throw new RuleFormatException(0, "Syntax error in rule", e);
+ throw new RuleFormatException("Syntax error in rule", e);
} catch (JSONException e) {
- throw new RuleFormatException(0, "Unparsable JSON in rule", e);
+ throw new RuleFormatException("Unparsable JSON in rule", e);
}
}
@@ -70,7 +70,7 @@ public static Rule from(String text) throws RuleFormatException {
}
return rules;
} catch (JSONException e) {
- throw new RuleFormatException(0, "Cannot parse JSON list", e);
+ throw new RuleFormatException("Cannot parse JSON list", e);
}
}
@@ -29,9 +29,9 @@ public GeoffLoadException(int ruleNumber, String s) {
this.ruleNumber = ruleNumber;
}
- public GeoffLoadException(int ruleNumber, String s, Throwable throwable) {
+ public GeoffLoadException(String s, Throwable throwable) {
super(s, throwable);
- this.ruleNumber = ruleNumber;
+ this.ruleNumber = null;
}
}
@@ -21,8 +21,8 @@
public class RuleFormatException extends GeoffLoadException {
- public RuleFormatException(int ruleNumber, String s, Throwable throwable) {
- super(ruleNumber, s, throwable);
+ public RuleFormatException(String s, Throwable throwable) {
+ super(s, throwable);
}
}
@@ -30,20 +30,20 @@ private static String beforeDot(String name) {
}
}
- private static int afterDot(String name, int defaultValue) {
+ private static int afterDot(String name) {
int dot = name.indexOf('.');
if (dot >= 0) {
return Integer.parseInt(name.substring(dot + 1));
} else {
- return defaultValue;
+ return 0;
}
}
protected final int index;
public EntityToken(Type tokenType, String name) {
super(tokenType, beforeDot(name));
- this.index = afterDot(name, 0);
+ this.index = afterDot(name);
}
public int getIndex() {
@@ -51,7 +51,7 @@ public static boolean isNameChar(char ch) {
tokens.add(readNodeToken());
break;
case '[':
- tokens.add(readRelToken());
+ tokens.add(readRelationshipToken());
break;
case '|':
tokens.add(readIndexToken());
@@ -103,7 +103,7 @@ public NodeToken readNodeToken() throws IOException, EndOfStreamException, Unexp
return token;
}
- public RelationshipToken readRelToken() throws IOException, EndOfStreamException, UnexpectedCharacterException {
+ public RelationshipToken readRelationshipToken() throws IOException, EndOfStreamException, UnexpectedCharacterException {
read('[');
String name = readName();
String type = "";
@@ -77,29 +77,4 @@
}
}
- /**
- * Parse the supplied text as a JSON object containing other sub-objects;
- * might validly be empty so fail gracefully in that case
- *
- * @param json
- * @return
- * @throws JSONException
- */
- @SuppressWarnings("unchecked")
- public static Map<String, Map<String, Object>> toObjectOfObjects(String json)
- throws JSONException {
- if (json == null || json.isEmpty()) {
- return null;
- } else {
- ObjectMapper mapper = new ObjectMapper();
- try {
- return (Map<String, Map<String, Object>>) mapper.readValue(json, Object.class);
- } catch (ClassCastException e) {
- throw new JSONException("Unable to cast JSON to Map<String,Map<String, Object>>", e);
- } catch (IOException e) {
- throw new JSONException("Unable to read JSON", e);
- }
- }
- }
-
}

0 comments on commit 81ddcb2

Please sign in to comment.