public void getInfo(PrintWriter pw) throws Exception { if( dateSource instanceof SerializableToInfo ){ SerializableToInfo infoSource = (SerializableToInfo)dateSource; infoSource.printInfo(pw); } }
public TreeNodeOngoing(int clusterId, long min, long mid) throws Exception { this.clusterId = clusterId; this.interval = new TimeInterval(min, (NowReference)null); this.mid = mid; }
public TimeInterval getIntersection(TimeInterval interval, NowReference now) throws Exception { if( !this.intersectsWith(interval, now) ){ return null; }; if( this.isIncludedIn(interval, now) ) { return this; } else if(interval.isIncludedIn(this, now)) { return interval; } else { long min = this.min; long max = this.getMax(now); if( min < interval.min ){ min = interval.min; }; if( max > interval.getMax(now) ){ max = interval.max; }; return new TimeInterval(min,max); } }
public TreeNodeRegular(int clusterId, TimeInterval interval) throws Exception { this.clusterId = clusterId; this.interval = interval; if( interval.isOngoing() ) { throw new Exception("Must be providing a regular time interval"); } else { this.mid = (long)(interval.getMin() + interval.getMax(null)) / (long)2; } }
public JSONObject getDocIdsFromInterval(TimeInterval interval) throws Exception { NowReference now = NowReference.now(); DateSource.SearchResults searchResults = dateSource.getDateIntervalsIntersectingWith(interval, now); List<DocumentWithInterval> docWithInts = searchResults.documentWithIntervals; Set<String> docIds = new HashSet<String>(); for(DocumentWithInterval docWithInt : docWithInts){ docIds.add(docWithInt.getDocId()); } JSONObject result = new JSONObject(); JSONArray arr = new JSONArray(); for(String docId : docIds){ arr.put(docId); } result.put("docIds", arr); result.put("clusterCount", searchResults.clusterCount); result.put("intervalCount", searchResults.intervalCount); result.put("intervalMatched", searchResults.intervalMatched); return result; }
@Override public void extendTo(TimeInterval interval) throws Exception { this.interval = this.interval.extendTo(interval); }
public long getMax(NowReference now) throws Exception { if( ongoing ){ if( null == now ){ throw new Exception("Must provide now reference to access now interval max"); } return now.getTime(); } return max; }
public void getDotInfo(PrintWriter pw) throws Exception { if( dateSource instanceof SerializableToDot ){ SerializableToDot dotSource = (SerializableToDot)dateSource; dotSource.printDot(pw); } } }
static public NowReference now(){ long nowTime = (new Date()).getTime(); return new NowReference(nowTime); }
@Override public void run() { logger.info("Start date worker thread"); boolean done = false; do { synchronized(this) { done = isShuttingDown; } if( false == done ) { activity(); } } while( false == done ); logger.info("Submission date thread exiting"); }
public TreeNodeRegular(int clusterId, long min, long max, long mid) throws Exception { this.clusterId = clusterId; this.interval = new TimeInterval(min, max); this.mid = mid; }
@Override public void extendTo(TimeInterval interval) throws Exception { this.interval = this.interval.extendTo(interval); }
public TimeInterval(long min, NowReference now) throws Exception { if( null != now ) { if( now.getTime() < min ){ throw new Exception("Interval bounded by now can not be created with min greater than now reference"); } } this.min = min; this.max = min; this.ongoing = true; }
static public TimeInterval fromJson(JSONObject jsonInterval) throws Exception { TimeInterval timeInterval = null; boolean ongoing = jsonInterval.optBoolean("ongoing", false); long min = jsonInterval.getLong("min"); if( ongoing ){ timeInterval = new TimeInterval(min, (NowReference)null); } else { long max = jsonInterval.getLong("max"); timeInterval = new TimeInterval(min, max); } return timeInterval; }
public long getSize(NowReference now) throws Exception { return getMax(now)-min; }
public DateStructureElement(JSONObject dateStructure) throws Exception{ this.dateStructure = dateStructure; long min = dateStructure.getLong("min"); boolean ongoing = dateStructure.optBoolean("ongoing",false); if( ongoing ){ this.interval = new TimeInterval(min, (NowReference)null); } else { long max = dateStructure.getLong("max"); this.interval = new TimeInterval(min, max); } int clusterId = dateStructure.optInt("index", -1); if( clusterId >= 0 ){ this.clusterId = clusterId; } }