Skip to content

Commit

Permalink
refactor tag parsing into new method
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Jun 8, 2022
1 parent 4b34795 commit 40f0801
Showing 1 changed file with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,7 @@ public void processStream(InputStream input) throws IOException {
}
if (state == ParseState.TAG) {
if (s.startsWith("\t")) {
String[] pair = s.trim().split(": ");
if (pair.length != 2) {
//
// Overriding processStream() thus need to comply with the
// set of exceptions it can throw.
//
throw new IOException("Failed to parse tag: '" + s + "'");
} else {
if (tags.containsKey(pair[1])) {
// Join multiple tags for one revision
String oldtag = tags.get(pair[1]);
tags.remove(pair[1]);
tags.put(pair[1], oldtag + " " + pair[0]);
} else {
tags.put(pair[1], pair[0]);
}
}
parseTag(tags, s);
} else {
state = ParseState.REVISION;
s = in.readLine();
Expand Down Expand Up @@ -158,6 +142,26 @@ public void processStream(InputStream input) throws IOException {
history.setHistoryEntries(entries);
}

private void parseTag(HashMap<String, String> tags, String s) throws IOException {
String[] pair = s.trim().split(": ");
if (pair.length != 2) {
//
// Overriding processStream() thus need to comply with the
// set of exceptions it can throw.
//
throw new IOException("Failed to parse tag: '" + s + "'");
} else {
if (tags.containsKey(pair[1])) {
// Join multiple tags for one revision
String oldTag = tags.get(pair[1]);
tags.remove(pair[1]);
tags.put(pair[1], oldTag + " " + pair[0]);
} else {
tags.put(pair[1], pair[0]);
}
}
}

/**
* Sort history entries in the object according to semantic ordering of the revision string.
* @param history {@link History} object
Expand Down

0 comments on commit 40f0801

Please sign in to comment.