2222import  walkingkooka .UsesToStringBuilder ;
2323import  walkingkooka .net .HasUrlFragment ;
2424import  walkingkooka .net .UrlFragment ;
25+ import  walkingkooka .spreadsheet .reference .SpreadsheetCellReference ;
2526import  walkingkooka .text .cursor .TextCursor ;
27+ import  walkingkooka .text .cursor .TextCursorSavePoint ;
2628import  walkingkooka .text .cursor .TextCursors ;
2729import  walkingkooka .text .printer .IndentingPrinter ;
2830import  walkingkooka .text .printer .TreePrintable ;
2931
3032import  java .util .Objects ;
3133
3234/** 
33-  * A value object that holds only a {@link SpreadsheetViewportRectangle} and {@link SpreadsheetViewportNavigationList}. 
34-  * This is intended to be the missing parts when combined with a {@link AnchoredSpreadsheetSelection} to create a 
35-  * {@link SpreadsheetViewport}. 
35+  * Holds the home and navigation list. This will appear within HistoryTokens, and merged with the {@link AnchoredSpreadsheetSelection} 
36+  * and viewport width and height to create a {@link SpreadsheetViewport}. 
3637 */ 
37- public  final  class  SpreadsheetViewportRectangleNavigationList  implements  HasUrlFragment ,
38+ public  final  class  SpreadsheetViewportHomeNavigationList  implements  HasUrlFragment ,
3839    TreePrintable ,
3940    UsesToStringBuilder  {
4041
4142    /** 
42-      * Accepts a {@link UrlFragment} that contains encoded within it a {@link SpreadsheetViewport }. 
43+      * Accepts a {@link UrlFragment} that contains encoded within it a {@link SpreadsheetViewportHomeNavigationList }. 
4344     * <pre> 
44-      * /home/ A1/width/200/height/300/navigations/ left 400  
45+      * /A1/left 400px  
4546     * </pre> 
4647     */ 
47-     public  static  SpreadsheetViewportRectangleNavigationList  fromUrlFragment (final  UrlFragment  urlFragment ) {
48+     public  static  SpreadsheetViewportHomeNavigationList  fromUrlFragment (final  UrlFragment  urlFragment ) {
4849        Objects .requireNonNull (urlFragment , "urlFragment" );
4950
5051        final  String  text  = urlFragment .value ();
5152        final  TextCursor  cursor  = TextCursors .charSequence (text );
5253        final  SpreadsheetViewportParser  parser  = SpreadsheetViewportParser .with (cursor );
5354
54-         SpreadsheetViewportRectangleNavigationList  spreadsheetViewportRectangleNavigationList  = with (
55-             parser .parseSpreadsheetViewportRectangle ()
55+         parser .slash ();
56+ 
57+         SpreadsheetViewportHomeNavigationList  SpreadsheetViewportHomeNavigationList  = with (
58+             parser .homeCellReference ()
5659        );
5760
5861        if  (parser .optionalSlash ()) {
59-             parser .navigationToken ();
60-             parser .slash ();
61- 
62-             spreadsheetViewportRectangleNavigationList  = spreadsheetViewportRectangleNavigationList .setNavigations (
63-                 parser .navigations ()
64-             );
62+             final  TextCursorSavePoint  save  = parser .cursor .save ();
63+ 
64+             try  {
65+                 SpreadsheetViewportHomeNavigationList  = SpreadsheetViewportHomeNavigationList .setNavigations (
66+                     parser .navigations ()
67+                 );
68+             } catch  (final  InvalidCharacterException  cause ) {
69+                 throw  cause .setTextAndPosition (
70+                     text ,
71+                     save .lineInfo ()
72+                         .textOffset () +
73+                         cause .position ()
74+                 );
75+             }
6576        }
6677
6778        if  (cursor .isNotEmpty ()) {
@@ -72,87 +83,87 @@ public static SpreadsheetViewportRectangleNavigationList fromUrlFragment(final U
7283            );
7384        }
7485
75-         return  spreadsheetViewportRectangleNavigationList ;
86+         return  SpreadsheetViewportHomeNavigationList ;
7687    }
7788
7889    /** 
7990     * Factory that creates a {@link SpreadsheetViewport} with the given cell home. 
8091     */ 
81-     public  static  SpreadsheetViewportRectangleNavigationList  with (final  SpreadsheetViewportRectangle   rectangle ) {
82-         Objects .requireNonNull (rectangle , "rectangle " );
92+     public  static  SpreadsheetViewportHomeNavigationList  with (final  SpreadsheetCellReference   home ) {
93+         Objects .requireNonNull (home , "home " );
8394
8495        return  with (
85-             rectangle ,
96+             home ,
8697            SpreadsheetViewport .NO_NAVIGATION 
8798        );
8899    }
89100
90101    // @VisibleForTesting 
91-     static  SpreadsheetViewportRectangleNavigationList  with (final  SpreadsheetViewportRectangle   rectangle ,
92-                                                             final  SpreadsheetViewportNavigationList  navigations ) {
93-         return  new  SpreadsheetViewportRectangleNavigationList (
94-             rectangle ,
102+     static  SpreadsheetViewportHomeNavigationList  with (final  SpreadsheetCellReference   home ,
103+                                                        final  SpreadsheetViewportNavigationList  navigations ) {
104+         return  new  SpreadsheetViewportHomeNavigationList (
105+             home ,
95106            navigations 
96107        );
97108    }
98109
99-     private  SpreadsheetViewportRectangleNavigationList (final  SpreadsheetViewportRectangle   rectangle ,
100-                                                         final  SpreadsheetViewportNavigationList  navigations ) {
110+     private  SpreadsheetViewportHomeNavigationList (final  SpreadsheetCellReference   home ,
111+                                                    final  SpreadsheetViewportNavigationList  navigations ) {
101112        super ();
102-         this .rectangle  = rectangle ;
113+         this .home  = home ;
103114        this .navigations  = navigations ;
104115    }
105116
106-     // rectangle ........................................................................................................ 
117+     // home ........................................................................................................ 
107118
108-     public  SpreadsheetViewportRectangle   rectangle () {
109-         return  this .rectangle ;
119+     public  SpreadsheetCellReference   home () {
120+         return  this .home ;
110121    }
111122
112-     public  SpreadsheetViewportRectangleNavigationList   setRectangle (final  SpreadsheetViewportRectangle   rectangle ) {
113-         Objects .requireNonNull (rectangle , "rectangle " );
123+     public  SpreadsheetViewportHomeNavigationList   setHome (final  SpreadsheetCellReference   home ) {
124+         Objects .requireNonNull (home , "home " );
114125
115-         return  this .rectangle .equals (rectangle ) ?
126+         return  this .home .equals (home ) ?
116127            this  :
117-             new  SpreadsheetViewportRectangleNavigationList (
118-                 rectangle ,
128+             new  SpreadsheetViewportHomeNavigationList (
129+                 home ,
119130                this .navigations 
120131            );
121132    }
122133
123-     private  final  SpreadsheetViewportRectangle   rectangle ;
134+     private  final  SpreadsheetCellReference   home ;
124135
125136    // navigations...................................................................................................... 
126137
127138    public  SpreadsheetViewportNavigationList  navigations () {
128139        return  this .navigations ;
129140    }
130141
131-     public  SpreadsheetViewportRectangleNavigationList  setNavigations (final  SpreadsheetViewportNavigationList  navigations ) {
142+     public  SpreadsheetViewportHomeNavigationList  setNavigations (final  SpreadsheetViewportNavigationList  navigations ) {
132143        Objects .requireNonNull (navigations , "navigations" );
133144
134145        return  this .navigations .equals (navigations ) ?
135146            this  :
136-             new  SpreadsheetViewportRectangleNavigationList (
137-                 this .rectangle ,
147+             new  SpreadsheetViewportHomeNavigationList (
148+                 this .home ,
138149                navigations 
139150            );
140151    }
141152
142153    private  final  SpreadsheetViewportNavigationList  navigations ;
143154
144155    // TreePrintable.................................................................................................... 
145- 
156+      
146157    @ Override 
147158    public  void  printTree (final  IndentingPrinter  printer ) {
148159        printer .println (this .getClass ().getSimpleName ());
149160        printer .indent ();
150161        {
151-             printer .println ("rectangle :" );
162+             printer .println ("home :" );
152163
153164            printer .indent ();
154165            {
155-                 this .rectangle ()
166+                 this .home ()
156167                    .printTree (printer );
157168            }
158169            printer .outdent ();
@@ -175,39 +186,38 @@ public void printTree(final IndentingPrinter printer) {
175186    // /home/A1/width/200/height/300/navigations/right 400px 
176187    @ Override 
177188    public  UrlFragment  urlFragment () {
178-         UrlFragment  urlFragment  = this .rectangle .urlFragment ();
189+         UrlFragment  urlFragment  = UrlFragment .SLASH .append (
190+             this .home .urlFragment ()
191+         );
179192
180193        final  SpreadsheetViewportNavigationList  navigations  = this .navigations ;
181194        if  (navigations .isNotEmpty ()) {
182-             urlFragment  = urlFragment .appendSlashThen (NAVIGATIONS )
183-                 .appendSlashThen (this .navigations .urlFragment ());
195+             urlFragment  = urlFragment .appendSlashThen (
196+                 this .navigations .urlFragment ()
197+             );
184198        }
185199
186200        return  urlFragment ;
187201    }
188202
189-     final  static  String  NAVIGATIONS_STRING  = "navigations" ;
190- 
191-     private  final  static  UrlFragment  NAVIGATIONS  = UrlFragment .with (NAVIGATIONS_STRING );
192- 
193203    // Object........................................................................................................... 
194204
195205    @ Override 
196206    public  int  hashCode () {
197207        return  Objects .hash (
198-             this .rectangle ,
208+             this .home ,
199209            this .navigations 
200210        );
201211    }
202212
203213    @ Override 
204214    public  boolean  equals (final  Object  other ) {
205215        return  this  == other  ||
206-             other  instanceof  SpreadsheetViewportRectangleNavigationList  && this .equals0 ((SpreadsheetViewportRectangleNavigationList ) other );
216+             other  instanceof  SpreadsheetViewportHomeNavigationList  && this .equals0 ((SpreadsheetViewportHomeNavigationList ) other );
207217    }
208218
209-     private  boolean  equals0 (final  SpreadsheetViewportRectangleNavigationList  other ) {
210-         return  this .rectangle .equals (other .rectangle ) &&
219+     private  boolean  equals0 (final  SpreadsheetViewportHomeNavigationList  other ) {
220+         return  this .home .equals (other .home ) &&
211221            this .navigations .equals (other .navigations );
212222    }
213223
@@ -219,8 +229,7 @@ public String toString() {
219229    @ Override 
220230    public  void  buildToString (final  ToStringBuilder  builder ) {
221231        builder .labelSeparator (": " )
222-             .value (this .rectangle )
223-             .label ("navigations" )
232+             .value (this .home )
224233            .value (this .navigations );
225234    }
226235}
0 commit comments