Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
/**
* Wrapos another {@link SpreadsheetFormatter} and uses the provided {@link #toString()}.
*/
final class ToStringSpreadsheetFormatter implements SpreadsheetFormatter,
TreePrintable {
final class SpreadsheetFormatterSharedToString extends SpreadsheetFormatterShared
implements TreePrintable {

static SpreadsheetFormatter with(final SpreadsheetFormatter formatter,
final String toString) {
Expand All @@ -45,13 +45,13 @@ static SpreadsheetFormatter with(final SpreadsheetFormatter formatter,
if (temp.toString().equals(toString)) {
formatterWithToString = formatter; // no need to wrap
} else {
if (temp instanceof ToStringSpreadsheetFormatter) {
temp = ((ToStringSpreadsheetFormatter) temp).formatter;
if (temp instanceof SpreadsheetFormatterSharedToString) {
temp = ((SpreadsheetFormatterSharedToString) temp).formatter;
}
if (temp.toString().equals(toString)) {
formatterWithToString = formatter; // no need to wrap
} else {
formatterWithToString = new ToStringSpreadsheetFormatter(
formatterWithToString = new SpreadsheetFormatterSharedToString(
formatter,
toString
);
Expand All @@ -61,8 +61,8 @@ static SpreadsheetFormatter with(final SpreadsheetFormatter formatter,
return formatterWithToString;
}

private ToStringSpreadsheetFormatter(final SpreadsheetFormatter formatter,
final String toString) {
private SpreadsheetFormatterSharedToString(final SpreadsheetFormatter formatter,
final String toString) {
super();

this.formatter = formatter;
Expand Down Expand Up @@ -98,11 +98,11 @@ public int hashCode() {
@Override
public boolean equals(final Object other) {
return this == other ||
other instanceof ToStringSpreadsheetFormatter &&
other instanceof SpreadsheetFormatterSharedToString &&
this.equals0(Cast.to(other));
}

private boolean equals0(final ToStringSpreadsheetFormatter other) {
private boolean equals0(final SpreadsheetFormatterSharedToString other) {
return this.formatter.equals(other.formatter) &&
this.toString.equals(other.toString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ public static SpreadsheetFormatter text(final TextSpreadsheetFormatParserToken t
}

/**
* {@see ToStringSpreadsheetFormatter}
* {@see SpreadsheetFormatterSharedToString}
*/
public static SpreadsheetFormatter toString(final SpreadsheetFormatter formatter,
final String toString) {
return ToStringSpreadsheetFormatter.with(
return SpreadsheetFormatterSharedToString.with(
formatter,
toString
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

import org.junit.jupiter.api.Test;
import walkingkooka.HashCodeEqualsDefinedTesting2;
import walkingkooka.ToStringTesting;
import walkingkooka.collect.list.Lists;
import walkingkooka.reflect.ClassTesting2;
import walkingkooka.reflect.JavaVisibility;
import walkingkooka.spreadsheet.format.provider.SpreadsheetFormatterSelectorToken;
import walkingkooka.tree.text.TextNode;

Expand All @@ -33,10 +30,8 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;

public final class ToStringSpreadsheetFormatterTest implements SpreadsheetFormatterTesting2<ToStringSpreadsheetFormatter>,
HashCodeEqualsDefinedTesting2<ToStringSpreadsheetFormatter>,
ToStringTesting<ToStringSpreadsheetFormatter>,
ClassTesting2<ToStringSpreadsheetFormatter> {
public final class SpreadsheetFormatterSharedToStringTest extends SpreadsheetFormatterSharedTestCase<SpreadsheetFormatterSharedToString>
implements HashCodeEqualsDefinedTesting2<SpreadsheetFormatterSharedToString> {

private final static List<SpreadsheetFormatterSelectorToken> TOKENS = Lists.of(
SpreadsheetFormatterSelectorToken.with(
Expand Down Expand Up @@ -83,7 +78,7 @@ public String toString() {
public void testWithNullFormatterFails() {
assertThrows(
NullPointerException.class,
() -> ToStringSpreadsheetFormatter.with(
() -> SpreadsheetFormatterSharedToString.with(
null,
TO_STRING
)
Expand All @@ -94,7 +89,7 @@ public void testWithNullFormatterFails() {
public void testWithNullToStringFails() {
assertThrows(
NullPointerException.class,
() -> ToStringSpreadsheetFormatter.with(
() -> SpreadsheetFormatterSharedToString.with(
FORMATTER,
null
)
Expand All @@ -105,7 +100,7 @@ public void testWithNullToStringFails() {
public void testWithToStringSameToString() {
assertSame(
FORMATTER,
ToStringSpreadsheetFormatter.with(
SpreadsheetFormatterSharedToString.with(
FORMATTER,
FORMATTER.toString()
)
Expand All @@ -114,10 +109,10 @@ public void testWithToStringSameToString() {

@Test
public void testWithToStringSameToString2() {
final ToStringSpreadsheetFormatter formatter = this.createFormatter();
final SpreadsheetFormatterSharedToString formatter = this.createFormatter();
assertSame(
formatter,
ToStringSpreadsheetFormatter.with(
SpreadsheetFormatterSharedToString.with(
formatter,
formatter.toString()
)
Expand All @@ -126,11 +121,11 @@ public void testWithToStringSameToString2() {

@Test
public void testWithToStringSpreadsheetFormatterUnwraps() {
final ToStringSpreadsheetFormatter formatter = this.createFormatter();
final SpreadsheetFormatterSharedToString formatter = this.createFormatter();

assertSame(
formatter,
ToStringSpreadsheetFormatter.with(
SpreadsheetFormatterSharedToString.with(
formatter,
FORMATTER.toString()
)
Expand All @@ -155,9 +150,9 @@ public void testTokens() {
}

@Override
public ToStringSpreadsheetFormatter createFormatter() {
return (ToStringSpreadsheetFormatter)
ToStringSpreadsheetFormatter.with(
public SpreadsheetFormatterSharedToString createFormatter() {
return (SpreadsheetFormatterSharedToString)
SpreadsheetFormatterSharedToString.with(
FORMATTER,
TO_STRING
);
Expand All @@ -178,7 +173,7 @@ public Object value() {
@Test
public void testEqualsDifferentFormatter() {
this.checkNotEquals(
ToStringSpreadsheetFormatter.with(
SpreadsheetFormatterSharedToString.with(
SpreadsheetFormatters.fake(),
TO_STRING
)
Expand All @@ -188,15 +183,15 @@ public void testEqualsDifferentFormatter() {
@Test
public void testEqualsDifferentToString() {
this.checkNotEquals(
ToStringSpreadsheetFormatter.with(
SpreadsheetFormatterSharedToString.with(
FORMATTER,
"DifferentToString"
)
);
}

@Override
public ToStringSpreadsheetFormatter createObject() {
public SpreadsheetFormatterSharedToString createObject() {
return this.createFormatter();
}

Expand All @@ -216,20 +211,15 @@ public void testToString() {
public void testTreePrintable() {
this.treePrintAndCheck(
this.createFormatter(),
"ToStringSpreadsheetFormatter\n" +
" TestSpreadsheetFormatter (walkingkooka.spreadsheet.format.ToStringSpreadsheetFormatterTest$1)\n"
"SpreadsheetFormatterSharedToString\n" +
" TestSpreadsheetFormatter (walkingkooka.spreadsheet.format.SpreadsheetFormatterSharedToStringTest$1)\n"
);
}

// Class............................................................................................................

@Override
public Class<ToStringSpreadsheetFormatter> type() {
return ToStringSpreadsheetFormatter.class;
}

@Override
public JavaVisibility typeVisibility() {
return JavaVisibility.PACKAGE_PRIVATE;
public Class<SpreadsheetFormatterSharedToString> type() {
return SpreadsheetFormatterSharedToString.class;
}
}
Loading