Skip to content

Commit c17a068

Browse files
committed
SpreadsheetViewportRectangle implements HasUrlFragment
1 parent 81af8ea commit c17a068

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/main/java/walkingkooka/spreadsheet/viewport/SpreadsheetViewportRectangle.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package walkingkooka.spreadsheet.viewport;
1919

20+
import walkingkooka.net.HasUrlFragment;
21+
import walkingkooka.net.UrlFragment;
2022
import walkingkooka.spreadsheet.reference.SpreadsheetCellReference;
2123
import walkingkooka.spreadsheet.reference.SpreadsheetSelection;
2224
import walkingkooka.text.CharSequences;
@@ -36,7 +38,8 @@
3638
*/
3739
@SuppressWarnings("lgtm[java/inconsistent-equals-and-hashcode]")
3840
public final class SpreadsheetViewportRectangle implements Comparable<SpreadsheetViewportRectangle>,
39-
TreePrintable {
41+
TreePrintable,
42+
HasUrlFragment {
4043

4144
final static CharacterConstant SEPARATOR = CharacterConstant.with(':');
4245

@@ -278,4 +281,38 @@ public void printTree(final IndentingPrinter printer) {
278281
printer.print("height: ");
279282
printer.println(String.valueOf(this.height));
280283
}
284+
285+
// UrlFragment......................................................................................................
286+
287+
// /home/A1/width/200/height/300
288+
@Override
289+
public UrlFragment urlFragment() {
290+
return UrlFragment.SLASH.append(HOME)
291+
.appendSlashThen(this.home.urlFragment())
292+
.appendSlashThen(WIDTH)
293+
.appendSlashThen(
294+
UrlFragment.with(
295+
toStringWithoutExtraTrailingZero(this.width)
296+
)
297+
).appendSlashThen(HEIGHT)
298+
.appendSlashThen(
299+
UrlFragment.with(
300+
toStringWithoutExtraTrailingZero(this.height)
301+
)
302+
);
303+
}
304+
305+
private static String toStringWithoutExtraTrailingZero(final double value) {
306+
final String toString = String.valueOf(value);
307+
return toString.endsWith(".0") ?
308+
toString.substring(
309+
0,
310+
toString.length() - 2
311+
) :
312+
toString;
313+
}
314+
315+
private final static UrlFragment HOME = UrlFragment.with("home");
316+
private final static UrlFragment WIDTH = UrlFragment.with("width");
317+
private final static UrlFragment HEIGHT = UrlFragment.with("height");
281318
}

src/test/java/walkingkooka/spreadsheet/viewport/SpreadsheetViewportRectangleTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.jupiter.api.Test;
2121
import walkingkooka.HashCodeEqualsDefinedTesting2;
2222
import walkingkooka.ToStringTesting;
23+
import walkingkooka.net.HasUrlFragmentTesting;
2324
import walkingkooka.reflect.ClassTesting2;
2425
import walkingkooka.reflect.JavaVisibility;
2526
import walkingkooka.spreadsheet.reference.SpreadsheetCellReference;
@@ -39,7 +40,8 @@ public final class SpreadsheetViewportRectangleTest implements ClassTesting2<Spr
3940
JsonNodeMarshallingTesting<SpreadsheetViewportRectangle>,
4041
ParseStringTesting<SpreadsheetViewportRectangle>,
4142
ToStringTesting<SpreadsheetViewportRectangle>,
42-
TreePrintableTesting {
43+
TreePrintableTesting,
44+
HasUrlFragmentTesting {
4345

4446
private final static double WIDTH = 50;
4547
private final static double HEIGHT = 30;
@@ -404,6 +406,28 @@ public void testTreePrint() {
404406
);
405407
}
406408

409+
// UrlFragment......................................................................................................
410+
411+
@Test
412+
public void testUrlFragment() {
413+
this.urlFragmentAndCheck(
414+
this.createObject(),
415+
"/home/B9/width/50/height/30"
416+
);
417+
}
418+
419+
@Test
420+
public void testUrlFragment2() {
421+
this.urlFragmentAndCheck(
422+
SpreadsheetViewportRectangle.with(
423+
this.home(),
424+
30.5,
425+
40.5
426+
),
427+
"/home/B9/width/30.5/height/40.5"
428+
);
429+
}
430+
407431
// toString.........................................................................................................
408432

409433
@Test

0 commit comments

Comments
 (0)