11/*
2- * Copyright (c) 2014, 2020 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2014, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -164,7 +164,8 @@ private void load(List<Path> files) throws IOException {
164164 }
165165 continue ;
166166 }
167- if (line .startsWith ("Zone" )) { // parse Zone line
167+ int token0len = tokens .length > 0 ? tokens [0 ].length () : line .length ();
168+ if (line .regionMatches (true , 0 , "Zone" , 0 , token0len )) { // parse Zone line
168169 String name = tokens [1 ];
169170 if (excludedZones .contains (name )){
170171 continue ;
@@ -182,13 +183,13 @@ private void load(List<Path> files) throws IOException {
182183 if (zLine .parse (tokens , 2 )) {
183184 openZone = null ;
184185 }
185- } else if (line .startsWith ( "Rule" )) { // parse Rule line
186+ } else if (line .regionMatches ( true , 0 , "Rule" , 0 , token0len )) { // parse Rule line
186187 String name = tokens [1 ];
187188 if (!rules .containsKey (name )) {
188189 rules .put (name , new ArrayList <RuleLine >(10 ));
189190 }
190191 rules .get (name ).add (new RuleLine ().parse (tokens ));
191- } else if (line .startsWith ( "Link" )) { // parse link line
192+ } else if (line .regionMatches ( true , 0 , "Link" , 0 , token0len )) { // parse link line
192193 if (tokens .length >= 3 ) {
193194 String realId = tokens [1 ];
194195 String aliasId = tokens [2 ];
@@ -304,7 +305,7 @@ private void parse(String[] tokens, int off) {
304305 month = parseMonth (tokens [off ++]);
305306 if (off < tokens .length ) {
306307 String dayRule = tokens [off ++];
307- if (dayRule .startsWith ( "last" )) {
308+ if (dayRule .regionMatches ( true , 0 , "last" , 0 , 4 )) {
308309 dayOfMonth = -1 ;
309310 dayOfWeek = parseDayOfWeek (dayRule .substring (4 ));
310311 adjustForwards = false ;
@@ -355,42 +356,45 @@ private void parse(String[] tokens, int off) {
355356 }
356357
357358 int parseYear (String year , int defaultYear ) {
358- switch (year .toLowerCase ()) {
359- case "min" : return 1900 ;
360- case "max" : return Year .MAX_VALUE ;
361- case "only" : return defaultYear ;
362- }
359+ int len = year .length ();
360+
361+ if (year .regionMatches (true , 0 , "minimum" , 0 , len )) return 1900 ;
362+ if (year .regionMatches (true , 0 , "maximum" , 0 , len )) return Year .MAX_VALUE ;
363+ if (year .regionMatches (true , 0 , "only" , 0 , len )) return defaultYear ;
364+
363365 return Integer .parseInt (year );
364366 }
365367
366368 Month parseMonth (String mon ) {
367- switch (mon ) {
368- case "Jan" : return Month .JANUARY ;
369- case "Feb" : return Month .FEBRUARY ;
370- case "Mar" : return Month .MARCH ;
371- case "Apr" : return Month .APRIL ;
372- case "May" : return Month .MAY ;
373- case "Jun" : return Month .JUNE ;
374- case "Jul" : return Month .JULY ;
375- case "Aug" : return Month .AUGUST ;
376- case "Sep" : return Month .SEPTEMBER ;
377- case "Oct" : return Month .OCTOBER ;
378- case "Nov" : return Month .NOVEMBER ;
379- case "Dec" : return Month .DECEMBER ;
380- }
369+ int len = mon .length ();
370+
371+ if (mon .regionMatches (true , 0 , "January" , 0 , len )) return Month .JANUARY ;
372+ if (mon .regionMatches (true , 0 , "February" , 0 , len )) return Month .FEBRUARY ;
373+ if (mon .regionMatches (true , 0 , "March" , 0 , len )) return Month .MARCH ;
374+ if (mon .regionMatches (true , 0 , "April" , 0 , len )) return Month .APRIL ;
375+ if (mon .regionMatches (true , 0 , "May" , 0 , len )) return Month .MAY ;
376+ if (mon .regionMatches (true , 0 , "June" , 0 , len )) return Month .JUNE ;
377+ if (mon .regionMatches (true , 0 , "July" , 0 , len )) return Month .JULY ;
378+ if (mon .regionMatches (true , 0 , "August" , 0 , len )) return Month .AUGUST ;
379+ if (mon .regionMatches (true , 0 , "September" , 0 , len )) return Month .SEPTEMBER ;
380+ if (mon .regionMatches (true , 0 , "October" , 0 , len )) return Month .OCTOBER ;
381+ if (mon .regionMatches (true , 0 , "November" , 0 , len )) return Month .NOVEMBER ;
382+ if (mon .regionMatches (true , 0 , "December" , 0 , len )) return Month .DECEMBER ;
383+
381384 throw new IllegalArgumentException ("Unknown month: " + mon );
382385 }
383386
384387 DayOfWeek parseDayOfWeek (String dow ) {
385- switch (dow ) {
386- case "Mon" : return DayOfWeek .MONDAY ;
387- case "Tue" : return DayOfWeek .TUESDAY ;
388- case "Wed" : return DayOfWeek .WEDNESDAY ;
389- case "Thu" : return DayOfWeek .THURSDAY ;
390- case "Fri" : return DayOfWeek .FRIDAY ;
391- case "Sat" : return DayOfWeek .SATURDAY ;
392- case "Sun" : return DayOfWeek .SUNDAY ;
393- }
388+ int len = dow .length ();
389+
390+ if (dow .regionMatches (true , 0 , "Monday" , 0 , len )) return DayOfWeek .MONDAY ;
391+ if (dow .regionMatches (true , 0 , "Tuesday" , 0 , len )) return DayOfWeek .TUESDAY ;
392+ if (dow .regionMatches (true , 0 , "Wednesday" , 0 , len )) return DayOfWeek .WEDNESDAY ;
393+ if (dow .regionMatches (true , 0 , "Thursday" , 0 , len )) return DayOfWeek .THURSDAY ;
394+ if (dow .regionMatches (true , 0 , "Friday" , 0 , len )) return DayOfWeek .FRIDAY ;
395+ if (dow .regionMatches (true , 0 , "Saturday" , 0 , len )) return DayOfWeek .SATURDAY ;
396+ if (dow .regionMatches (true , 0 , "Sunday" , 0 , len )) return DayOfWeek .SUNDAY ;
397+
394398 throw new IllegalArgumentException ("Unknown day-of-week: " + dow );
395399 }
396400
0 commit comments