@Test public void testParsing() { assertNotEquals(new BacnetDate(119, 3, 15, 5), new BacnetDate(119, 3, 15, 6)); assertNotEquals(new BacnetDate(119, 3, 15, 5), new BacnetDate(119, 3, 16, 5)); assertNotEquals(new BacnetDate(119, 3, 15, 5), new BacnetDate(119, 4, 15, 5)); assertNotEquals(new BacnetDate(119, 3, 15, 5), new BacnetDate(118, 3, 15, 5)); testRoundtrip(new BacnetDate(119, 3, 15, 5)); testRoundtrip(new BacnetDate(119, 3, 15, BacnetDate.ANY)); testRoundtrip(new BacnetDate(119, BacnetDate.ANY, 15, BacnetDate.ANY)); testRoundtrip(new BacnetDate(119, 3, BacnetDate.ANY, BacnetDate.ANY)); testRoundtrip(new BacnetDate(BacnetDate.ANY, 3, 15, BacnetDate.ANY)); testRoundtrip(new BacnetDate(BacnetDate.ANY, 3, BacnetDate.ANY, BacnetDate.ANY)); testRoundtrip(new BacnetDate(BacnetDate.ANY, BacnetDate.ANY, 15, BacnetDate.ANY)); testRoundtrip(new BacnetDate(BacnetDate.ANY, BacnetDate.MONTH_EVEN, 15, BacnetDate.ANY)); testRoundtrip(new BacnetDate(BacnetDate.ANY, BacnetDate.MONTH_EVEN, BacnetDate.DAY_OF_MONTH_LAST, BacnetDate.ANY)); testRoundtrip(new BacnetDate(BacnetDate.ANY, BacnetDate.MONTH_ODD, BacnetDate.DAY_OF_MONTH_ODD, BacnetDate.ANY)); testRoundtrip(new BacnetDate(BacnetDate.ANY, BacnetDate.MONTH_ODD, BacnetDate.DAY_OF_MONTH_EVEN, BacnetDate.ANY)); testRoundtrip(new BacnetDate(BacnetDate.ANY, BacnetDate.MONTH_ODD, BacnetDate.DAY_OF_MONTH_LAST, BacnetDate.ANY)); assertEquals(new BacnetDate(BacnetDate.ANY, BacnetDate.ANY, BacnetDate.ANY, BacnetDate.ANY), BacnetDate.parse("*")); }
public static BacnetDate parse(String date) { date = date.toLowerCase(); if (date.equals("any") || date.equals("*")) { return new BacnetDate(ANY, (byte) ANY, (byte) ANY, (byte) ANY); } String[] a = date.split("-"); if (a.length == 0) { throw new IllegalArgumentException(date); } int year; if (a[0].equals("any") || a[0].equals("*")) { year = ANY; } else { try { year = Integer.parseInt(a[0]); if (year > 1900 + 255) { throw new IllegalArgumentException("year out of range in " + date); } if (year == 1900 + 255) { year = ANY; } else { year -= 1900; } } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no year in " + date); } } if (a.length == 1) { return new BacnetDate(year, (byte) ANY, (byte) ANY, (byte) ANY); } byte month; switch (a[1]) { case "any": case "*": month = (byte) ANY; break; case "even": month = MONTH_EVEN; break; case "odd": month = MONTH_ODD; break; default: try { month = (byte) Integer.parseInt(a[1]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no month in " + date); } if (month > 14) { throw new IllegalArgumentException("month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, (byte) ANY, (byte) ANY); } byte dayOfMonth; switch (a[2]) { case "any": case "*": dayOfMonth = (byte) ANY; break; case "even": dayOfMonth = DAY_OF_MONTH_EVEN; break; case "last": dayOfMonth = DAY_OF_MONTH_LAST; break; case "odd": dayOfMonth = DAY_OF_MONTH_ODD; break; default: try { dayOfMonth = (byte) Integer.parseInt(a[2]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of month in " + date); } if (dayOfMonth > 34) { throw new IllegalArgumentException("day of month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, dayOfMonth, (byte) ANY); } byte dayOfWeek; if (a[3].equals("any") || a[3].equals("*")) { dayOfWeek = (byte) ANY; } else { try { dayOfWeek = (byte) Integer.parseInt(a[3]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of week in " + date); } if (dayOfWeek > 7) { throw new IllegalArgumentException("day of week out of range in " + date); } } return new BacnetDate(year, month, dayOfMonth, dayOfWeek); }
BacnetDate { public static BacnetDate parse(String date) { date = date.toLowerCase(); if (date.equals("any") || date.equals("*")) { return new BacnetDate(ANY, (byte) ANY, (byte) ANY, (byte) ANY); } String[] a = date.split("-"); if (a.length == 0) { throw new IllegalArgumentException(date); } int year; if (a[0].equals("any") || a[0].equals("*")) { year = ANY; } else { try { year = Integer.parseInt(a[0]); if (year > 1900 + 255) { throw new IllegalArgumentException("year out of range in " + date); } if (year == 1900 + 255) { year = ANY; } else { year -= 1900; } } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no year in " + date); } } if (a.length == 1) { return new BacnetDate(year, (byte) ANY, (byte) ANY, (byte) ANY); } byte month; switch (a[1]) { case "any": case "*": month = (byte) ANY; break; case "even": month = MONTH_EVEN; break; case "odd": month = MONTH_ODD; break; default: try { month = (byte) Integer.parseInt(a[1]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no month in " + date); } if (month > 14) { throw new IllegalArgumentException("month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, (byte) ANY, (byte) ANY); } byte dayOfMonth; switch (a[2]) { case "any": case "*": dayOfMonth = (byte) ANY; break; case "even": dayOfMonth = DAY_OF_MONTH_EVEN; break; case "last": dayOfMonth = DAY_OF_MONTH_LAST; break; case "odd": dayOfMonth = DAY_OF_MONTH_ODD; break; default: try { dayOfMonth = (byte) Integer.parseInt(a[2]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of month in " + date); } if (dayOfMonth > 34) { throw new IllegalArgumentException("day of month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, dayOfMonth, (byte) ANY); } byte dayOfWeek; if (a[3].equals("any") || a[3].equals("*")) { dayOfWeek = (byte) ANY; } else { try { dayOfWeek = (byte) Integer.parseInt(a[3]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of week in " + date); } if (dayOfWeek > 7) { throw new IllegalArgumentException("day of week out of range in " + date); } } return new BacnetDate(year, month, dayOfMonth, dayOfWeek); } }
BacnetDate { public static BacnetDate parse(String date) { date = date.toLowerCase(); if (date.equals("any") || date.equals("*")) { return new BacnetDate(ANY, (byte) ANY, (byte) ANY, (byte) ANY); } String[] a = date.split("-"); if (a.length == 0) { throw new IllegalArgumentException(date); } int year; if (a[0].equals("any") || a[0].equals("*")) { year = ANY; } else { try { year = Integer.parseInt(a[0]); if (year > 1900 + 255) { throw new IllegalArgumentException("year out of range in " + date); } if (year == 1900 + 255) { year = ANY; } else { year -= 1900; } } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no year in " + date); } } if (a.length == 1) { return new BacnetDate(year, (byte) ANY, (byte) ANY, (byte) ANY); } byte month; switch (a[1]) { case "any": case "*": month = (byte) ANY; break; case "even": month = MONTH_EVEN; break; case "odd": month = MONTH_ODD; break; default: try { month = (byte) Integer.parseInt(a[1]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no month in " + date); } if (month > 14) { throw new IllegalArgumentException("month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, (byte) ANY, (byte) ANY); } byte dayOfMonth; switch (a[2]) { case "any": case "*": dayOfMonth = (byte) ANY; break; case "even": dayOfMonth = DAY_OF_MONTH_EVEN; break; case "last": dayOfMonth = DAY_OF_MONTH_LAST; break; case "odd": dayOfMonth = DAY_OF_MONTH_ODD; break; default: try { dayOfMonth = (byte) Integer.parseInt(a[2]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of month in " + date); } if (dayOfMonth > 34) { throw new IllegalArgumentException("day of month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, dayOfMonth, (byte) ANY); } byte dayOfWeek; if (a[3].equals("any") || a[3].equals("*")) { dayOfWeek = (byte) ANY; } else { try { dayOfWeek = (byte) Integer.parseInt(a[3]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of week in " + date); } if (dayOfWeek > 7) { throw new IllegalArgumentException("day of week out of range in " + date); } } return new BacnetDate(year, month, dayOfMonth, dayOfWeek); } BacnetDate(ByteBuffer contentBuffer);  BacnetDate(int relYear, int month, int dayOfMonth, int dayOfWeek);  BacnetDate(TemporalAccessor date); }
BacnetDate { public static BacnetDate parse(String date) { date = date.toLowerCase(); if (date.equals("any") || date.equals("*")) { return new BacnetDate(ANY, (byte) ANY, (byte) ANY, (byte) ANY); } String[] a = date.split("-"); if (a.length == 0) { throw new IllegalArgumentException(date); } int year; if (a[0].equals("any") || a[0].equals("*")) { year = ANY; } else { try { year = Integer.parseInt(a[0]); if (year > 1900 + 255) { throw new IllegalArgumentException("year out of range in " + date); } if (year == 1900 + 255) { year = ANY; } else { year -= 1900; } } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no year in " + date); } } if (a.length == 1) { return new BacnetDate(year, (byte) ANY, (byte) ANY, (byte) ANY); } byte month; switch (a[1]) { case "any": case "*": month = (byte) ANY; break; case "even": month = MONTH_EVEN; break; case "odd": month = MONTH_ODD; break; default: try { month = (byte) Integer.parseInt(a[1]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no month in " + date); } if (month > 14) { throw new IllegalArgumentException("month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, (byte) ANY, (byte) ANY); } byte dayOfMonth; switch (a[2]) { case "any": case "*": dayOfMonth = (byte) ANY; break; case "even": dayOfMonth = DAY_OF_MONTH_EVEN; break; case "last": dayOfMonth = DAY_OF_MONTH_LAST; break; case "odd": dayOfMonth = DAY_OF_MONTH_ODD; break; default: try { dayOfMonth = (byte) Integer.parseInt(a[2]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of month in " + date); } if (dayOfMonth > 34) { throw new IllegalArgumentException("day of month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, dayOfMonth, (byte) ANY); } byte dayOfWeek; if (a[3].equals("any") || a[3].equals("*")) { dayOfWeek = (byte) ANY; } else { try { dayOfWeek = (byte) Integer.parseInt(a[3]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of week in " + date); } if (dayOfWeek > 7) { throw new IllegalArgumentException("day of week out of range in " + date); } } return new BacnetDate(year, month, dayOfMonth, dayOfWeek); } BacnetDate(ByteBuffer contentBuffer);  BacnetDate(int relYear, int month, int dayOfMonth, int dayOfWeek);  BacnetDate(TemporalAccessor date); int getYear(); byte getMonth(); byte getDayOfMonth(); byte getDayOfWeek(); boolean hasWildcards(); LocalDate toDate(); @Override String toString(); static BacnetDate parse(String date); @Override int hashCode(); @Override boolean equals(Object obj); }
BacnetDate { public static BacnetDate parse(String date) { date = date.toLowerCase(); if (date.equals("any") || date.equals("*")) { return new BacnetDate(ANY, (byte) ANY, (byte) ANY, (byte) ANY); } String[] a = date.split("-"); if (a.length == 0) { throw new IllegalArgumentException(date); } int year; if (a[0].equals("any") || a[0].equals("*")) { year = ANY; } else { try { year = Integer.parseInt(a[0]); if (year > 1900 + 255) { throw new IllegalArgumentException("year out of range in " + date); } if (year == 1900 + 255) { year = ANY; } else { year -= 1900; } } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no year in " + date); } } if (a.length == 1) { return new BacnetDate(year, (byte) ANY, (byte) ANY, (byte) ANY); } byte month; switch (a[1]) { case "any": case "*": month = (byte) ANY; break; case "even": month = MONTH_EVEN; break; case "odd": month = MONTH_ODD; break; default: try { month = (byte) Integer.parseInt(a[1]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no month in " + date); } if (month > 14) { throw new IllegalArgumentException("month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, (byte) ANY, (byte) ANY); } byte dayOfMonth; switch (a[2]) { case "any": case "*": dayOfMonth = (byte) ANY; break; case "even": dayOfMonth = DAY_OF_MONTH_EVEN; break; case "last": dayOfMonth = DAY_OF_MONTH_LAST; break; case "odd": dayOfMonth = DAY_OF_MONTH_ODD; break; default: try { dayOfMonth = (byte) Integer.parseInt(a[2]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of month in " + date); } if (dayOfMonth > 34) { throw new IllegalArgumentException("day of month out of range in " + date); } break; } if (a.length == 3) { return new BacnetDate(year, month, dayOfMonth, (byte) ANY); } byte dayOfWeek; if (a[3].equals("any") || a[3].equals("*")) { dayOfWeek = (byte) ANY; } else { try { dayOfWeek = (byte) Integer.parseInt(a[3]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("no day of week in " + date); } if (dayOfWeek > 7) { throw new IllegalArgumentException("day of week out of range in " + date); } } return new BacnetDate(year, month, dayOfMonth, dayOfWeek); } BacnetDate(ByteBuffer contentBuffer);  BacnetDate(int relYear, int month, int dayOfMonth, int dayOfWeek);  BacnetDate(TemporalAccessor date); int getYear(); byte getMonth(); byte getDayOfMonth(); byte getDayOfWeek(); boolean hasWildcards(); LocalDate toDate(); @Override String toString(); static BacnetDate parse(String date); @Override int hashCode(); @Override boolean equals(Object obj); static final int ANY; static final byte MONTH_ODD; static final byte MONTH_EVEN; static final byte DAY_OF_MONTH_LAST; static final byte DAY_OF_MONTH_ODD; static final byte DAY_OF_MONTH_EVEN; }