Example usage for org.joda.time Interval getStart

List of usage examples for org.joda.time Interval getStart

Introduction

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

Prototype

public DateTime getStart() 

Source Link

Document

Gets the start of this time interval, which is inclusive, as a DateTime.

Usage

From source file:de.hpi.bpmn2_0.animation.AnimationJSONBuilder.java

License:Open Source License

protected JSONArray parseSequenceAnalysis() throws JSONException {
    JSONArray jsonSequences = new JSONArray();
    JSONObject jsonObject;/* w ww  .j a v a  2  s .  c o  m*/

    if (this.animations.size() >= 2) {
        Map<String, Map<Interval, Integer>> log1Map = TimeUtilities
                .aggregateIntervalMap(this.animations.get(0).getIntervalMap());
        Map<String, Map<Interval, Integer>> log2Map = TimeUtilities
                .aggregateIntervalMap(this.animations.get(1).getIntervalMap());
        Map<Interval, Integer> compare;
        for (String sequenceId : log1Map.keySet()) {
            if (log2Map.containsKey(sequenceId)) {
                compare = TimeUtilities.compareIntervalMaps(log1Map.get(sequenceId), log2Map.get(sequenceId));
                for (Interval interval : compare.keySet()) {
                    if (Math.abs(compare.get(interval)) > params.getSequenceTokenDiffThreshold()) {
                        jsonObject = new JSONObject();
                        jsonObject.put("sequenceId", sequenceId);
                        jsonObject.put("from", this.getEngineTime(interval.getStart()));
                        jsonObject.put("to", this.getEngineTime(interval.getEnd()));
                        jsonSequences.put(jsonObject);
                    }
                }
            }
        }
    }

    return jsonSequences;
}

From source file:de.hpi.bpmn2_0.replay.AnimationLog.java

License:Open Source License

public Map<String, SortedSet<Interval>> getIntervalMap() {
    Map<String, SortedSet<Interval>> sequenceByIds = new HashMap();

    SortedSet<Interval> transfers;

    for (ReplayTrace trace : traceMap.values()) {
        for (SequenceFlow seqFlow : trace.getSequenceFlows()) {
            if (!sequenceByIds.containsKey(seqFlow.getId())) {
                transfers = new TreeSet<>(new Comparator<Interval>() {
                    @Override/*from w w  w . j  a  v  a  2  s .  com*/
                    public int compare(Interval o1, Interval o2) {
                        if (o1.getStart().isBefore(o2.getStart())) {
                            return -1;
                        } else {
                            return +1;
                        }
                    }
                });
                sequenceByIds.put(seqFlow.getId(), transfers);
            }
            //LOGGER.info("Node1:" + seqFlow.getSourceRef().getName() + " id:" + seqFlow.getSourceRef().getId() + 
            //            "Node2:" + seqFlow.getTargetRef().getName() + " id:" + seqFlow.getTargetRef().getId());
            sequenceByIds.get(seqFlow.getId()).add(TimeUtilities.getInterval(seqFlow));
        }
    }
    return sequenceByIds;
}

From source file:de.hpi.bpmn2_0.replay.IntervalStartComparator.java

License:Open Source License

@Override
public int compare(Interval x, Interval y) {
    return x.getStart().compareTo(y.getStart());
}

From source file:de.hpi.bpmn2_0.replay.TimeUtilities.java

License:Open Source License

private static Map<Interval, Integer> aggregateIntervals(SortedSet<Interval> intervals) {
    SortedSet<DateTime> timeline = new TreeSet<>(new Comparator<DateTime>() {
        @Override/*from  w w w .ja v a2s .c  om*/
        public int compare(DateTime o1, DateTime o2) {
            if (o1.isBefore(o2)) {
                return -1;
            } else {
                return +1;
            }
        }
    });

    //-----------------------------------------------------
    //First, create an ordered timeline based on intervals
    //The date milestone on the timeline is the start and end date of each interval
    //Note: if two datetime are equal, two duplicate elements are on the timeline
    //-----------------------------------------------------        
    Set<DateTime> starts = new HashSet();
    Set<DateTime> ends = new HashSet();
    for (Interval interval : intervals) {
        timeline.add(interval.getStart()); //added datetime will be arranged in timing order
        starts.add(interval.getStart());
        timeline.add(interval.getEnd());
        ends.add(interval.getEnd());
    }

    //------------------------------------------------
    //Then, traverse the timeline to count tokens
    //current-next traverses every interval on the timeline formed by two 
    //consecutive datetime points
    //------------------------------------------------
    DateTime current = null;
    DateTime next = null;
    Iterator<DateTime> iterator = timeline.iterator();
    int intervalCount = 0;
    Map<Interval, Integer> intervalCountMap = new HashMap();

    while (iterator.hasNext()) {
        if (current == null) {
            current = iterator.next();
        } else {
            current = next;
        }

        if (iterator.hasNext()) {
            next = iterator.next();

            if (starts.contains(current)) {
                intervalCount++;
            }
            if (ends.contains(current)) {
                intervalCount--;
            }

            if (current.isBefore(next)) {
                intervalCountMap.put(new Interval(current, next), intervalCount);
            }
        }
    }

    return intervalCountMap;
}

From source file:de.hpi.bpmn2_0.replay.TimeUtilities.java

License:Open Source License

public static Map<Interval, Integer> compareIntervalMaps(Map<Interval, Integer> map1,
        Map<Interval, Integer> map2) {

    Map<Interval, Integer> resultMap = new HashMap();
    SortedSet<DateTime> timeline = new TreeSet<>(new Comparator<DateTime>() {
        @Override/*from   w  w  w .  j  ava  2  s.  c  o m*/
        public int compare(DateTime o1, DateTime o2) {
            if (o1.isBefore(o2)) {
                return -1;
            } else if (o1.isEqual(o2)) { //if two points are the same, only one is added
                return 0;
            } else {
                return +1;
            }
        }
    });

    //-------------------------------------------
    // Put all start and end points of all intervals on a timeline
    // Note: if two points of time are the same, only one is kept on timeline
    //-------------------------------------------
    for (Interval interval : map1.keySet()) {
        timeline.add(interval.getStart()); //added datetime will be arranged in timing order
        timeline.add(interval.getEnd());
    }
    for (Interval interval : map2.keySet()) {
        timeline.add(interval.getStart());
        timeline.add(interval.getEnd());
    }

    //----------------------------------------------
    //Traverse the timeline and compare intervals of map1,map2
    //current-next traverses every interval on the timeline formed 
    //by two consecutive datetime points
    //----------------------------------------------
    DateTime current = null;
    DateTime next = null;
    Interval timelineInterval;
    Iterator<DateTime> iterator = timeline.iterator();
    while (iterator.hasNext()) {
        if (current == null) {
            current = iterator.next();
        } else {
            current = next;
        }

        if (iterator.hasNext()) {
            next = iterator.next();
            if (current.isBefore(next)) {
                timelineInterval = new Interval(current, next);
                resultMap.put(timelineInterval,
                        getIntervalCount(timelineInterval, map1) - getIntervalCount(timelineInterval, map2));
            }
        }
    }
    return resultMap;
}

From source file:de.ifgi.fmt.mongo.conv.IntervalConverter.java

License:Open Source License

/**
 * //from   w  w  w.  j  a va 2  s .  c o  m
 * @param value
 * @param optionalExtraInfo
 * @return
 */
@Override
public Object encode(Object value, MappedField optionalExtraInfo) {
    if (value == null)
        return null;
    Interval i = (Interval) value;
    DBObject dbo = new BasicDBObject();
    dbo.put("start", i.getStart().getMillis());
    dbo.put("end", i.getEnd().getMillis());
    return dbo;
}

From source file:de.topobyte.joda.utils.MonthSpan.java

License:Open Source License

public Interval toInterval() {
    Interval m1 = limitLower.toInterval();
    Interval m2 = limitUpper.toInterval();
    return new Interval(m1.getStart(), m2.getStart());
}

From source file:dk.nsi.sdm4.ydelse.relation.model.SSR.java

License:Open Source License

public SSR withTreatmentIntervalIgnoringMillis(Interval admittedInterval) {
    if (admittedInterval == null) {
        throw new IllegalArgumentException("Admitted interval must be non-null.");
    }/*from w  w w.  j ava  2s . c om*/

    DateTime start = admittedInterval.getStart().minusMillis(admittedInterval.getStart().getMillisOfSecond());
    DateTime end = admittedInterval.getEnd().minusMillis(admittedInterval.getEnd().getMillisOfSecond());
    admittedInterval = new Interval(start, end);

    SSR ssr = new SSR(this);
    ssr.admittedInterval = admittedInterval;
    return ssr;
}

From source file:edu.illinois.cs.cogcomp.temporal.normalizer.main.timex2interval.Period.java

License:Open Source License

/**
 * This function deals with a period of time with format the xxth day/month, etc
 * @param start the anchor time//from   ww w.  j  ava 2s .c om
 * @param temporalPhrase
  * @return
  */
public static TimexChunk Periodrule(DateTime start, TemporalPhrase temporalPhrase) {

    int year;
    DateTime finish;
    String temp1;
    String temp2;
    Interval interval;
    interval = new Interval(start, start);
    String phrase = temporalPhrase.getPhrase();
    phrase = phrase.toLowerCase();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");

    int modiword = 0;// 0 :no modified words 1:early,ealier 2:late,later
    // Handle some special cases
    TimexChunk tc = new TimexChunk();
    tc.addAttribute(TimexNames.type, TimexNames.DATE);
    if (phrase.contains("now") || phrase.contains("currently") || phrase.contains("current")
            || phrase.contains("today")) {
        DateTime virtualStart = interval.getStart();
        virtualStart = new DateTime(virtualStart.getYear(), virtualStart.getMonthOfYear(),
                virtualStart.getDayOfMonth(), virtualStart.getHourOfDay(), virtualStart.getMinuteOfHour(),
                virtualStart.getSecondOfMinute(), virtualStart.getMillisOfSecond() + 1);
        tc.addAttribute(TimexNames.value, TimexNames.PRESENT_REF);
        return tc;
    }
    if (phrase.contains("early") || phrase.contains("earlier")) {
        modiword = 1;
    }
    if (phrase.contains("late") || phrase.contains("later")) {
        modiword = 2;
    }

    String units = "";

    for (String unitStr : dateUnitSet) {
        units = units + unitStr + "|";
    }
    units += "s$";

    String patternStr = "(?:the)?\\s*(\\d{1,4})(?:th|nd|st|rd)\\s*(" + units + ")\\s*";
    Pattern pattern = Pattern.compile(patternStr);
    Matcher matcher = pattern.matcher(phrase);
    boolean matchFound = matcher.find();
    if (matchFound) {
        temp1 = matcher.group(1);
        temp2 = matcher.group(2);

        String residual = StringUtils.difference(matcher.group(0), phrase);
        String anchorStr = "";
        if (residual.length() > 0) {
            TemporalPhrase anchorPhrase = new TemporalPhrase(residual, temporalPhrase.getTense());
            TimexChunk anchorTimex = TimexNormalizer.normalize(anchorPhrase);
            if (anchorTimex != null) {
                anchorStr = anchorTimex.getAttribute(TimexNames.value);
            }
        }

        if (temp2.equals("century")) {
            year = (Integer.parseInt(temp1) - 1) * 100;
            start = new DateTime(year, 1, 1, 0, 0, 0, 0);
            finish = new DateTime(year + 99, 12, 31, 23, 59, 59, 59);
            tc.addAttribute(TimexNames.value, String.valueOf(finish.getCenturyOfEra()));
            return tc;
        }

        else if (temp2.equals("decade")) {
            // e.g.: 3rd decade (of this century)
            // first we get this century is 20, then the 3rd decade is 203
            int anchorCentury = start.getCenturyOfEra();
            String val = String.valueOf(anchorCentury * 10 + temp1);
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("year")) {
            int anchorCentury = start.getCenturyOfEra();
            String val = String.valueOf(anchorCentury * 100 + temp1);
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("quarter")) {
            int anchorYear = start.getYear();
            String val = String.valueOf(anchorYear) + "-Q" + temp1;
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("month")) {
            int anchorYear = start.getYear();
            String monthStr = Integer.parseInt(temp1) < 10 ? "0" + temp1 : temp1;
            String val = String.valueOf(anchorYear) + "-" + monthStr;
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("day")) {
            String val = "";
            if (anchorStr.length() > 0) {
                List<String> normTimexList = Period.normTimexToList(anchorStr);
                String anchorYear = normTimexList.get(0);
                String anchorDate;
                String anchorMonth;
                if (normTimexList.size() == 1 || Integer.parseInt(temp1) > 31) {
                    anchorMonth = "01";
                } else {
                    anchorMonth = normTimexList.get(1);
                }
                DateTime normDateTime = new DateTime(Integer.parseInt(anchorYear),
                        Integer.parseInt(anchorMonth), 1, 0, 0);
                normDateTime = normDateTime.minusDays(-1 * Integer.parseInt(temp1));
                anchorYear = String.valueOf(normDateTime.getYear());
                anchorMonth = String.valueOf(normDateTime.getMonthOfYear());
                anchorDate = String.valueOf(normDateTime.getDayOfMonth());
                anchorMonth = anchorMonth.length() == 1 ? "0" + anchorMonth : anchorMonth;
                anchorDate = anchorDate.length() == 1 ? "0" + anchorDate : anchorDate;
                val = anchorYear + "-" + anchorMonth + "-" + anchorDate;

            } else {
                int month = Integer.parseInt(temp1) > 31 ? 1 : start.getMonthOfYear();
                DateTime normDateTime = new DateTime(start.getYear(), month, 1, 0, 0);
                normDateTime = normDateTime.minusDays(-1 * Integer.parseInt(temp1));
                String anchorYear = String.valueOf(normDateTime.getYear());
                String anchorMonth = String.valueOf(normDateTime.getMonthOfYear());
                String anchorDate = String.valueOf(normDateTime.getDayOfMonth());
                anchorMonth = anchorMonth.length() == 1 ? "0" + anchorMonth : anchorMonth;
                anchorDate = anchorDate.length() == 1 ? "0" + anchorDate : anchorDate;
                val = String.valueOf(anchorYear) + "-" + anchorMonth + "-" + anchorDate;
            }
            tc.addAttribute(TimexNames.value, String.valueOf(val));
            return tc;
        }

        else if (temp2.equals("s")) {

            if (Integer.parseInt(temp1) < 100) {
                year = start.getCenturyOfEra();
                year = year * 100 + Integer.parseInt(temp1);
                if (modiword == 0) {
                    tc.addAttribute(TimexNames.value, String.valueOf(year / 10));
                }

                else if (modiword == 1) {
                    tc.addAttribute(TimexNames.value, String.valueOf(year / 10));
                    tc.addAttribute(TimexNames.mod, TimexNames.START);
                }

                else if (modiword == 2) {
                    tc.addAttribute(TimexNames.value, String.valueOf(year / 10));
                    tc.addAttribute(TimexNames.mod, TimexNames.END);
                }

                return tc;
            }

            else {
                if (modiword == 0) {
                    start = new DateTime(Integer.parseInt(temp1), 1, 1, 0, 0, 0, 0);
                    finish = new DateTime(Integer.parseInt(temp1) + 9, 12, 31, 23, 59, 59, 59);
                    tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10));
                }

                else if (modiword == 1) {
                    start = new DateTime(Integer.parseInt(temp1), 1, 1, 0, 0, 0, 0);
                    finish = new DateTime(Integer.parseInt(temp1) + 3, 12, 31, 23, 59, 59, 59);
                    tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10));
                    tc.addAttribute(TimexNames.mod, TimexNames.START);
                }

                else if (modiword == 2) {
                    start = new DateTime(Integer.parseInt(temp1) + 7, 1, 1, 0, 0, 0, 0);
                    finish = new DateTime(Integer.parseInt(temp1) + 9, 12, 31, 23, 59, 59, 59);
                    tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10));
                    tc.addAttribute(TimexNames.mod, TimexNames.END);
                }
                return tc;

            }
        }

    }
    return null;
}

From source file:eu.itesla_project.histodb.client.impl.HistoDbClientImpl.java

License:Mozilla Public License

private static String toString(Interval interval) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm'Z'");
    return "[" + interval.getStart().toDateTime(DateTimeZone.UTC).toString(fmt) + ","
            + interval.getEnd().toDateTime(DateTimeZone.UTC).toString(fmt) + "]";
}