Skip to content

Commit

Permalink
Minor refactoring for better clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Apr 9, 2010
1 parent f6cfda7 commit f5aa347
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/com/googlecode/jbencode/composite/DictionaryType.java
Expand Up @@ -20,13 +20,13 @@ public DictionaryType() {


@Override @Override
protected final void writeValue(OutputStream os) throws IOException { protected final void writeValue(OutputStream os) throws IOException {
final SortedSet<Key<?>> keys = new TreeSet<Key<?>>(); final SortedSet<EntryType<?>> entries = new TreeSet<EntryType<?>>();
populate(keys); populate(entries);


for (Key<?> key : keys) { for (EntryType<?> entry : entries) {
key.write(os); entry.write(os);
} }
} }


protected abstract void populate(SortedSet<Key<?>> keys); protected abstract void populate(SortedSet<EntryType<?>> entries);
} }
8 changes: 4 additions & 4 deletions src/com/googlecode/jbencode/composite/DictionaryValue.java
Expand Up @@ -13,22 +13,22 @@
* @author Daniel Spiewak * @author Daniel Spiewak
*/ */
@Prefix('d') @Prefix('d')
public class DictionaryValue extends CompositeValue<DictionaryValue, EntryPair> { public class DictionaryValue extends CompositeValue<DictionaryValue, EntryValue> {
private EntryPair previous; private EntryValue previous;


public DictionaryValue(Parser p, InputStream is) { public DictionaryValue(Parser p, InputStream is) {
super(p, is); super(p, is);


previous = null; previous = null;
} }


public EntryPair next() { public EntryValue next() {
try { try {
if (previous != null) { if (previous != null) {
previous.resolve(); previous.resolve();
} }


return previous = new EntryPair(this); return previous = new EntryValue(this);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Expand Down
Expand Up @@ -12,11 +12,11 @@
/** /**
* @author Daniel Spiewak * @author Daniel Spiewak
*/ */
public final class Key<T extends StringType & Comparable<T>> implements Type, Comparable<Key<T>> { public final class EntryType<T extends StringType & Comparable<T>> implements Type, Comparable<EntryType<T>> {
private final T key; private final T key;
private final Type value; private final Type value;


public Key(T key, Type value) { public EntryType(T key, Type value) {
this.key = key; this.key = key;
this.value = value; this.value = value;
} }
Expand All @@ -26,7 +26,7 @@ public void write(OutputStream os) throws IOException {
value.write(os); value.write(os);
} }


public int compareTo(Key<T> o) { public int compareTo(EntryType<T> o) {
return o.key.compareTo(key); return o.key.compareTo(key);
} }
} }
Expand Up @@ -11,19 +11,19 @@
/** /**
* @author Daniel Spiewak * @author Daniel Spiewak
*/ */
public class EntryPair implements Value<EntryPair> { public class EntryValue implements Value<EntryValue> {
private final DictionaryValue parent; private final DictionaryValue parent;


private StringValue key; private StringValue key;
private Value<?> value; private Value<?> value;


private boolean resolved = false; private boolean resolved = false;


EntryPair(DictionaryValue parent) { EntryValue(DictionaryValue parent) {
this.parent = parent; this.parent = parent;
} }


public EntryPair resolve() throws IOException { public EntryValue resolve() throws IOException {
if (resolved) { if (resolved) {
throw new IOException("Value already resolved"); throw new IOException("Value already resolved");
} }
Expand Down
4 changes: 2 additions & 2 deletions test/ParserTest.java
Expand Up @@ -8,7 +8,7 @@
import com.googlecode.jbencode.Parser; import com.googlecode.jbencode.Parser;
import com.googlecode.jbencode.Value; import com.googlecode.jbencode.Value;
import com.googlecode.jbencode.composite.DictionaryValue; import com.googlecode.jbencode.composite.DictionaryValue;
import com.googlecode.jbencode.composite.EntryPair; import com.googlecode.jbencode.composite.EntryValue;
import com.googlecode.jbencode.composite.ListValue; import com.googlecode.jbencode.composite.ListValue;
import com.googlecode.jbencode.primitive.IntegerValue; import com.googlecode.jbencode.primitive.IntegerValue;
import com.googlecode.jbencode.primitive.StringValue; import com.googlecode.jbencode.primitive.StringValue;
Expand Down Expand Up @@ -36,7 +36,7 @@ public void testParse() throws IOException {
DictionaryValue dict = (DictionaryValue) value; DictionaryValue dict = (DictionaryValue) value;


System.out.println('{'); System.out.println('{');
for (EntryPair pair : dict) { for (EntryValue pair : dict) {
System.out.print(" \"" + new String(pair.getKey().resolve()) + "\" -> "); System.out.print(" \"" + new String(pair.getKey().resolve()) + "\" -> ");


if (pair.getValue() instanceof IntegerValue) { if (pair.getValue() instanceof IntegerValue) {
Expand Down

0 comments on commit f5aa347

Please sign in to comment.