Java Code Examples for org.joda.time.Period#parse()
The following examples show how to use
org.joda.time.Period#parse() .
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: ParsePeriod.java From super-csv with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} * * @throws SuperCsvCellProcessorException * if value is null or is not a String */ public Object execute(final Object value, final CsvContext context) { validateInputNotNull(value, context); if (!(value instanceof String)) { throw new SuperCsvCellProcessorException(String.class, value, context, this); } final String string = (String) value; final Period result; try { if (formatter != null) { result = Period.parse(string, formatter); } else { result = Period.parse(string); } } catch (IllegalArgumentException e) { throw new SuperCsvCellProcessorException( "Failed to parse value as a Period", context, this, e); } return next.execute(result, context); }
Example 2
Source File: WikipediaExtractor.java From incubator-gobblin with Apache License 2.0 | 6 votes |
private long createLowWatermarkForBootstrap(WorkUnitState state) throws IOException { String bootstrapPeriodString = state.getProp(BOOTSTRAP_PERIOD, DEFAULT_BOOTSTRAP_PERIOD); Period period = Period.parse(bootstrapPeriodString); DateTime startTime = DateTime.now().minus(period); try { Queue<JsonElement> firstRevision = retrievePageRevisions(ImmutableMap.<String, String>builder().putAll(this.baseQuery) .put("rvprop", "ids") .put("titles", this.requestedTitle) .put("rvlimit", "1") .put("rvstart", WIKIPEDIA_TIMESTAMP_FORMAT.print(startTime)) .put("rvdir", "newer") .build()); if (firstRevision.isEmpty()) { throw new IOException("Could not retrieve oldest revision, returned empty revisions list."); } return parseRevision(firstRevision.poll()); } catch (URISyntaxException use) { throw new IOException(use); } }
Example 3
Source File: GatewayConfigImpl.java From knox with Apache License 2.0 | 6 votes |
@Override public long getGatewayDeploymentsBackupAgeLimit() { PeriodFormatter f = new PeriodFormatterBuilder().appendDays().toFormatter(); String s = get( DEPLOYMENTS_BACKUP_AGE_LIMIT, "-1" ); long d; try { Period p = Period.parse( s, f ); d = p.toStandardDuration().getMillis(); if( d < 0 ) { d = -1; } } catch( Exception e ) { d = -1; } return d; }
Example 4
Source File: EwsUtilities.java From ews-java-api with MIT License | 6 votes |
/** * Takes an xs:duration string as defined by the W3 Consortiums * Recommendation "XML Schema Part 2: Datatypes Second Edition", * http://www.w3.org/TR/xmlschema-2/#duration, and converts it into a * System.TimeSpan structure This method uses the following approximations: * 1 year = 365 days 1 month = 30 days Additionally, it only allows for four * decimal points of seconds precision. * * @param xsDuration xs:duration string to convert * @return System.TimeSpan structure */ public static TimeSpan getXSDurationToTimeSpan(String xsDuration) { // TODO: Need to check whether this should be the equivalent or not Matcher m = PATTERN_TIME_SPAN.matcher(xsDuration); boolean negative = false; if (m.find()) { negative = true; } // Removing leading '-' if (negative) { xsDuration = xsDuration.replace("-P", "P"); } Period period = Period.parse(xsDuration, ISOPeriodFormat.standard()); long retval = period.toStandardDuration().getMillis(); if (negative) { retval = -retval; } return new TimeSpan(retval); }
Example 5
Source File: DetectionConfigFormatter.java From incubator-pinot with Apache License 2.0 | 5 votes |
/** * extract the detection granularity for ALGORITHM detector types * @param specs the specs for the ALGORITHM detectors * @return the granularity */ private Optional<TimeGranularity> extractTimeGranularitiesFromAlgorithmSpecs(Map<String, Object> specs, String bucketPeriodFieldName) { String bucketPeriod = String.valueOf(MapUtils.getMap(specs, CONFIGURATION).get(bucketPeriodFieldName)); Period p = Period.parse(bucketPeriod); PeriodType periodType = p.getPeriodType(); if (PeriodType.days().equals(periodType)) { return Optional.of(new TimeGranularity(p.getDays(), TimeUnit.DAYS)); } else if (PeriodType.hours().equals(periodType)) { return Optional.of(new TimeGranularity(p.getHours(), TimeUnit.HOURS)); } else if (PeriodType.minutes().equals(periodType)) { return Optional.of(new TimeGranularity(p.getMinutes(), TimeUnit.MINUTES)); } return Optional.empty(); }
Example 6
Source File: StreamSortWindowHandlerImpl.java From eagle with Apache License 2.0 | 5 votes |
public void prepare(String streamId, StreamSortSpec streamSortSpecSpec, PartitionedEventCollector outputCollector) { this.windowManager = new StreamWindowManagerImpl( Period.parse(streamSortSpecSpec.getWindowPeriod()), streamSortSpecSpec.getWindowMargin(), PartitionedEventTimeOrderingComparator.INSTANCE, outputCollector); this.streamSortSpecSpec = streamSortSpecSpec; this.streamId = streamId; this.outputCollector = outputCollector; }
Example 7
Source File: DefaultHttpClientFactory.java From knox with Apache License 2.0 | 5 votes |
private static long parseTimeout( String s ) { PeriodFormatter f = new PeriodFormatterBuilder() .appendMinutes().appendSuffix("m"," min") .appendSeconds().appendSuffix("s"," sec") .appendMillis().toFormatter(); Period p = Period.parse( s, f ); return p.toStandardDuration().getMillis(); }
Example 8
Source File: Converters.java From activitystreams with Apache License 2.0 | 5 votes |
/** * Method tryParsePeriod. * @param input String * @return Period */ private static Period tryParsePeriod(String input) { try { return Period.parse(input); } catch (Throwable t) { return null; } }
Example 9
Source File: PeriodFormatter.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public Period parse(String text, Locale locale) throws ParseException { return Period.parse(text); }
Example 10
Source File: DurationConstant.java From FROST-Server with GNU Lesser General Public License v3.0 | 4 votes |
public DurationConstant(String value) { super(Period.parse(value)); }
Example 11
Source File: AggregatesUtil.java From graylog-plugin-aggregates with GNU General Public License v3.0 | 4 votes |
public static int timespanToSeconds(String timespan, Calendar cal){ Period period = Period.parse(timespan); Duration duration = period.toDurationFrom(new DateTime(cal.getTime())); return duration.toStandardSeconds().getSeconds(); }
Example 12
Source File: PeriodAdapter.java From nomulus with Apache License 2.0 | 4 votes |
@Nullable @Override public Period unmarshal(@Nullable String periodString) { return isNullOrEmpty(periodString) ? null : Period.parse(periodString); }
Example 13
Source File: UserProfileAggregatorExecutor.java From Eagle with Apache License 2.0 | 4 votes |
@Override public void init() { aggregator = new UserActivityAggregatorImpl(Arrays.asList(cmdFeatures),Period.parse(this.granularity),site,this.safeWindowMs); }
Example 14
Source File: PrimitiveColumnMetadata.java From Bats with Apache License 2.0 | 4 votes |
/** * Converts value in string literal form into Object instance based on {@link MinorType} value. * Returns null in case of error during parsing or unsupported type. * * @param value value in string literal form * @return Object instance */ @Override public Object valueFromString(String value) { if (value == null) { return null; } try { switch (type) { case INT: return Integer.parseInt(value); case BIGINT: return Long.parseLong(value); case FLOAT4: return (double) Float.parseFloat(value); case FLOAT8: return Double.parseDouble(value); case VARDECIMAL: return new BigDecimal(value); case BIT: return BooleanType.fromString(value); case VARCHAR: case VARBINARY: return value; case TIME: return LocalTime.parse(value, dateTimeFormatter()); case DATE: return LocalDate.parse(value, dateTimeFormatter()); case TIMESTAMP: return Instant.parse(value, dateTimeFormatter()); case INTERVAL: case INTERVALDAY: case INTERVALYEAR: return Period.parse(value); default: throw new IllegalArgumentException("Unsupported conversion: " + type.toString()); } } catch (IllegalArgumentException e) { logger.warn("Error while parsing type {} default value {}", type, value, e); throw new IllegalArgumentException(String.format("The string \"%s\" is not valid for type %s", value, type), e); } }
Example 15
Source File: PeriodFormatter.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public Period parse(String text, Locale locale) throws ParseException { return Period.parse(text); }
Example 16
Source File: LocalGatewayConfig.java From hadoop-mini-clusters with Apache License 2.0 | 4 votes |
private static long parseNetworkTimeout(String s) { PeriodFormatter f = (new PeriodFormatterBuilder()).appendMinutes().appendSuffix("m", " min").appendSeconds().appendSuffix("s", " sec").appendMillis().toFormatter(); Period p = Period.parse(s, f); return p.toStandardDuration().getMillis(); }
Example 17
Source File: Adapters.java From activitystreams with Apache License 2.0 | 4 votes |
public Period apply(String v) { return Period.parse(v); }
Example 18
Source File: PeriodFormatter.java From java-technology-stack with MIT License | 4 votes |
@Override public Period parse(String text, Locale locale) throws ParseException { return Period.parse(text); }
Example 19
Source File: AnomalyDetectorWrapper.java From incubator-pinot with Apache License 2.0 | 4 votes |
public AnomalyDetectorWrapper(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) { super(provider, config, startTime, endTime); Preconditions.checkArgument(this.config.getProperties().containsKey(PROP_SUB_ENTITY_NAME)); this.entityName = MapUtils.getString(config.getProperties(), PROP_SUB_ENTITY_NAME); this.metricUrn = MapUtils.getString(config.getProperties(), PROP_METRIC_URN); this.metricEntity = MetricEntity.fromURN(this.metricUrn); this.metric = provider.fetchMetrics(Collections.singleton(this.metricEntity.getId())).get(this.metricEntity.getId()); Preconditions.checkArgument(this.config.getProperties().containsKey(PROP_DETECTOR)); this.detectorName = DetectionUtils.getComponentKey(MapUtils.getString(config.getProperties(), PROP_DETECTOR)); Preconditions.checkArgument(this.config.getComponents().containsKey(this.detectorName)); this.anomalyDetector = (AnomalyDetector) this.config.getComponents().get(this.detectorName); // emulate moving window or now this.isMovingWindowDetection = MapUtils.getBooleanValue(config.getProperties(), PROP_MOVING_WINDOW_DETECTION, false); // delays to wait for data becomes available this.windowDelay = MapUtils.getIntValue(config.getProperties(), PROP_WINDOW_DELAY, 0); // window delay unit this.windowDelayUnit = TimeUnit.valueOf(MapUtils.getString(config.getProperties(), PROP_WINDOW_DELAY_UNIT, "DAYS")); // detection window size this.windowSize = MapUtils.getIntValue(config.getProperties(), PROP_WINDOW_SIZE, 1); // detection window unit this.windowUnit = TimeUnit.valueOf(MapUtils.getString(config.getProperties(), PROP_WINDOW_UNIT, "DAYS")); // run frequency, used to determine moving windows for minute-level detection Map<String, Object> frequency = (Map<String, Object>) MapUtils.getMap(config.getProperties(), PROP_FREQUENCY); this.functionFrequency = new TimeGranularity(MapUtils.getIntValue(frequency, "size", 15), TimeUnit.valueOf(MapUtils.getString(frequency, "unit", "MINUTES"))); MetricConfigDTO metricConfigDTO = this.provider.fetchMetrics(Collections.singletonList(this.metricEntity.getId())).get(this.metricEntity.getId()); this.dataset = this.provider.fetchDatasets(Collections.singletonList(metricConfigDTO.getDataset())) .get(metricConfigDTO.getDataset()); // date time zone for moving windows. use dataset time zone as default this.dateTimeZone = DateTimeZone.forID(MapUtils.getString(config.getProperties(), PROP_TIMEZONE, this.dataset.getTimezone())); String bucketStr = MapUtils.getString(config.getProperties(), PROP_BUCKET_PERIOD); this.bucketPeriod = bucketStr == null ? this.getBucketSizePeriodForDataset() : Period.parse(bucketStr); this.cachingPeriodLookback = config.getProperties().containsKey(PROP_CACHE_PERIOD_LOOKBACK) ? MapUtils.getLong(config.getProperties(), PROP_CACHE_PERIOD_LOOKBACK) : ThirdEyeUtils.getCachingPeriodLookback(this.dataset.bucketTimeGranularity()); speedUpMinuteLevelDetection(); }
Example 20
Source File: PeriodFormatter.java From spring-analysis-note with MIT License | 4 votes |
@Override public Period parse(String text, Locale locale) throws ParseException { return Period.parse(text); }