Esempio n. 1
0
 /**
  * Get the first date attribute found as a string. If none are found return an empty string.
  *
  * @return the date string.
  */
 public String getDate() {
   for (final GedObject gedObject : getAttributes()) {
     if (!(gedObject instanceof Date)) {
       continue;
     }
     final Date attr = (Date) gedObject;
     if (!attr.getDate().isEmpty()) {
       return attr.getDate();
     }
   }
   return "";
 }
Esempio n. 2
0
 public void draw() {
   int i;
   System.out.printf("ID:%d,Date:%d/%d/%d", ID, day.getYear(), day.getMonth(), day.getDate());
   System.out.println();
   System.out.print("Number:");
   for (i = 0; i < 6; i++) {
     System.out.printf("%d ", num[i]);
   }
   System.out.println();
 }
Esempio n. 3
0
  public static Timestamp valueOf(String s) {
    String[] components = s.split(" ");
    if (components.length != 2) {
      throw new IllegalArgumentException("Invalid escape format: " + s);
    }

    String[] timeComponents = components[1].split("\\.");
    boolean hasNanos = true;
    int nanos = 0;

    if (timeComponents.length == 1) {
      // Allow timestamps without .fffffffff nanoseconds field
      hasNanos = false;
    } else if (timeComponents.length != 2) {
      throw new IllegalArgumentException("Invalid escape format: " + s);
    }

    Date d = Date.valueOf(components[0]);
    Time t = Time.valueOf(timeComponents[0]);
    if (hasNanos) {
      String nanosString = timeComponents[1];
      int len = nanosString.length();
      assert len > 0; // len must be > 0 if hasNanos is true
      if (len > 9) {
        throw new IllegalArgumentException("Invalid escape format: " + s);
      }

      // Pad zeros on the right up to a total of 9 digits
      if (len < 9) {
        nanosString += "00000000".substring(len - 1);
      }

      try {
        nanos = Integer.valueOf(nanosString);
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Invalid escape format: " + s);
      }
    }

    return new Timestamp(
        d.getYear(),
        d.getMonth(),
        d.getDate(),
        t.getHours(),
        t.getMinutes(),
        t.getSeconds(),
        nanos);
  }