Java 类org.joda.time.ReadablePeriod 实例源码

项目:azkaban    文件:Schedule.java   
public Schedule(int projectId, String projectName, String flowName,
    String status, long firstSchedTime, DateTimeZone timezone,
    ReadablePeriod period, long lastModifyTime, long nextExecTime,
    long submitTime, String submitUser) {
  this.projectId = projectId;
  this.projectName = projectName;
  this.flowName = flowName;
  this.firstSchedTime = firstSchedTime;
  this.timezone = timezone;
  this.lastModifyTime = lastModifyTime;
  this.period = period;
  this.nextExecTime = nextExecTime;
  this.submitUser = submitUser;
  this.status = status;
  this.submitTime = submitTime;
  this.executionOptions = null;
  this.slaOptions = null;
}
项目:azkaban    文件:Schedule.java   
public Schedule(int projectId, String projectName, String flowName,
    String status, long firstSchedTime, DateTimeZone timezone,
    ReadablePeriod period, long lastModifyTime, long nextExecTime,
    long submitTime, String submitUser, ExecutionOptions executionOptions,
    SlaOptions slaOptions) {
  this.projectId = projectId;
  this.projectName = projectName;
  this.flowName = flowName;
  this.firstSchedTime = firstSchedTime;
  this.timezone = timezone;
  this.lastModifyTime = lastModifyTime;
  this.period = period;
  this.nextExecTime = nextExecTime;
  this.submitUser = submitUser;
  this.status = status;
  this.submitTime = submitTime;
  this.executionOptions = executionOptions;
  this.slaOptions = slaOptions;
}
项目:azkaban    文件:Schedule.java   
private DateTime getNextRuntime(long scheduleTime, DateTimeZone timezone,
    ReadablePeriod period) {
  DateTime now = new DateTime();
  DateTime date = new DateTime(scheduleTime).withZone(timezone);
  int count = 0;
  while (!now.isBefore(date)) {
    if (count > 100000) {
      throw new IllegalStateException(
          "100000 increments of period did not get to present time.");
    }

    if (period == null) {
      break;
    } else {
      date = date.plus(period);
    }

    count += 1;
  }

  return date;
}
项目:azkaban    文件:SLA.java   
@SuppressWarnings("unchecked")
public static SlaSetting fromObject(Object obj) {
  Map<String, Object> slaObj = (HashMap<String, Object>) obj;
  String subId = (String) slaObj.get("id");
  ReadablePeriod dur =
      Schedule.parsePeriodString((String) slaObj.get("duration"));
  // List<String> rulesObj = (ArrayList<String>) slaObj.get("rules");
  // List<SlaRule> slaRules = new ArrayList<SLA.SlaRule>();
  // for(String rule : rulesObj) {
  // slaRules.add(SlaRule.valueOf(rule));
  // }
  SlaRule slaRule = SlaRule.valueOf((String) slaObj.get("rule"));
  List<String> actsObj = (ArrayList<String>) slaObj.get("actions");
  List<SlaAction> slaActs = new ArrayList<SlaAction>();
  for (String act : actsObj) {
    slaActs.add(SlaAction.valueOf(act));
  }

  SlaSetting ret = new SlaSetting();
  ret.setId(subId);
  ret.setDuration(dur);
  ret.setRule(slaRule);
  ret.setActions(slaActs);
  return ret;
}
项目:azkaban    文件:Schedule.java   
public Schedule(int scheduleId, int projectId, String projectName,
    String flowName, String status, long firstSchedTime,
    DateTimeZone timezone, ReadablePeriod period, long lastModifyTime,
    long nextExecTime, long submitTime, String submitUser,
    ExecutionOptions executionOptions, List<SlaOption> slaOptions) {
  this.scheduleId = scheduleId;
  this.projectId = projectId;
  this.projectName = projectName;
  this.flowName = flowName;
  this.firstSchedTime = firstSchedTime;
  this.timezone = timezone;
  this.lastModifyTime = lastModifyTime;
  this.period = period;
  this.nextExecTime = nextExecTime;
  this.submitUser = submitUser;
  this.status = status;
  this.submitTime = submitTime;
  this.executionOptions = executionOptions;
  this.slaOptions = slaOptions;
}
项目:azkaban    文件:Schedule.java   
private DateTime getNextRuntime(long scheduleTime, DateTimeZone timezone,
    ReadablePeriod period) {
  DateTime now = new DateTime();
  DateTime date = new DateTime(scheduleTime).withZone(timezone);
  int count = 0;
  while (!now.isBefore(date)) {
    if (count > 100000) {
      throw new IllegalStateException(
          "100000 increments of period did not get to present time.");
    }

    if (period == null) {
      break;
    } else {
      date = date.plus(period);
    }

    count += 1;
  }

  return date;
}
项目:azkaban    文件:ScheduleManager.java   
public Schedule scheduleFlow(final int scheduleId, final int projectId,
    final String projectName, final String flowName, final String status,
    final long firstSchedTime, final DateTimeZone timezone,
    final ReadablePeriod period, final long lastModifyTime,
    final long nextExecTime, final long submitTime, final String submitUser,
    ExecutionOptions execOptions, List<SlaOption> slaOptions) {
  Schedule sched =
      new Schedule(scheduleId, projectId, projectName, flowName, status,
          firstSchedTime, timezone, period, lastModifyTime, nextExecTime,
          submitTime, submitUser, execOptions, slaOptions);
  logger
      .info("Scheduling flow '" + sched.getScheduleName() + "' for "
          + _dateFormat.print(firstSchedTime) + " with a period of " + period == null ? "(non-recurring)"
          : period);

  insertSchedule(sched);
  return sched;
}
项目:azkaban    文件:BasicTimeChecker.java   
public static BasicTimeChecker createFromJson(HashMap<String, Object> obj)
    throws Exception {
  Map<String, Object> jsonObj = (HashMap<String, Object>) obj;
  if (!jsonObj.get("type").equals(type)) {
    throw new Exception("Cannot create checker of " + type + " from "
        + jsonObj.get("type"));
  }
  Long firstCheckTime = Long.valueOf((String) jsonObj.get("firstCheckTime"));
  String timezoneId = (String) jsonObj.get("timezone");
  long nextCheckTime = Long.valueOf((String) jsonObj.get("nextCheckTime"));
  DateTimeZone timezone = DateTimeZone.forID(timezoneId);
  boolean isRecurring = Boolean.valueOf((String) jsonObj.get("isRecurring"));
  boolean skipPastChecks =
      Boolean.valueOf((String) jsonObj.get("skipPastChecks"));
  ReadablePeriod period =
      Utils.parsePeriodString((String) jsonObj.get("period"));
  String id = (String) jsonObj.get("id");

  BasicTimeChecker checker =
      new BasicTimeChecker(id, firstCheckTime, timezone, nextCheckTime,
          isRecurring, skipPastChecks, period);
  if (skipPastChecks) {
    checker.updateNextCheckTime();
  }
  return checker;
}
项目:warp10-platform    文件:ISODURATION.java   
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
  Object top = stack.pop();

  if (!(top instanceof Long)) {
    throw new WarpScriptException(getName() + " expects a number of time units (LONG) on top of the stack.");
  }

  long duration = ((Number) top).longValue();

  StringBuffer buf = new StringBuffer();
  ReadablePeriod period = new MutablePeriod(duration / Constants.TIME_UNITS_PER_MS);
  ISOPeriodFormat.standard().getPrinter().printTo(buf, period, Locale.US);

  stack.push(buf.toString());

  return stack;
}
项目:fili    文件:BaseTableLoader.java   
/**
 * Build a logical table, supplying it with a name, grain, table group, and metrics.
 * <p>
 * Note: This builds a logical table with all valid metrics for the grain of the table.
 *
 * @param name  The name for this logical table
 * @param granularity  The granularity for this logical table
 * @param category  The category for this logical table
 * @param longName  The long name for this logical table
 * @param retention  The retention for this logical table
 * @param description  The description for this logical table
 * @param group  The group of physical tables for this logical table
 * @param metrics  The dictionary of all metrics
 *
 * @return The logical table built
 *
 * @deprecated The LogicalTable constructor is being mirrored here, can be referenced directly
 */
@Deprecated
public LogicalTable buildLogicalTable(
        String name,
        Granularity granularity,
        String category,
        String longName,
        ReadablePeriod retention,
        String description,
        TableGroup group,
        MetricDictionary metrics
) {
    return new LogicalTable(
            name,
            category,
            longName,
            granularity,
            retention,
            description,
            group,
            metrics
    );
}
项目:fili    文件:LogicalTable.java   
/**
 * Constructor.
 *
 * @param name  The logical table name
 * @param category  The category of the logical table
 * @param longName  The long name of the logical table
 * @param granularity  The logical table time grain
 * @param retention  The period the data in the logical table is retained for
 * @param description  The description for this logical table
 * @param tableGroup  The tablegroup for the logical table
 * @param metricDictionary The metric dictionary to bind tableGroup's metrics
 */
public LogicalTable(
        @NotNull String name,
        String category,
        String longName,
        @NotNull Granularity granularity,
        ReadablePeriod retention,
        String description,
        TableGroup tableGroup,
        MetricDictionary metricDictionary
) {
    this.name = name;
    this.tableGroup = tableGroup;
    this.category = category;
    this.longName = longName;
    this.retention = retention;
    this.description = description;
    this.comparableParam = name + granularity.toString();

    schema = new LogicalTableSchema(tableGroup, granularity, metricDictionary);

}
项目:TinyTravelTracker    文件:BaseSingleFieldPeriod.java   
/**
 * Calculates the number of whole units between the two specified partial datetimes.
 * <p>
 * The two partials must contain the same fields, for example you can specify
 * two <code>LocalDate</code> objects.
 *
 * @param start  the start partial date, validated to not be null
 * @param end  the end partial date, validated to not be null
 * @param zeroInstance  the zero instance constant, must not be null
 * @return the period
 * @throws IllegalArgumentException if the partials are null or invalid
 */
protected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance) {
    if (start == null || end == null) {
        throw new IllegalArgumentException("ReadablePartial objects must not be null");
    }
    if (start.size() != end.size()) {
        throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
    }
    for (int i = 0, isize = start.size(); i < isize; i++) {
        if (start.getFieldType(i) != end.getFieldType(i)) {
            throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
        }
    }
    if (DateTimeUtils.isContiguous(start) == false) {
        throw new IllegalArgumentException("ReadablePartial objects must be contiguous");
    }
    Chronology chrono = DateTimeUtils.getChronology(start.getChronology()).withUTC();
    int[] values = chrono.get(zeroInstance, chrono.set(start, 0L), chrono.set(end, 0L));
    return values[0];
}
项目:TinyTravelTracker    文件:BaseSingleFieldPeriod.java   
/**
 * Creates a new instance representing the number of complete standard length units
 * in the specified period.
 * <p>
 * This factory method converts all fields from the period to hours using standardised
 * durations for each field. Only those fields which have a precise duration in
 * the ISO UTC chronology can be converted.
 * <ul>
 * <li>One week consists of 7 days.
 * <li>One day consists of 24 hours.
 * <li>One hour consists of 60 minutes.
 * <li>One minute consists of 60 seconds.
 * <li>One second consists of 1000 milliseconds.
 * </ul>
 * Months and Years are imprecise and periods containing these values cannot be converted.
 *
 * @param period  the period to get the number of hours from, must not be null
 * @param millisPerUnit  the number of milliseconds in one standard unit of this period
 * @throws IllegalArgumentException if the period contains imprecise duration values
 */
protected static int standardPeriodIn(ReadablePeriod period, long millisPerUnit) {
    if (period == null) {
        return 0;
    }
    Chronology iso = ISOChronology.getInstanceUTC();
    long duration = 0L;
    for (int i = 0; i < period.size(); i++) {
        int value = period.getValue(i);
        if (value != 0) {
            DurationField field = period.getFieldType(i).getField(iso);
            if (field.isPrecise() == false) {
                throw new IllegalArgumentException(
                        "Cannot convert period to duration as " + field.getName() +
                        " is not precise in the period " + period);
            }
            duration = FieldUtils.safeAdd(duration, FieldUtils.safeMultiply(field.getUnitMillis(), value));
        }
    }
    return FieldUtils.safeToInt(duration / millisPerUnit);
}
项目:TinyTravelTracker    文件:BasePeriod.java   
/**
 * Adds the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        if (value != 0) {
            int index = indexOf(type);
            if (index == -1) {
                throw new IllegalArgumentException(
                    "Period does not support field '" + type.getName() + "'");
            } else {
                values[index] = FieldUtils.safeAdd(getValue(index), value);
            }
        }
    }
    return values;
}
项目:TinyTravelTracker    文件:PeriodFormatterBuilder.java   
public int calculatePrintedLength(ReadablePeriod period, Locale locale) {
    PeriodPrinter before = iBeforePrinter;
    PeriodPrinter after = iAfterPrinter;

    int sum = before.calculatePrintedLength(period, locale)
            + after.calculatePrintedLength(period, locale);

    if (iUseBefore) {
        if (before.countFieldsToPrint(period, 1, locale) > 0) {
            if (iUseAfter) {
                int afterCount = after.countFieldsToPrint(period, 2, locale);
                if (afterCount > 0) {
                    sum += (afterCount > 1 ? iText : iFinalText).length();
                }
            } else {
                sum += iText.length();
            }
        }
    } else if (iUseAfter && after.countFieldsToPrint(period, 1, locale) > 0) {
        sum += iText.length();
    }

    return sum;
}
项目:TinyTravelTracker    文件:PeriodFormatterBuilder.java   
public void printTo(StringBuffer buf, ReadablePeriod period, Locale locale) {
    PeriodPrinter before = iBeforePrinter;
    PeriodPrinter after = iAfterPrinter;

    before.printTo(buf, period, locale);
    if (iUseBefore) {
        if (before.countFieldsToPrint(period, 1, locale) > 0) {
            if (iUseAfter) {
                int afterCount = after.countFieldsToPrint(period, 2, locale);
                if (afterCount > 0) {
                    buf.append(afterCount > 1 ? iText : iFinalText);
                }
            } else {
                buf.append(iText);
            }
        }
    } else if (iUseAfter && after.countFieldsToPrint(period, 1, locale) > 0) {
        buf.append(iText);
    }
    after.printTo(buf, period, locale);
}
项目:TinyTravelTracker    文件:PeriodFormatterBuilder.java   
public void printTo(Writer out, ReadablePeriod period, Locale locale) throws IOException {
    PeriodPrinter before = iBeforePrinter;
    PeriodPrinter after = iAfterPrinter;

    before.printTo(out, period, locale);
    if (iUseBefore) {
        if (before.countFieldsToPrint(period, 1, locale) > 0) {
            if (iUseAfter) {
                int afterCount = after.countFieldsToPrint(period, 2, locale);
                if (afterCount > 0) {
                    out.write(afterCount > 1 ? iText : iFinalText);
                }
            } else {
                out.write(iText);
            }
        }
    } else if (iUseAfter && after.countFieldsToPrint(period, 1, locale) > 0) {
        out.write(iText);
    }
    after.printTo(out, period, locale);
}
项目:TinyTravelTracker    文件:BaseChronology.java   
/**
 * Gets the values of a period from an interval.
 *
 * @param period  the period instant to use
 * @param duration  the duration to query
 * @return the values of the period extracted from the duration
 */
public int[] get(ReadablePeriod period, long duration) {
    int size = period.size();
    int[] values = new int[size];
    if (duration != 0) {
        long current = 0;
        for (int i = 0; i < size; i++) {
            DurationField field = period.getFieldType(i).getField(this);
            if (field.isPrecise()) {
                int value = field.getDifference(duration, current);
                current = field.add(current, value);
                values[i] = value;
            }
        }
    }
    return values;
}
项目:azkaban-customization    文件:Schedule.java   
private DateTime getNextRuntime(long scheduleTime, DateTimeZone timezone, ReadablePeriod period) {
    DateTime now = new DateTime();
    DateTime date = new DateTime(scheduleTime).withZone(timezone);
    int count = 0;
    while (!now.isBefore(date)) {
        if (count > 100000) {
            throw new IllegalStateException(
                    "100000 increments of period did not get to present time.");
        }

        if (period == null) {
            break;
        } else {
            date = date.plus(period);
        }

        count += 1;
    }

    return date;
}
项目:azkaban-customization    文件:SLA.java   
@SuppressWarnings("unchecked")
        public static SlaSetting fromObject(Object obj) {
            Map<String, Object> slaObj = (HashMap<String, Object>) obj;
            String subId = (String) slaObj.get("id");
            ReadablePeriod dur = Schedule.parsePeriodString((String) slaObj.get("duration"));
//          List<String> rulesObj = (ArrayList<String>) slaObj.get("rules");
//          List<SlaRule> slaRules = new ArrayList<SLA.SlaRule>();
//          for(String rule : rulesObj) {
//              slaRules.add(SlaRule.valueOf(rule));
//          }
            SlaRule slaRule = SlaRule.valueOf((String) slaObj.get("rule"));
            List<String> actsObj = (ArrayList<String>) slaObj.get("actions");
            List<SlaAction> slaActs = new ArrayList<SlaAction>();
            for(String act : actsObj) {
                slaActs.add(SlaAction.valueOf(act));
            }

            SlaSetting ret = new SlaSetting();
            ret.setId(subId);
            ret.setDuration(dur);
            ret.setRule(slaRule);
            ret.setActions(slaActs);
            return ret;
        }
项目:azkaban-customization    文件:Schedule.java   
private DateTime getNextRuntime(long scheduleTime, DateTimeZone timezone, ReadablePeriod period) {
    DateTime now = new DateTime();
    DateTime date = new DateTime(scheduleTime).withZone(timezone);
    int count = 0;
    while (!now.isBefore(date)) {
        if (count > 100000) {
            throw new IllegalStateException(
                    "100000 increments of period did not get to present time.");
        }

        if (period == null) {
            break;
        } else {
            date = date.plus(period);
        }

        count += 1;
    }

    return date;
}
项目:astor    文件:PeriodFormatterBuilder.java   
public void printTo(StringBuffer buf, ReadablePeriod period, Locale locale) {
    PeriodPrinter before = iBeforePrinter;
    PeriodPrinter after = iAfterPrinter;

    before.printTo(buf, period, locale);
    if (iUseBefore) {
        if (before.countFieldsToPrint(period, 1, locale) > 0) {
            if (iUseAfter) {
                int afterCount = after.countFieldsToPrint(period, 2, locale);
                if (afterCount > 0) {
                    buf.append(afterCount > 1 ? iText : iFinalText);
                }
            } else {
                buf.append(iText);
            }
        }
    } else if (iUseAfter && after.countFieldsToPrint(period, 1, locale) > 0) {
        buf.append(iText);
    }
    after.printTo(buf, period, locale);
}
项目:azkaban-customization    文件:ScheduleManager.java   
public Schedule scheduleFlow(
        final int scheduleId,
        final int projectId,
        final String projectName,
        final String flowName,
        final String status,
        final long firstSchedTime,
        final DateTimeZone timezone,
        final ReadablePeriod period,
        final long lastModifyTime,
        final long nextExecTime,
        final long submitTime,
        final String submitUser
        ) {
    return scheduleFlow(scheduleId, projectId, projectName, flowName, status, firstSchedTime, timezone, period, lastModifyTime, nextExecTime, submitTime, submitUser, null, null, false, Trigger.TRIGGER_RETRIES);
}
项目:azkaban-customization    文件:ScheduleManager.java   
public Schedule scheduleFlow(
        final int scheduleId,
        final int projectId,
        final String projectName,
        final String flowName,
        final String status,
        final long firstSchedTime,
        final DateTimeZone timezone,
        final ReadablePeriod period,
        final long lastModifyTime,
        final long nextExecTime,
        final long submitTime,
        final String submitUser,
        ExecutionOptions execOptions,
        List<SlaOption> slaOptions,
        Boolean retriesCheck,
        int scheduleRetries
        ) {
    Schedule sched = new Schedule(scheduleId, projectId, projectName, flowName, status, firstSchedTime, timezone, period, lastModifyTime, nextExecTime, submitTime, submitUser, execOptions, slaOptions, retriesCheck, scheduleRetries);
    logger.info("Scheduling flow '" + sched.getScheduleName() + "' for "
            + _dateFormat.print(firstSchedTime) + " with a period of "
            + period == null ? "(non-recurring)" : period);

    insertSchedule(sched);
    return sched;
}
项目:azkaban-customization    文件:BasicTimeChecker.java   
public BasicTimeChecker(
        String id,
        long firstCheckTime,
        DateTimeZone timezone,
        boolean isRecurring, 
        boolean skipPastChecks,
        ReadablePeriod period) {
    this.id = id;
    this.firstCheckTime = firstCheckTime;
    this.timezone = timezone;
    this.isRecurring = isRecurring;
    this.skipPastChecks = skipPastChecks;
    this.period = period;
    this.nextCheckTime = firstCheckTime;
    this.nextCheckTime = calculateNextCheckTime();
}
项目:azkaban-customization    文件:BasicTimeChecker.java   
public BasicTimeChecker(
        String id,
        long firstCheckTime,
        DateTimeZone timezone,
        long nextCheckTime,
        boolean isRecurring, 
        boolean skipPastChecks,
        ReadablePeriod period) {
    this.id = id;
    this.firstCheckTime = firstCheckTime;
    this.timezone = timezone;
    this.nextCheckTime = nextCheckTime;
    this.isRecurring = isRecurring;
    this.skipPastChecks = skipPastChecks;
    this.period = period;
}
项目:azkaban-customization    文件:BasicTimeChecker.java   
public static BasicTimeChecker createFromJson(HashMap<String, Object> obj) throws Exception {
    Map<String, Object> jsonObj = (HashMap<String, Object>) obj;
    if(!jsonObj.get("type").equals(type)) {
        throw new Exception("Cannot create checker of " + type + " from " + jsonObj.get("type"));
    }
    Long firstCheckTime = Long.valueOf((String) jsonObj.get("firstCheckTime"));
    String timezoneId = (String) jsonObj.get("timezone");
    long nextCheckTime = Long.valueOf((String) jsonObj.get("nextCheckTime"));
    DateTimeZone timezone = DateTimeZone.forID(timezoneId);
    boolean isRecurring = Boolean.valueOf((String)jsonObj.get("isRecurring"));
    boolean skipPastChecks = Boolean.valueOf((String)jsonObj.get("skipPastChecks"));
    ReadablePeriod period = Utils.parsePeriodString((String)jsonObj.get("period"));
    String id = (String) jsonObj.get("id");

    BasicTimeChecker checker = new BasicTimeChecker(id, firstCheckTime, timezone, nextCheckTime, isRecurring, skipPastChecks, period);
    if(skipPastChecks) {
        checker.updateNextCheckTime();
    }
    return checker;
}
项目:astor    文件:BaseSingleFieldPeriod.java   
/**
 * Calculates the number of whole units between the two specified partial datetimes.
 * <p>
 * The two partials must contain the same fields, for example you can specify
 * two <code>LocalDate</code> objects.
 *
 * @param start  the start partial date, validated to not be null
 * @param end  the end partial date, validated to not be null
 * @param zeroInstance  the zero instance constant, must not be null
 * @return the period
 * @throws IllegalArgumentException if the partials are null or invalid
 */
protected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance) {
    if (start == null || end == null) {
        throw new IllegalArgumentException("ReadablePartial objects must not be null");
    }
    if (start.size() != end.size()) {
        throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
    }
    for (int i = 0, isize = start.size(); i < isize; i++) {
        if (start.getFieldType(i) != end.getFieldType(i)) {
            throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
        }
    }
    if (DateTimeUtils.isContiguous(start) == false) {
        throw new IllegalArgumentException("ReadablePartial objects must be contiguous");
    }
    Chronology chrono = DateTimeUtils.getChronology(start.getChronology()).withUTC();
    int[] values = chrono.get(zeroInstance, chrono.set(start, START_1972), chrono.set(end, START_1972));
    return values[0];
}
项目:astor    文件:TestConverterManager.java   
public void testGetPeriodConverter() {
    PeriodConverter c = ConverterManager.getInstance().getPeriodConverter(new Period(1, 2, 3, 4, 5, 6, 7, 8));
    assertEquals(ReadablePeriod.class, c.getSupportedType());

    c = ConverterManager.getInstance().getPeriodConverter(new Duration(123L));
    assertEquals(ReadableDuration.class, c.getSupportedType());

    c = ConverterManager.getInstance().getPeriodConverter(new Interval(0L, 1000L));
    assertEquals(ReadableInterval.class, c.getSupportedType());

    c = ConverterManager.getInstance().getPeriodConverter("");
    assertEquals(String.class, c.getSupportedType());

    c = ConverterManager.getInstance().getPeriodConverter(null);
    assertEquals(null, c.getSupportedType());

    try {
        ConverterManager.getInstance().getPeriodConverter(Boolean.TRUE);
        fail();
    } catch (IllegalArgumentException ex) {}
}
项目:astor    文件:BaseChronology.java   
/**
 * Gets the values of a period from an interval.
 *
 * @param period  the period instant to use
 * @param duration  the duration to query
 * @return the values of the period extracted from the duration
 */
public int[] get(ReadablePeriod period, long duration) {
    int size = period.size();
    int[] values = new int[size];
    if (duration != 0) {
        long current = 0;
        for (int i = 0; i < size; i++) {
            DurationField field = period.getFieldType(i).getField(this);
            if (field.isPrecise()) {
                int value = field.getDifference(duration, current);
                current = field.add(current, value);
                values[i] = value;
            }
        }
    }
    return values;
}
项目:astor    文件:PeriodFormatterBuilder.java   
public int calculatePrintedLength(ReadablePeriod period, Locale locale) {
    PeriodPrinter before = iBeforePrinter;
    PeriodPrinter after = iAfterPrinter;

    int sum = before.calculatePrintedLength(period, locale)
            + after.calculatePrintedLength(period, locale);

    if (iUseBefore) {
        if (before.countFieldsToPrint(period, 1, locale) > 0) {
            if (iUseAfter) {
                int afterCount = after.countFieldsToPrint(period, 2, locale);
                if (afterCount > 0) {
                    sum += (afterCount > 1 ? iText : iFinalText).length();
                }
            } else {
                sum += iText.length();
            }
        }
    } else if (iUseAfter && after.countFieldsToPrint(period, 1, locale) > 0) {
        sum += iText.length();
    }

    return sum;
}
项目:astor    文件:BasePeriod.java   
/**
 * Adds the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        if (value != 0) {
            int index = indexOf(type);
            if (index == -1) {
                throw new IllegalArgumentException(
                    "Period does not support field '" + type.getName() + "'");
            } else {
                values[index] = FieldUtils.safeAdd(getValue(index), value);
            }
        }
    }
    return values;
}
项目:astor    文件:BaseSingleFieldPeriod.java   
/**
 * Calculates the number of whole units between the two specified partial datetimes.
 * <p>
 * The two partials must contain the same fields, for example you can specify
 * two <code>LocalDate</code> objects.
 *
 * @param start  the start partial date, validated to not be null
 * @param end  the end partial date, validated to not be null
 * @param zeroInstance  the zero instance constant, must not be null
 * @return the period
 * @throws IllegalArgumentException if the partials are null or invalid
 */
protected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance) {
    if (start == null || end == null) {
        throw new IllegalArgumentException("ReadablePartial objects must not be null");
    }
    if (start.size() != end.size()) {
        throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
    }
    for (int i = 0, isize = start.size(); i < isize; i++) {
        if (start.getFieldType(i) != end.getFieldType(i)) {
            throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
        }
    }
    if (DateTimeUtils.isContiguous(start) == false) {
        throw new IllegalArgumentException("ReadablePartial objects must be contiguous");
    }
    Chronology chrono = DateTimeUtils.getChronology(start.getChronology()).withUTC();
    int[] values = chrono.get(zeroInstance, chrono.set(start, 0L), chrono.set(end, 0L));
    return values[0];
}
项目:astor    文件:BaseSingleFieldPeriod.java   
/**
 * Creates a new instance representing the number of complete standard length units
 * in the specified period.
 * <p>
 * This factory method converts all fields from the period to hours using standardised
 * durations for each field. Only those fields which have a precise duration in
 * the ISO UTC chronology can be converted.
 * <ul>
 * <li>One week consists of 7 days.
 * <li>One day consists of 24 hours.
 * <li>One hour consists of 60 minutes.
 * <li>One minute consists of 60 seconds.
 * <li>One second consists of 1000 milliseconds.
 * </ul>
 * Months and Years are imprecise and periods containing these values cannot be converted.
 *
 * @param period  the period to get the number of hours from, must not be null
 * @param millisPerUnit  the number of milliseconds in one standard unit of this period
 * @throws IllegalArgumentException if the period contains imprecise duration values
 */
protected static int standardPeriodIn(ReadablePeriod period, long millisPerUnit) {
    if (period == null) {
        return 0;
    }
    Chronology iso = ISOChronology.getInstanceUTC();
    long duration = 0L;
    for (int i = 0; i < period.size(); i++) {
        int value = period.getValue(i);
        if (value != 0) {
            DurationField field = period.getFieldType(i).getField(iso);
            if (field.isPrecise() == false) {
                throw new IllegalArgumentException(
                        "Cannot convert period to duration as " + field.getName() +
                        " is not precise in the period " + period);
            }
            duration = FieldUtils.safeAdd(duration, FieldUtils.safeMultiply(field.getUnitMillis(), value));
        }
    }
    return FieldUtils.safeToInt(duration / millisPerUnit);
}
项目:unitimes    文件:QueryLog.java   
ChartWindow(String name, String format,
        ReadablePeriod start, int window, ReadablePeriod increment,
        String axeFormat, DateTimeFieldType axeType, int axeMod, int axeValue, int minutes, String base,
        String oracleFormat, String oracleCondition, String mySqlFormat, String mySqlCondition) {
    iName = name;
    iFormat = new SimpleDateFormat(format, Locale.US);
    iStart = start; iWindow = window; iIncrement = increment;
    iAxeFormat = axeFormat; iAxeType = axeType; iAxeMod = axeMod; iAxeValue = axeValue;
    iMinutes = minutes; iBase = base;
    iOracleFormat = oracleFormat; iOracleCondition = oracleCondition;
    iMySqlFormat = mySqlFormat; iMySqlCondition = mySqlCondition;
}
项目:oma-riista-web    文件:TemporaryGameDiaryImagesRemover.java   
@Transactional
public void removeExpiredTemporaryImages(final ReadablePeriod expirationTime) {
    final Date olderThan = DateTime.now().minus(expirationTime).toDate();

    final List<GameDiaryImage> expired = gameDiaryImageRepository.findAll(
            where(SPEC_FOR_IMAGE_NOT_RELATED_TO_ANY_GAME_DIARY_ENTRY)
                    .and(JpaSpecs.creationTimeOlderThan(olderThan)));

    if (expired.size() > 0) {
        LOG.debug("Removing GameDiaryImages ids:" + F.getNonNullIds(expired));
        gameDiaryImageRepository.deleteInBatch(expired);
    }
}
项目:RIT-Dining-Planner-Android    文件:DateUtils.java   
/**
 * Return string describing the time until/elapsed time since 'time' formatted like
 * "[relative time/date], [time]".
 *
 * See {@link android.text.format.DateUtils#getRelativeDateTimeString} for full docs.
 *
 * @throws IllegalArgumentException if using a ReadablePartial without a time component
 * @see #getRelativeDateTimeString(Context, ReadableInstant, ReadablePeriod, int)
 */
public static CharSequence getRelativeDateTimeString(Context context, ReadablePartial time,
                                                     ReadablePeriod transitionResolution, int flags) {
    if (!time.isSupported(DateTimeFieldType.hourOfDay())
        || !time.isSupported(DateTimeFieldType.minuteOfHour())) {
        throw new IllegalArgumentException("getRelativeDateTimeString() must be passed a ReadablePartial that " +
            "supports time, otherwise it makes no sense");
    }

    return getRelativeDateTimeString(context, time.toDateTime(DateTime.now()), transitionResolution, flags);
}
项目:spring-analytics    文件:AggregateCounterController.java   
@Override
protected AggregateCounterResource instantiateResource(AggregateCounter entity) {
    AggregateCounterResource result = new AggregateCounterResource(
            entity.getName());
    ReadablePeriod increment = entity.getResolution().unitPeriod;
    DateTime end = entity.getInterval().getEnd();
    int i = 0;
    for (DateTime when = entity.getInterval().getStart(); !when
            .isAfter(end); when = when.plus(increment)) {
        result.addValue(new Date(when.getMillis()), entity.getCounts()[i++]);
    }
    return result;
}
项目:azkaban    文件:Schedule.java   
public static ReadablePeriod parsePeriodString(String periodStr) {
  ReadablePeriod period;
  char periodUnit = periodStr.charAt(periodStr.length() - 1);
  if (periodUnit == 'n') {
    return null;
  }

  int periodInt =
      Integer.parseInt(periodStr.substring(0, periodStr.length() - 1));
  switch (periodUnit) {
  case 'M':
    period = Months.months(periodInt);
    break;
  case 'w':
    period = Weeks.weeks(periodInt);
    break;
  case 'd':
    period = Days.days(periodInt);
    break;
  case 'h':
    period = Hours.hours(periodInt);
    break;
  case 'm':
    period = Minutes.minutes(periodInt);
    break;
  case 's':
    period = Seconds.seconds(periodInt);
    break;
  default:
    throw new IllegalArgumentException("Invalid schedule period unit '"
        + periodUnit);
  }

  return period;
}
项目:azkaban    文件:Utils.java   
public static ReadablePeriod parsePeriodString(String periodStr) {
  ReadablePeriod period;
  char periodUnit = periodStr.charAt(periodStr.length() - 1);
  if (periodStr.equals("null") || periodUnit == 'n') {
    return null;
  }

  int periodInt =
      Integer.parseInt(periodStr.substring(0, periodStr.length() - 1));
  switch (periodUnit) {
  case 'y':
    period = Years.years(periodInt);
    break;
  case 'M':
    period = Months.months(periodInt);
    break;
  case 'w':
    period = Weeks.weeks(periodInt);
    break;
  case 'd':
    period = Days.days(periodInt);
    break;
  case 'h':
    period = Hours.hours(periodInt);
    break;
  case 'm':
    period = Minutes.minutes(periodInt);
    break;
  case 's':
    period = Seconds.seconds(periodInt);
    break;
  default:
    throw new IllegalArgumentException("Invalid schedule period unit '"
        + periodUnit);
  }

  return period;
}