Skip to content

Commit

Permalink
Add toString() methods to several classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjon3377 committed Mar 17, 2024
1 parent 7fe4d08 commit d5219f9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lovelace-util/src/main/java/lovelace/util/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public RangeIterator(final Range range) {
upperBound = range.upperBound;
}

@Override
public String toString() {
return "RangeIterator (" + current + ", " + upperBound + ")";
}

@Override
public boolean hasNext() {
return current < upperBound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
*/
public class ResourceInputStream extends InputStream {
private final InputStream wrapped;
private final String filename;

public ResourceInputStream(final String filename) throws NoSuchFileException {
this(filename, ResourceInputStream.class);
}

public ResourceInputStream(final String filename, final Class<?> sourceClass) throws NoSuchFileException {
this.filename = filename;
InputStream temp;
try {
// N.B. we don't use Files::newInputStream because we'd have to either catch or throw IOException.
Expand Down Expand Up @@ -85,4 +87,9 @@ public int available() throws IOException {
public void close() throws IOException {
wrapped.close();
}

@Override
public String toString() {
return "ResourceInputStream for: " + filename;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* A convenience wrapper around {@link CardLayout} so callers don't have to
* pass around a reference to the laid-out container to flip between cards.
*/
@SuppressWarnings("ClassHasNoToStringMethod") // CardLayout toString suffices
public class SimpleCardLayout extends CardLayout {
@Serial
private static final long serialVersionUID = 1;
Expand Down
5 changes: 5 additions & 0 deletions lovelace-util/src/main/java/lovelace/util/SimplePair.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public int hashCode() {
public static <Type> SimplePair<Type> of(final Type first, final Type second) {
return new SimplePair<>(first, second);
}

@Override
public String toString() {
return "SimplePair["+ first + "," + second + "]";
}
}
10 changes: 10 additions & 0 deletions lovelace-util/src/main/java/lovelace/util/StreamingLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public String getColorName() {
LabelTextColor(final String color) {
colorName = color;
}

@Override
public String toString() {
return colorName;
}
}

private final StringBuilder buffer = new StringBuilder();
Expand Down Expand Up @@ -55,4 +60,9 @@ public void appendLine(final String string) {
setText("<html><body bgcolor=\"#000000\">" + buffer + "</body></html>");
repaint();
}

@Override
public String toString() {
return "StreamingLabel with " + buffer.length() + " characters.";
}
}
12 changes: 12 additions & 0 deletions lovelace-util/src/main/java/lovelace/util/TypeStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,23 @@ public Iterator<Class<?>> iterator() {
return new TypeIterator(obj, cache);
}

@Override
public String toString() {
return "TypeStream for " + obj;
}

private static final class TypeIterator implements Iterator<Class<?>> {
private final LinkedList<Class<?>> ourCopy;
private final List<Class<?>> cache;
private final Collection<Class<?>> classes = new HashSet<>();
private final Queue<Class<?>> queue = new LinkedList<>();
private final String str;

public TypeIterator(final Object obj, final List<Class<?>> cache) {
this.cache = cache;
ourCopy = new LinkedList<>(cache);
queue.add(obj.getClass());
str = "TypeStream iterator for: " + obj;
}

@Override
Expand Down Expand Up @@ -63,5 +70,10 @@ public Class<?> next() {
}
throw new NoSuchElementException("No more supertypes");
}

@Override
public String toString() {
return str;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ public boolean hasNext() {
return wrapped.hasNext();
}
}

@Override
public String toString() {
return "TypesafeXMLEventReader wrapping: " + wrapped;
}
}

0 comments on commit d5219f9

Please sign in to comment.