Example usage for org.joda.time Period Period

List of usage examples for org.joda.time Period Period

Introduction

In this page you can find the example usage for org.joda.time Period Period.

Prototype

public Period(Object period) 

Source Link

Document

Creates a period by converting or copying from another object.

Usage

From source file:il.ac.technion.datacenter.sla.TableSLA.java

@Override
@Requires("old(noise) <= 1.0 && old(noise) >= 0")
public Period addRandomDowntime(double noise) {
    Iterator<Range> iter = new RangeIterator(compensationTable.keySet());
    Range r = iter.next();/*from   w  w  w . j a  v a2s .co m*/
    while (iter.hasNext()) {
        if (coin.nextDouble() >= noise)
            break;
        r = iter.next();
    }
    double downTimePerc = 100.0 - (coin.nextDouble() * r.size + r.left);
    long downtimeInMillis = (long) (PeriodConverter.toMillis(billingPeriod) * (downTimePerc / 100.0));
    Period $ = new Period(downtimeInMillis);
    reportDownTime($);
    return $;
}

From source file:influent.server.utilities.ResultFormatter.java

License:MIT License

public static String formatDur(FL_Duration d) {
    if (d == null)
        return "";

    int t = d.getNumIntervals().intValue();
    if (t == 0)/*from  ww w.  ja  v a  2s .c  o m*/
        return "-";

    ReadablePeriod period = null;
    switch (d.getInterval()) {
    case SECONDS:
        period = Seconds.seconds(t);
        break;
    case HOURS:
        period = Hours.hours(t);
        break;
    case DAYS:
        period = Days.days(t);
        break;
    case WEEKS:
        period = Weeks.weeks(t);
        break;
    case MONTHS:
        period = Months.months(t);
        break;
    case QUARTERS:
        period = Months.months(t * 3);
        break;
    case YEARS:
        period = Years.years(t);
        break;
    }

    PeriodFormatter formatter = new PeriodFormatterBuilder().printZeroAlways().minimumPrintedDigits(2)
            .appendHours().appendSeparator(":").printZeroAlways().minimumPrintedDigits(2).appendMinutes()
            .appendSeparator(":").printZeroAlways().minimumPrintedDigits(2).appendSeconds().toFormatter();
    final String ftime = formatter.print(DateTimeParser.normalize(new Period(period)));

    return ftime;
}

From source file:io.druid.indexing.common.actions.TaskActionTestKit.java

License:Apache License

@Override
public void before() {
    taskStorage = new HeapMemoryTaskStorage(new TaskStorageConfig(new Period("PT24H")));
    taskLockbox = new TaskLockbox(taskStorage);
    testDerbyConnector = new TestDerbyConnector(Suppliers.ofInstance(new MetadataStorageConnectorConfig()),
            Suppliers.ofInstance(metadataStorageTablesConfig));
    metadataStorageCoordinator = new IndexerSQLMetadataStorageCoordinator(new TestUtils().getTestObjectMapper(),
            metadataStorageTablesConfig, testDerbyConnector);
    taskActionToolbox = new TaskActionToolbox(taskLockbox, metadataStorageCoordinator, new NoopServiceEmitter(),
            EasyMock.createMock(SupervisorManager.class));
    testDerbyConnector.createDataSourceTable();
    testDerbyConnector.createPendingSegmentsTable();
    testDerbyConnector.createSegmentTable();
    testDerbyConnector.createRulesTable();
    testDerbyConnector.createConfigTable();
    testDerbyConnector.createTaskTables();
    testDerbyConnector.createAuditTable();
}

From source file:io.druid.indexing.jdbc.supervisor.JDBCSupervisorIOConfig.java

License:Apache License

private static Duration defaultDuration(final Period period, final String theDefault) {
    return (period == null ? new Period(theDefault) : period).toStandardDuration();
}

From source file:io.druid.java.util.common.granularity.GranularityType.java

License:Apache License

GranularityType(final String hiveFormat, final String lowerDefaultFormat, final String defaultFormat,
        final int dateValuePositions, final String period) {
    this.hiveFormat = hiveFormat;
    this.lowerDefaultFormat = lowerDefaultFormat;
    this.defaultFormat = defaultFormat;
    this.dateValuePositions = dateValuePositions;
    this.period = new Period(period);
    this.defaultGranularity = new PeriodGranularity(this.period, null, null);
}

From source file:io.druid.query.expression.ExprUtils.java

License:Apache License

public static PeriodGranularity toPeriodGranularity(final Expr periodArg, final Expr originArg,
        final Expr timeZoneArg, final Expr.ObjectBinding bindings) {
    final Period period = new Period(periodArg.eval(bindings).asString());
    final DateTime origin;
    final DateTimeZone timeZone;

    if (originArg == null) {
        origin = null;/*from  w  w  w.j  av a  2  s.  com*/
    } else {
        final Object value = originArg.eval(bindings).value();
        origin = value != null ? new DateTime(value) : null;
    }

    if (timeZoneArg == null) {
        timeZone = null;
    } else {
        final String value = timeZoneArg.eval(bindings).asString();
        timeZone = value != null ? DateTimeZone.forID(value) : null;
    }

    return new PeriodGranularity(period, origin, timeZone);
}

From source file:io.druid.query.extraction.namespace.JDBCExtractionNamespace.java

License:Apache License

@JsonCreator
public JDBCExtractionNamespace(
        @NotNull @JsonProperty(value = "namespace", required = true) final String namespace,
        @NotNull @JsonProperty(value = "connectorConfig", required = true) final MetadataStorageConnectorConfig connectorConfig,
        @NotNull @JsonProperty(value = "table", required = true) final String table,
        @NotNull @JsonProperty(value = "keyColumn", required = true) final String keyColumn,
        @NotNull @JsonProperty(value = "valueColumn", required = true) final String valueColumn,
        @Nullable @JsonProperty(value = "tsColumn", required = false) final String tsColumn,
        @Min(0) @Nullable @JsonProperty(value = "pollPeriod", required = false) final Period pollPeriod) {
    this.connectorConfig = Preconditions.checkNotNull(connectorConfig, "connectorConfig");
    Preconditions.checkNotNull(connectorConfig.getConnectURI(), "connectorConfig.connectURI");
    this.table = Preconditions.checkNotNull(table, "table");
    this.keyColumn = Preconditions.checkNotNull(keyColumn, "keyColumn");
    this.valueColumn = Preconditions.checkNotNull(valueColumn, "valueColumn");
    this.tsColumn = tsColumn;
    this.namespace = Preconditions.checkNotNull(namespace, "namespace");
    this.pollPeriod = pollPeriod == null ? new Period(0L) : pollPeriod;
}

From source file:io.druid.query.lookup.namespace.JdbcExtractionNamespace.java

License:Apache License

@JsonCreator
public JdbcExtractionNamespace(
        @NotNull @JsonProperty(value = "connectorConfig", required = true) final MetadataStorageConnectorConfig connectorConfig,
        @NotNull @JsonProperty(value = "table", required = true) final String table,
        @NotNull @JsonProperty(value = "keyColumn", required = true) final String keyColumn,
        @NotNull @JsonProperty(value = "valueColumn", required = true) final String valueColumn,
        @Nullable @JsonProperty(value = "tsColumn", required = false) final String tsColumn,
        @Nullable @JsonProperty(value = "filter", required = false) final String filter,
        @Min(0) @Nullable @JsonProperty(value = "pollPeriod", required = false) final Period pollPeriod) {
    this.connectorConfig = Preconditions.checkNotNull(connectorConfig, "connectorConfig");
    Preconditions.checkNotNull(connectorConfig.getConnectURI(), "connectorConfig.connectURI");
    this.table = Preconditions.checkNotNull(table, "table");
    this.keyColumn = Preconditions.checkNotNull(keyColumn, "keyColumn");
    this.valueColumn = Preconditions.checkNotNull(valueColumn, "valueColumn");
    this.tsColumn = tsColumn;
    this.filter = filter;
    this.pollPeriod = pollPeriod == null ? new Period(0L) : pollPeriod;
}

From source file:io.druid.sql.calcite.expression.builtin.TimeFloorOperatorConversion.java

License:Apache License

@Override
public DruidExpression toDruidExpression(final PlannerContext plannerContext, final RowSignature rowSignature,
        final RexNode rexNode) {
    final RexCall call = (RexCall) rexNode;
    final List<RexNode> operands = call.getOperands();
    final List<DruidExpression> druidExpressions = Expressions.toDruidExpressions(plannerContext, rowSignature,
            operands);/*from www .  ja va2s  .c  o  m*/

    if (druidExpressions == null) {
        return null;
    } else if (operands.get(1).isA(SqlKind.LITERAL)
            && (operands.size() <= 2 || operands.get(2).isA(SqlKind.LITERAL))
            && (operands.size() <= 3 || operands.get(3).isA(SqlKind.LITERAL))) {
        // Granularity is a literal. Special case since we can use an extractionFn here.
        final Period period = new Period(RexLiteral.stringValue(operands.get(1)));
        final DateTime origin = operands.size() > 2 && !RexLiteral.isNullLiteral(operands.get(2))
                ? Calcites.calciteDateTimeLiteralToJoda(operands.get(2), plannerContext.getTimeZone())
                : null;
        final DateTimeZone timeZone = operands.size() > 3 && !RexLiteral.isNullLiteral(operands.get(3))
                ? DateTimes.inferTzfromString(RexLiteral.stringValue(operands.get(3)))
                : plannerContext.getTimeZone();
        final PeriodGranularity granularity = new PeriodGranularity(period, origin, timeZone);
        return applyTimestampFloor(druidExpressions.get(0), granularity, plannerContext.getExprMacroTable());
    } else {
        // Granularity is dynamic
        return DruidExpression.fromFunctionCall("timestamp_floor", druidExpressions);
    }
}

From source file:io.druid.sql.calcite.expression.TimeFloorOperatorConversion.java

License:Apache License

@Override
public DruidExpression toDruidExpression(final PlannerContext plannerContext, final RowSignature rowSignature,
        final RexNode rexNode) {
    final RexCall call = (RexCall) rexNode;
    final List<RexNode> operands = call.getOperands();
    final List<DruidExpression> druidExpressions = Expressions.toDruidExpressions(plannerContext, rowSignature,
            operands);/*w  w  w .  j  a  va2  s  .  c  o  m*/

    if (druidExpressions == null) {
        return null;
    } else if (operands.get(1).isA(SqlKind.LITERAL)
            && (operands.size() <= 2 || operands.get(2).isA(SqlKind.LITERAL))
            && (operands.size() <= 3 || operands.get(3).isA(SqlKind.LITERAL))) {
        // Granularity is a literal. Special case since we can use an extractionFn here.
        final Period period = new Period(RexLiteral.stringValue(operands.get(1)));
        final DateTime origin = operands.size() > 2 && !RexLiteral.isNullLiteral(operands.get(2))
                ? Calcites.calciteDateTimeLiteralToJoda(operands.get(2), plannerContext.getTimeZone())
                : null;
        final DateTimeZone timeZone = operands.size() > 3 && !RexLiteral.isNullLiteral(operands.get(3))
                ? DateTimeZone.forID(RexLiteral.stringValue(operands.get(3)))
                : plannerContext.getTimeZone();
        final PeriodGranularity granularity = new PeriodGranularity(period, origin, timeZone);
        return applyTimestampFloor(druidExpressions.get(0), granularity);
    } else {
        // Granularity is dynamic
        return DruidExpression.fromFunctionCall("timestamp_floor", druidExpressions);
    }
}