List of usage examples for org.joda.time Interval parse
public static Interval parse(String str)
From source file:candlelight.joda.converters.JodaIntervalConverter.java
License:Apache License
public Interval convertToEntityAttribute(String string) { return Interval.parse(string); }
From source file:com.ibm.common.activitystreams.util.Converters.java
License:Apache License
/** * Method tryParseInterval./*from w w w.ja va 2 s .c o m*/ * @param input String * @return Interval */ private static Interval tryParseInterval(String input) { try { return Interval.parse(input); } catch (Throwable t) { return null; } }
From source file:com.netflix.fenzo.triggers.IntervalTrigger.java
License:Apache License
/** * Creates an interval based trigger/*from w ww . j a va 2s .c o m*/ * @param iso8601Interval - See https://en.wikipedia.org/wiki/ISO_8601 for how to specify intervals with start time/end * time/interval * @param repeatCount - repeat count after first trigger. Specify -1 to repeat indefinitely * @param name * @param data * @param dataType * @param action */ @JsonCreator public IntervalTrigger(@JsonProperty("iso8601Interval") String iso8601Interval, @JsonProperty("repeatCount") int repeatCount, @JsonProperty("name") String name, @JsonProperty("data") T data, @JsonProperty("dataType") Class<T> dataType, @JsonProperty("action") Class<? extends Action1<T>> action) { super(name, data, dataType, action, Interval.parse(iso8601Interval).getStart().toDate(), null); final Interval jodaInterval = Interval.parse(iso8601Interval); this.repeatCount = repeatCount; // -1 is repeat indefinitely this.repeatInterval = Interval.parse(iso8601Interval).getEndMillis() - jodaInterval.getStartMillis(); }
From source file:com.netflix.fenzo.triggers.TriggerUtils.java
License:Apache License
public static boolean isValidISO8601Interval(String iso8601Interval) { try {/*from ww w .ja va2 s . c o m*/ Interval.parse(iso8601Interval); return true; } catch (Exception e) { return false; } }
From source file:com.netflix.fenzo.triggers.TriggerUtils.java
License:Apache License
public static void validateISO8601Interval(String iso8601Interval) { try {//from w ww .j a v a 2s. c o m Interval.parse(iso8601Interval); } catch (Exception e) { throw new IllegalArgumentException(e.getMessage()); } }
From source file:com.studium.joda.converters.JodaIntervalConverter.java
License:Apache License
public Interval convertToEntityAttribute(String string) { return string == null ? null : Interval.parse(string); }
From source file:com.yahoo.bard.webservice.metadata.SegmentMetadata.java
License:Apache License
/** * Create a map of dimension and metric intervals from a map of intervals to dimensions and metrics. * * @param queryResult The java mapped data objects built directly from the Segment Metadata endpoint JSON *///from w ww . jav a 2s . co m public SegmentMetadata(Map<String, Map<String, List<String>>> queryResult) { Map<String, Set<Interval>> tempDimensionIntervals = new HashMap<>(); Map<String, Set<Interval>> tempMetricIntervals = new HashMap<>(); for (Map.Entry<String, Map<String, List<String>>> intervalColumns : queryResult.entrySet()) { Interval interval = Interval.parse(intervalColumns.getKey()); // Store dimensions in pivoted map intervalColumns.getValue().get("dimensions").forEach(column -> tempDimensionIntervals .computeIfAbsent(column, k -> new LinkedHashSet<>()).add(interval)); // Store metrics in pivoted map intervalColumns.getValue().get("metrics").forEach(column -> tempMetricIntervals .computeIfAbsent(column, k -> new LinkedHashSet<>()).add(interval)); } // Stitch the intervals together for (Map.Entry<String, Set<Interval>> entry : tempDimensionIntervals.entrySet()) { tempDimensionIntervals.put(entry.getKey(), DateTimeUtils.mergeIntervalSet(entry.getValue())); } for (Map.Entry<String, Set<Interval>> entry : tempMetricIntervals.entrySet()) { tempMetricIntervals.put(entry.getKey(), DateTimeUtils.mergeIntervalSet(entry.getValue())); } dimensionIntervals = ImmutableMap.copyOf(tempDimensionIntervals); metricIntervals = ImmutableMap.copyOf(tempMetricIntervals); isEmpty = dimensionIntervals.isEmpty() && metricIntervals.isEmpty(); }
From source file:de.fraunhofer.iosb.ilt.sta.model.ext.TimeInterval.java
License:Open Source License
public static TimeInterval parse(String value) { return new TimeInterval(Interval.parse(value)); }
From source file:de.fraunhofer.iosb.ilt.sta.query.expression.constant.IntervalConstant.java
License:Open Source License
public IntervalConstant(String value) { super(Interval.parse(value)); }
From source file:dk.dma.ais.store.FileExportRest.java
License:Apache License
/** {@inheritDoc} */ @Override/*from w w w . j a va 2 s. c om*/ protected void run(Injector injector) throws Exception { printAisStoreNL("AIS STORE COMMAND LINE TOOL INITIATED"); printAisStoreLine(); // Hardcoded values // interval = "2015-1-5T14:00:00Z/2015-1-5T14:10:00Z"; // java -jar ais-store-cli-0.3-SNAPSHOT.jar export -area 15,-18,-10,14 -filter // "m.country=DNK & t.pos within bbox(15,-18,-10,14) & (t.lat<-0.3|t.lat>0.3) & (t.lon<-0.3|t.lon>0.3)" -fetchSize 30000 // -interval // java -jar ais-store-cli-0.3-SNAPSHOT.jar export -area 15,-18,-10,14 -filter // "m.country=DNK & t.pos within bbox(15,-18,-10,14) & (t.lat<-0.3|t.lat>0.3) & (t.lon<-0.3|t.lon>0.3)" -fetchSize 30000 // -interval 2015-1-5T14:00:00Z/2015-1-5T14:10:00Z // Create request String request = ""; if (interval == null || interval.equals("")) { printAisStoreNL("No Interval provided, please check your request."); // return; terminateAndPrintHelp(); } try { intervalVar = Interval.parse(interval); } catch (Exception e) { printAisStoreNL("Invalid Interval provided, please check your request."); terminateAndPrintHelp(); } // intervalVar = DateTimeUtil.toInterval(intervalStr); intervalStartTime = intervalVar.getStartMillis(); String intervalStr = interval.toString(); request = request + "?interval=" + interval; // System.out.println("Interval parsed correct " + intervalStr); // Check if interval is valid, throw exception etc // Create task for exception throwing if args are required // If error, throw exception of error description then -help if (mmsis.size() > 0) { request = request + "&mmsi="; for (int i = 0; i < mmsis.size() - 1; i++) { request = request + Integer.toString(mmsis.get(i)) + ","; } request = request + mmsis.get(mmsis.size() - 1); } // filter // Google URL Encoder // "t.name like H* & t.name like HAMLET" // CHeck if url filter is valid, then url encode it and add to request // filter = "t.name like H* & t.name like HAMLET"; // filter = "s.country in (DNK)"; if (filter != null && !filter.equals("")) { String encodedFilter = URLEncoder.encode(filter, "UTF-8"); try { AisPacketFilters.parseExpressionFilter(filter); } catch (Exception e) { printAisStoreNL("Invalid filter expression"); terminateAndPrintHelp(); } request = request + "&filter=" + encodedFilter; } // area // "&box=lat1,lon1,lat2,lon2" // blabla check if valid if (area != null && !area.equals("")) { request = request + "&box=" + area; } // If table, make sure column is added if ((columns == null || columns.equals("")) && (outputFormat.equals("table") || outputFormat.equals("jsonObject"))) { printAisStoreNL("When using outputFormat " + outputFormat + ", columns are required"); terminateAndPrintHelp(); } try { sink = AisPacketOutputSinks.getOutputSink(outputFormat, columns, separator); request = request + "&outputFormat=" + outputFormat; } catch (Exception e) { printAisStoreNL("Invalid output format provided, " + outputFormat + ", please check your request."); terminateAndPrintHelp(); } // if table do shit // columns \/ REQUIRED // "columns=mmsi;time;timestamp" // Check if valid // Split on ";" // "columns=<listElement0>:list1" if (columns != null) { request = request + "&columns=" + columns; } // seperator // "seperator=\t" // Url encode and add if (separator != null || !separator.equals("")) { String encodedSeparator = URLEncoder.encode(separator, "UTF-8"); request = request + "&seperator=" + encodedSeparator; } // fetchSize if (fetchSize != -1) { request = request + "&fetchsize=" + fetchSize; } // Get path from request, if none it will store in root of ais store client // filePath = "C:\\AisStoreData\\"; if (filePath == null) { filePath = ""; } else { filePath = filePath + "/"; } // No filename provided, generate unique based on request parameters if (fileName == null || fileName.equals("")) { MessageDigest md5 = MessageDigest.getInstance("MD5"); String hex = (new HexBinaryAdapter()).marshal(md5.digest(request.getBytes())); fileName = hex; } // Generate unique hashsum based on request metaFileName = fileName + ".aisstore"; // boolean isTryResume = true; // If we are trying to resume, don't override previous file try { fileOutputStream = new FileOutputStream(filePath + fileName, !forceDownload); } catch (Exception e) { printAisStoreNL("Error occuring writing to disk, make sure the folder path exists "); terminateAndPrintHelp(); } outputStream = new BufferedOutputStream(fileOutputStream); // Should we resume anything // We have read the file // If the file exists that means a previous transaction has been done // Do we resume, if we do, we need to find the resume point ie move the start interval /** * System.out.println("Test Compare"); System.out.println(intervalStr); * * DateTime time = new DateTime(interval.getStartMillis(), DateTimeZone.UTC); DateTime time2 = new * DateTime(interval.getEndMillis(), DateTimeZone.UTC); * * String newIntervalStr = dateTimeFormatter.withZoneUTC().print(time) + "/" + dateTimeFormatter.withZoneUTC().print(time2); * System.out.println(newIntervalStr); // DateTime dateTime = * dateTimeFormatter.parseDateTime("15-Oct-2013 11:34:26 AM").withZone(DateTimeZone.UTC); * * // System.out.println(dateTime); * * // Interval var = Interval.parse(intervalStr); // String dateStr = formatter.withZone(DateTimeZone.UTC).print(dateTime1); * // * * System.exit(0); **/ printAisStoreNL("Request generation complete."); printAisStoreNL("AIS Data will be saved to " + filePath + fileName); // System.out.println("--------------------------------------------------------------------------------"); // We are resuming, insert a Carriage Return Line Feed if (!forceDownload) { // Load the meta data in readMeta(); // We have processed some packages already if (packageCount != 0) { String str = "\r\n"; outputStream.write(str.getBytes()); printAisStoreLine(); printAisStoreNL("Resume detected - Updating Request"); // System.out.println("From " + intervalStr); // Update intervalStr DateTime time = new DateTime(lastLoadedTimestamp, DateTimeZone.UTC); DateTime time2 = new DateTime(intervalVar.getEndMillis(), DateTimeZone.UTC); intervalStr = dateTimeFormatter.withZoneUTC().print(time) + "/" + dateTimeFormatter.withZoneUTC().print(time2); // System.out.println("To " + intervalStr); printAisStoreLine(); // System.out.println("The last stored timestamp was \n" + lastLoadedTimestamp); // Interval interval2 = DateTimeUtil.toInterval(intervalStr); // System.out.println(interval2.getStartMillis()); } else { writeMetaInit(intervalVar.getStartMillis()); lastLoadedTimestamp = intervalVar.getStartMillis(); } } else { // We are starting a new request, create a new meta init writeMetaInit(intervalVar.getStartMillis()); lastLoadedTimestamp = intervalVar.getStartMillis(); } // System.out.println("Interval Str is " + intervalStr); // System.exit(0); // Initialize counter = new AtomicLong(packageCount); // Do we need to set a new interval start based on the meta data read? DefaultHttpClient httpClient = new DefaultHttpClient(); HttpHost target = new HttpHost("ais2.e-navigation.net", 443, "https"); request = "/aisview/rest/store/query" + request; HttpGet getRequest = new HttpGet(request); // HttpGet getRequest = new // HttpGet("/aisview/rest/store/query?interval=2015-1-1T10:00:00Z/2015-2-1T10:10:00Z&box=65.145,-5.373,34.450,76.893"); // + "&mmsi=219230000" // + "&mmsi=219230000" printAisStoreNL("Executing request to " + target); printAisStoreNL("Request is: " + request); HttpResponse httpResponse = httpClient.execute(target, getRequest); HttpEntity entity = httpResponse.getEntity(); // Check we have an OK from server etc. printAisStoreLine(); boolean terminateFailure = false; StatusLine reply = httpResponse.getStatusLine(); switch (reply.getStatusCode()) { case HttpStatus.SC_OK: printAisStoreNL("Server Accepted Connection, download will begin shortly"); printAisStoreLine(); break; default: printAisStoreNL("An error occured establishing connection to the server. "); printAisStoreNL( "Server returned Status Code " + reply.getStatusCode() + " with " + reply.getReasonPhrase()); terminateFailure = true; break; } if (terminateFailure) { return; } // System.out.println("Got reply " + reply.getReasonPhrase() + " status code " + reply.getStatusCode()); // String httpServerReply = httpResponse.getStatusLine(); // System.out.println(httpResponse.getStatusLine()); // // Header[] headers = httpResponse.getAllHeaders(); // for (int i = 0; i < headers.length; i++) { // System.out.println(headers[i]); // } // Do we use the footer? AisReader aisReader; if (entity != null) { InputStream inputStream = entity.getContent(); aisReader = aisReadWriter(inputStream); aisReader.start(); aisReader.join(); // Write the remainder still stored in buffer, update the final meta data with the finished data writeMetaUpdate(currentTimeStamp, counter.get()); // Write the footer sink.footer(outputStream, counter.get()); // Closer and flush the buffer outputStream.flush(); outputStream.close(); // Close and flush the file stream fileOutputStream.flush(); fileOutputStream.close(); } // print a new line to move on from previous /r printAisStoreNL( "Downloading AIS Data 100% Estimated Time Left: 00:00:00 "); printAisStoreLine(); printAisStoreNL("DOWNLOAD SUCCESS"); printAisStoreLine(); // We know current time long currentTime = System.currentTimeMillis(); // How long have we been running long millis = currentTime - timeStart; String timeLeftStr = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))); printAisStoreNL("Total Time " + timeLeftStr); printAisStoreNL("Finished at: " + new Date()); printAisStoreNL("Messages recieved " + counter); // printAisStore("Query took " + timeLeftStr); }