@Override
 public Temporal adjustInto(Temporal temporal) {
   DayOfWeek dow = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));
   int dayToAdd = 1;
   if (dow == DayOfWeek.FRIDAY) dayToAdd = 3;
   if (dow == DayOfWeek.SATURDAY) dayToAdd = 2;
   return temporal.plus(dayToAdd, ChronoUnit.DAYS);
 }
Example #2
0
        @Override
        public long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive) {
          if (temporal1Inclusive.getClass() != temporal2Exclusive.getClass()) {
            return temporal1Inclusive.until(temporal2Exclusive, this);
          }

          return temporal1Inclusive.until(temporal2Exclusive, MINUTES) / 15;
        }
Example #3
0
 /**
  * Subtracts this period from the specified temporal object.
  *
  * <p>This returns a temporal object of the same observable type as the input with this period
  * subtracted.
  *
  * <p>In most cases, it is clearer to reverse the calling pattern by using {@link
  * Temporal#minus(TemporalAmount)}.
  *
  * <pre>
  *   // these two lines are equivalent, but the second approach is recommended
  *   dateTime = thisPeriod.subtractFrom(dateTime);
  *   dateTime = dateTime.minus(thisPeriod);
  * </pre>
  *
  * <p>The calculation will subtract the years, then months, then days. Only non-zero amounts will
  * be subtracted. If the date-time has a calendar system with a fixed number of months in a year,
  * then the years and months will be combined before being subtracted.
  *
  * <p>This instance is immutable and unaffected by this method call.
  *
  * @param temporal the temporal object to adjust, not null
  * @return an object of the same type with the adjustment made, not null
  * @throws DateTimeException if unable to subtract
  * @throws ArithmeticException if numeric overflow occurs
  */
 @Override
 public Temporal subtractFrom(Temporal temporal) {
   Objects.requireNonNull(temporal, "temporal");
   if ((years | months) != 0) {
     long monthRange = monthRange(temporal);
     if (monthRange >= 0) {
       temporal = temporal.minus(years * monthRange + months, MONTHS);
     } else {
       if (years != 0) {
         temporal = temporal.minus(years, YEARS);
       }
       if (months != 0) {
         temporal = temporal.minus(months, MONTHS);
       }
     }
   }
   if (days != 0) {
     temporal = temporal.minus(days, DAYS);
   }
   return temporal;
 }
  @Override
  public void log(
      Temporal t,
      LogicalDateTime d,
      LogLevels level,
      Object obj,
      String function,
      String message,
      Object... args) {

    try {
      fw.write(
          String.format(
              t.toString() + sep + d + sep + level + sep + obj + sep + function + sep + message,
              args));
      fw.write("\n");
      fw.flush();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #5
0
 /**
  * Adjusts the specified temporal object to have this day-of-week.
  *
  * <p>This returns a temporal object of the same observable type as the input with the day-of-week
  * changed to be the same as this.
  *
  * <p>The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} passing
  * {@link ChronoField#DAY_OF_WEEK} as the field. Note that this adjusts forwards or backwards
  * within a Monday to Sunday week. See {@link WeekFields#dayOfWeek} for localized week start days.
  * See {@code TemporalAdjuster} for other adjusters with more control, such as {@code
  * next(MONDAY)}.
  *
  * <p>In most cases, it is clearer to reverse the calling pattern by using {@link
  * Temporal#with(TemporalAdjuster)}:
  *
  * <pre>
  *   // these two lines are equivalent, but the second approach is recommended
  *   temporal = thisDayOfWeek.adjustInto(temporal);
  *   temporal = temporal.with(thisDayOfWeek);
  * </pre>
  *
  * <p>For example, given a date that is a Wednesday, the following are output:
  *
  * <pre>
  *   dateOnWed.with(MONDAY);     // two days earlier
  *   dateOnWed.with(TUESDAY);    // one day earlier
  *   dateOnWed.with(WEDNESDAY);  // same date
  *   dateOnWed.with(THURSDAY);   // one day later
  *   dateOnWed.with(FRIDAY);     // two days later
  *   dateOnWed.with(SATURDAY);   // three days later
  *   dateOnWed.with(SUNDAY);     // four days later
  * </pre>
  *
  * <p>This instance is immutable and unaffected by this method call.
  *
  * @param temporal the target object to be adjusted, not null
  * @return the adjusted object, not null
  * @throws DateTimeException if unable to make the adjustment
  * @throws ArithmeticException if numeric overflow occurs
  */
 @Override
 public Temporal adjustInto(Temporal temporal) {
   return temporal.with(DAY_OF_WEEK, getValue());
 }
  @Override
  public void log(
      ScenarioId scenarioId,
      Temporal t,
      LogicalDateTime d,
      LogLevels level,
      Object obj,
      String function,
      String message,
      Object... args) {
    if (!level.equals(LogLevels.data)) {
      StackTraceElement el = Thread.currentThread().getStackTrace()[8];
      String elTxt = "(" + el.getFileName() + ":" + el.getLineNumber() + ")>" + el.getMethodName();

      ps.printf(message, args);
      String[] s;
      if (d == null) {
        if (obj != null)
          s =
              new String[] {
                scenarioId.getScenarioId(),
                Long.toString(scenarioId.getRepliqueNumber()),
                t.toString(),
                "",
                level.toString(),
                obj.toString(),
                elTxt,
                baos.toString()
              };
        else
          s =
              new String[] {
                scenarioId.getScenarioId(),
                Long.toString(scenarioId.getRepliqueNumber()),
                t.toString(),
                "",
                level.toString(),
                "",
                elTxt,
                baos.toString()
              };
      } else {
        if (obj != null)
          s =
              new String[] {
                scenarioId.getScenarioId(),
                Long.toString(scenarioId.getRepliqueNumber()),
                t.toString(),
                d.toString(),
                level.toString(),
                obj.toString(),
                elTxt,
                baos.toString()
              };
        else
          s =
              new String[] {
                scenarioId.getScenarioId(),
                Long.toString(scenarioId.getRepliqueNumber()),
                t.toString(),
                d.toString(),
                level.toString(),
                "",
                elTxt,
                baos.toString()
              };
      }
      baos.reset();

      Logs l = new Logs(s);
      createRowFrom(l);
    } else {
      if (IRecordable.class.isAssignableFrom(obj.getClass())) {
        DataLogs dl =
            new DataLogs(scenarioId, t.toString(), d.toString(), obj.toString(), (IRecordable) obj);
        createRowFrom(dl);
      }
    }
  }
 @Override
 public Temporal fromTargetValue(Temporal existingValue, Long value) {
   existingValue.with(_temporalField, value);
   return existingValue;
 }
 @Override
 public Long toTargetValue(Temporal fieldValue) {
   return fieldValue.getLong(_temporalField);
 }