diff options
author | Vladimir Piskarev | 2015-08-25 08:13:01 +0000 |
---|---|---|
committer | Vladimir Piskarev | 2015-08-25 08:20:17 +0000 |
commit | 5faad53f881d1e1cb7976e18d251e38273371df1 (patch) | |
tree | c1dedfac781d09154f41ca8d2f37bffbdff38d66 | |
parent | 2ced3047cdfa27641393911a34ec6b937ec962fa (diff) | |
download | org.eclipse.handly-5faad53f881d1e1cb7976e18d251e38273371df1.tar.gz org.eclipse.handly-5faad53f881d1e1cb7976e18d251e38273371df1.tar.xz org.eclipse.handly-5faad53f881d1e1cb7976e18d251e38273371df1.zip |
Some enhancements in TextIndent and IHandle.ToStringStyle
-rw-r--r-- | org.eclipse.handly/src/org/eclipse/handly/model/IHandle.java | 6 | ||||
-rw-r--r-- | org.eclipse.handly/src/org/eclipse/handly/util/TextIndent.java | 69 |
2 files changed, 54 insertions, 21 deletions
diff --git a/org.eclipse.handly/src/org/eclipse/handly/model/IHandle.java b/org.eclipse.handly/src/org/eclipse/handly/model/IHandle.java index e034f8ed..3cce7ee7 100644 --- a/org.eclipse.handly/src/org/eclipse/handly/model/IHandle.java +++ b/org.eclipse.handly/src/org/eclipse/handly/model/IHandle.java @@ -163,7 +163,7 @@ public interface IHandle final class ToStringStyle { private final TextIndent indent; - private final EnumSet<Option> options; + private final Set<Option> options; /** * Creates a new style with the given indent and options. @@ -178,7 +178,7 @@ public interface IHandle if (options == null) throw new IllegalArgumentException(); this.indent = indent; - this.options = options; + this.options = Collections.unmodifiableSet(options); } /** @@ -198,7 +198,7 @@ public interface IHandle */ public Set<Option> getOptions() { - return Collections.unmodifiableSet(options); + return options; } /** diff --git a/org.eclipse.handly/src/org/eclipse/handly/util/TextIndent.java b/org.eclipse.handly/src/org/eclipse/handly/util/TextIndent.java index 9bc4fc87..f85cb82b 100644 --- a/org.eclipse.handly/src/org/eclipse/handly/util/TextIndent.java +++ b/org.eclipse.handly/src/org/eclipse/handly/util/TextIndent.java @@ -11,7 +11,13 @@ package org.eclipse.handly.util; /** - * A text indent has a level and is based on an indentation string. + * A text indent has a level and is based on a given indentation unit such as + * two spaces or a tab. Its string representation is the indentation unit + * repeated the number of times equal to the indentation level. + * <p> + * A text indent is a value object. Its indentation level and unit + * do not change over time. + * </p> */ public final class TextIndent { @@ -21,19 +27,19 @@ public final class TextIndent public static final TextIndent NONE = new TextIndent(0, ""); //$NON-NLS-1$ private final int level; - private final String space; + private final String unit; /** - * Returns a text indent of level 0 with the given indentation string. + * Returns a text indent of level 0 with the given indentation unit. * - * @param space an indentation string (not <code>null</code>) - * @return a text indent of level 0 with the given indentation string + * @param unit an indentation unit (not <code>null</code>) + * @return a text indent of level 0 with the given indentation unit */ - public static TextIndent with(String space) + public static TextIndent with(String unit) { - if (space == null) + if (unit == null) throw new IllegalArgumentException(); - return new TextIndent(0, space); + return new TextIndent(0, unit); } /** @@ -47,29 +53,29 @@ public final class TextIndent } /** - * Returns whether this text indent is empty, i.e. is based on an empty - * indentation string. + * Returns whether this text indent is empty, i.e. + * its indentation unit is an empty string. * * @return <code>true</code> if this text indent is empty, * <code>false</code> otherwise */ public boolean isEmpty() { - return space.isEmpty(); + return unit.isEmpty(); } /** - * Returns a text indent increased by one level. Does not modify this object. + * Returns a text indent increased by one level. * * @return a text indent increased by one level (never <code>null</code>) */ public TextIndent getIncreasedIndent() { - return new TextIndent(level + 1, space); + return new TextIndent(level + 1, unit); } /** - * Returns a text indent decreased by one level. Does not modify this object. + * Returns a text indent decreased by one level. * * @return a text indent decreased by one level (never <code>null</code>) * @throws IllegalStateException if this indent's level is zero @@ -78,7 +84,7 @@ public final class TextIndent { if (level == 0) throw new IllegalStateException(); - return new TextIndent(level - 1, space); + return new TextIndent(level - 1, unit); } /** @@ -99,7 +105,7 @@ public final class TextIndent public void appendTo(StringBuilder builder) { for (int i = 0; i < level; i++) - builder.append(space); + builder.append(unit); } @Override @@ -110,9 +116,36 @@ public final class TextIndent return builder.toString(); } - private TextIndent(int level, String space) + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + level; + result = prime * result + unit.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TextIndent other = (TextIndent)obj; + if (level != other.level) + return false; + if (!unit.equals(other.unit)) + return false; + return true; + } + + private TextIndent(int level, String unit) { this.level = level; - this.space = space; + this.unit = unit; } } |