Example #1
0
 @Override
 public void writeImpl(ByteQueue queue) {
   queue.push(year);
   queue.push(month.getId());
   queue.push((byte) day);
   queue.push(dayOfWeek.getId());
 }
Example #2
0
 //
 // Reading and writing
 //
 public Date(ByteQueue queue) {
   readTag(queue);
   year = queue.popU1B();
   month = Month.valueOf(queue.pop());
   day = queue.popU1B();
   dayOfWeek = DayOfWeek.valueOf(queue.pop());
 }
Example #3
0
 @Override
 public int hashCode() {
   final int PRIME = 31;
   int result = 1;
   result = PRIME * result + day;
   result = PRIME * result + ((dayOfWeek == null) ? 0 : dayOfWeek.hashCode());
   result = PRIME * result + ((month == null) ? 0 : month.hashCode());
   result = PRIME * result + year;
   return result;
 }
Example #4
0
  @Override
  public int compareTo(Date that) {
    if (!isSpecific())
      throw new BACnetRuntimeException(
          "Comparisons can only be made between specific dates: " + this);
    if (!that.isSpecific())
      throw new BACnetRuntimeException(
          "Comparisons can only be made between specific dates: " + that);

    if (year == that.year) {
      if (month == that.month) return day - that.day;
      return month.ordinal() - that.month.ordinal();
    }
    return year - that.year;
  }
Example #5
0
  /**
   * Matches this presumably wildcard date with a (that) necessarily specifically defined date to
   * determine if (true) the given date is one of this' defined dates or (false) not.
   *
   * @param that the specific date with which to compare.
   * @return
   */
  @Override
  public boolean matches(Date that) {
    if (!that.isSpecific())
      throw new BACnetRuntimeException("Dates for matching must be completely specified: " + that);

    if (!matchYear(that.year)) return false;

    if (!month.matches(that.month)) return false;

    if (!matchDay(that)) return false;

    if (!dayOfWeek.matches(that)) return false;

    return true;
  }
Example #6
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   final Date other = (Date) obj;
   if (day != other.day) return false;
   if (dayOfWeek == null) {
     if (other.dayOfWeek != null) return false;
   } else if (!dayOfWeek.equals(other.dayOfWeek)) return false;
   if (month == null) {
     if (other.month != null) return false;
   } else if (!month.equals(other.month)) return false;
   if (year != other.year) return false;
   return true;
 }
Example #7
0
 private void resetTo(GregorianCalendar gc) {
   this.year = gc.get(Calendar.YEAR) - 1900;
   this.month = Month.valueOf((byte) (gc.get(Calendar.MONTH) + 1));
   this.day = gc.get(Calendar.DATE);
   this.dayOfWeek = DayOfWeek.valueOf((byte) (((gc.get(Calendar.DAY_OF_WEEK) + 5) % 7) + 1));
 }
Example #8
0
 /** @return true if the date has been completely specified, false if any fields is unspecified. */
 public boolean isSpecific() {
   if (year == UNSPECIFIED_YEAR) return false;
   if (!month.isSpecific()) return false;
   if (day == UNSPECIFIED_DAY || day == LAST_DAY_OF_MONTH) return false;
   return true;
 }
Example #9
0
 public GregorianCalendar calculateGC() {
   if (!isSpecific())
     throw new BACnetRuntimeException("Date must be completely specified to calculate calendar");
   return new GregorianCalendar(year + 1900, (month.getId() & 0xff) - 1, day, 12, 0);
 }