Java Code Examples for java.util.concurrent.TimeUnit#equals()

The following examples show how to use java.util.concurrent.TimeUnit#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpectMaxExecutionTimeAnnotationFormatter.java    From quickperf with Apache License 2.0 6 votes vote down vote up
private TreeMap<TimeUnit, Long> buildTimeValueByUnit(ExpectMaxExecutionTime annotation, SortedSet<TimeUnit> unitsToDisplay) {
    TreeMap<TimeUnit, Long> valuesByTimeUnit = new TreeMap<>();
    for (TimeUnit unitToDisplay : unitsToDisplay) {
        if(unitToDisplay.equals(TimeUnit.HOURS)) {
            valuesByTimeUnit.put(TimeUnit.HOURS, (long) annotation.hours());
        } else if(unitToDisplay.equals(TimeUnit.MINUTES)) {
            valuesByTimeUnit.put(TimeUnit.MINUTES, (long) annotation.minutes());
        } else if(unitToDisplay.equals(TimeUnit.SECONDS)) {
            valuesByTimeUnit.put(TimeUnit.SECONDS, (long) annotation.seconds());
        } else if(unitToDisplay.equals(TimeUnit.MILLISECONDS)) {
            valuesByTimeUnit.put(TimeUnit.MILLISECONDS, (long) annotation.milliSeconds());
        } else if(unitToDisplay.equals(TimeUnit.MICROSECONDS)) {
            valuesByTimeUnit.put(TimeUnit.MICROSECONDS, annotation.microSeconds());
        } else if(unitToDisplay.equals(TimeUnit.NANOSECONDS)) {
            valuesByTimeUnit.put(TimeUnit.NANOSECONDS, annotation.nanoSeconds());
        }
    }
    return valuesByTimeUnit;
}
 
Example 2
Source File: InternalDataSerializer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a <code>TimeUnit</code> to a <code>DataOutput</code>.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 *
 * @see #readTimeUnit
 */
public static void writeTimeUnit(TimeUnit unit, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  if (DEBUG) {
    logger.info(LocalizedStrings.DEBUG, "Writing TimeUnit: " + unit);
  }

  if (unit.equals(TimeUnit.NANOSECONDS)) {
    out.writeByte(TIME_UNIT_NANOSECONDS);

  } else if (unit.equals(TimeUnit.MICROSECONDS)) {
    out.writeByte(TIME_UNIT_MICROSECONDS);

  } else if (unit.equals(TimeUnit.MILLISECONDS)) {
    out.writeByte(TIME_UNIT_MILLISECONDS);

  } else if (unit.equals(TimeUnit.SECONDS)) {
    out.writeByte(TIME_UNIT_SECONDS);

  } else {
    throw new InternalGemFireException(LocalizedStrings.DataSerializer_UNSUPPORTED_TIMEUNIT_0.toLocalizedString(unit));
  }
}
 
Example 3
Source File: InternalDataSerializer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a <code>TimeUnit</code> to a <code>DataOutput</code>.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 *
 * @see #readTimeUnit
 */
public static void writeTimeUnit(TimeUnit unit, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  if (DEBUG) {
    logger.info(LocalizedStrings.DEBUG, "Writing TimeUnit: " + unit);
  }

  if (unit.equals(TimeUnit.NANOSECONDS)) {
    out.writeByte(TIME_UNIT_NANOSECONDS);

  } else if (unit.equals(TimeUnit.MICROSECONDS)) {
    out.writeByte(TIME_UNIT_MICROSECONDS);

  } else if (unit.equals(TimeUnit.MILLISECONDS)) {
    out.writeByte(TIME_UNIT_MILLISECONDS);

  } else if (unit.equals(TimeUnit.SECONDS)) {
    out.writeByte(TIME_UNIT_SECONDS);

  } else {
    throw new InternalGemFireException(LocalizedStrings.DataSerializer_UNSUPPORTED_TIMEUNIT_0.toLocalizedString(unit));
  }
}
 
Example 4
Source File: AnomalyDetectorWrapper.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * round this time to earlier boundary, depending on granularity of dataset
 * e.g. 12:15pm on HOURLY dataset should be treated as 12pm
 * any dataset with granularity finer than HOUR, will be rounded as per function frequency (assumption is that this is in MINUTES)
 * so 12.53 on 5 MINUTES dataset, with function frequency 15 MINUTES will be rounded to 12.45
 * See also {@link DetectionJobSchedulerUtils#getBoundaryAlignedTimeForDataset(DateTime, TimeUnit)}
 */
private long getBoundaryAlignedTimeForDataset(DateTime currentTime) {
  TimeSpec timeSpec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(dataset);
  TimeUnit dataUnit = timeSpec.getDataGranularity().getUnit();

  // For nMINUTE level datasets, with frequency defined in nMINUTES in the function, (make sure size doesnt exceed 30 minutes, just use 1 HOUR in that case)
  // Calculate time periods according to the function frequency
  if (dataUnit.equals(TimeUnit.MINUTES) || dataUnit.equals(TimeUnit.MILLISECONDS) || dataUnit.equals(
      TimeUnit.SECONDS)) {
    if (functionFrequency.getUnit().equals(TimeUnit.MINUTES) && (functionFrequency.getSize() <= 30)) {
      int minuteBucketSize = functionFrequency.getSize();
      int roundedMinutes = (currentTime.getMinuteOfHour() / minuteBucketSize) * minuteBucketSize;
      currentTime = currentTime.withTime(currentTime.getHourOfDay(), roundedMinutes, 0, 0);
    } else {
      currentTime = DetectionJobSchedulerUtils.getBoundaryAlignedTimeForDataset(currentTime,
          TimeUnit.HOURS); // default to HOURS
    }
  } else {
    currentTime = DetectionJobSchedulerUtils.getBoundaryAlignedTimeForDataset(currentTime, dataUnit);
  }

  return currentTime.getMillis();
}
 
Example 5
Source File: DetectionJobSchedulerUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * round this time to earlier boundary, depending on granularity of dataset
 * e.g. 12:15pm on HOURLY dataset should be treated as 12pm
 * any dataset with granularity finer than HOUR, will be rounded as per function frequency (assumption is that this is in MINUTES)
 * so 12.53 on 5 MINUTES dataset, with function frequency 15 MINUTES will be rounded to 12.45
 * @param anomalyFunction
 * @return
 */
public static long getBoundaryAlignedTimeForDataset(DatasetConfigDTO datasetConfig, DateTime dateTime,
    AnomalyFunctionDTO anomalyFunction) {
  TimeSpec timeSpec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
  TimeUnit dataUnit = timeSpec.getDataGranularity().getUnit();
  TimeGranularity functionFrequency = anomalyFunction.getFrequency();

  // For nMINUTE level datasets, with frequency defined in nMINUTES in the function, (make sure size doesnt exceed 30 minutes, just use 1 HOUR in that case)
  // Calculate time periods according to the function frequency
  if (dataUnit.equals(TimeUnit.MINUTES) || dataUnit.equals(TimeUnit.MILLISECONDS) || dataUnit.equals(TimeUnit.SECONDS)) {
    if (functionFrequency.getUnit().equals(TimeUnit.MINUTES) && (functionFrequency.getSize() <=30)) {
      int minuteBucketSize = functionFrequency.getSize();
      int roundedMinutes = (dateTime.getMinuteOfHour()/minuteBucketSize) * minuteBucketSize;
      dateTime = dateTime.withTime(dateTime.getHourOfDay(), roundedMinutes, 0, 0);
    } else {
      dateTime = getBoundaryAlignedTimeForDataset(dateTime, TimeUnit.HOURS); // default to HOURS
    }
  } else {
    dateTime = getBoundaryAlignedTimeForDataset(dateTime, dataUnit);
  }

  return dateTime.getMillis();
}
 
Example 6
Source File: TokenGenerator.java    From aws-photosharing-example with Apache License 2.0 5 votes vote down vote up
public boolean validateToken(String token, Integer loginTime, TimeUnit timeUnit) {
    try {
        String key = jasypt.decrypt(token);

        String [] keyParts = key.split("\\|");
        String strDate = keyParts[keyParts.length - 1];
        Date date = format.parse(strDate);

        Date currentTime = new Date();

        long duration = currentTime.getTime() - date.getTime();
        long diff;

        if (timeUnit.equals(TimeUnit.MINUTES))
            diff = TimeUnit.MILLISECONDS.toMinutes(duration);
        else if (timeUnit.equals(TimeUnit.SECONDS))
            diff = TimeUnit.MILLISECONDS.toSeconds(duration);
        else
            throw new UnsupportedOperationException(timeUnit.toString() + " not supported");

        if (diff > loginTime)
            return false;

        return true;
    }

    catch (Exception exc) {
        exc.printStackTrace();

        return false;
    }
}
 
Example 7
Source File: AnomaliesResource.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Get formatted date time for anomaly chart
 * @param timestamp
 * @param datasetConfig
 * @return
 */
private String getFormattedDateTime(long timestamp, DatasetConfigDTO datasetConfig) {
  TimeSpec timeSpec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
  TimeUnit dataGranularityUnit = timeSpec.getDataGranularity().getUnit();
  String formattedDateTime = null;
  if (dataGranularityUnit.equals(TimeUnit.MINUTES) || dataGranularityUnit.equals(TimeUnit.HOURS)) {
    formattedDateTime = startEndDateFormatterHours.print(timestamp);
  } else if (dataGranularityUnit.equals(TimeUnit.DAYS)) {
    formattedDateTime = startEndDateFormatterDays.print(timestamp);
  }
  return formattedDateTime;
}
 
Example 8
Source File: TestExclusiveConditions.java    From huntbugs with Apache License 2.0 4 votes vote down vote up
@AssertWarning("AndEqualsAlwaysFalse")
public void testEnum(TimeUnit tu) {
    if(tu.equals(TimeUnit.DAYS) && tu == TimeUnit.HOURS) {
        System.out.println("Never!");
    }
}
 
Example 9
Source File: ElasticSearchBulkMetaTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public boolean validateTestObject( TimeUnit testObject, Object actual ) {
  return testObject.equals( (TimeUnit) actual );
}
 
Example 10
Source File: PrettyTime.java    From Time4A with Apache License 2.0 3 votes vote down vote up
private String getEmptyRelativeString(TimeUnit precision) {

        UnitPatterns patterns = UnitPatterns.of(this.locale);

        if (precision.equals(TimeUnit.DAYS)) {
            String replacement = patterns.getTodayWord();

            if (!replacement.isEmpty()) {
                return replacement;
            }
        }

        return patterns.getNowWord();

    }