Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IntervalUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.timeline.utils;
20 
21 import java.time.Instant;
22 import java.time.temporal.TemporalAmount;
23 import java.util.Collection;
24 import org.joda.time.DateTime;
25 import org.joda.time.DateTimeZone;
26 import org.joda.time.Interval;
27 import org.joda.time.ReadablePeriod;
29 
33 public class IntervalUtils {
34 
35  static public Interval getSpanningInterval(Collection<DateTime> times) {
36  Interval trange = null;
37  for (DateTime t : times) {
38  if (trange == null) {
39  trange = new Interval(t.getMillis(), t.getMillis() + 1000, DateTimeZone.UTC);
40  } else {
41  trange = extendInterval(trange, t.getMillis());
42  }
43  }
44  return trange;
45  }
46 
47  static public Interval span(Interval range, final Interval range2) {
48  return new Interval(Math.min(range.getStartMillis(), range2.getStartMillis()), Math.max(range.getEndMillis(), range2.getEndMillis()), DateTimeZone.UTC);
49  }
50 
51  static public Interval extendInterval(Interval range, final Long eventTime) {
52  return new Interval(Math.min(range.getStartMillis(), eventTime), Math.max(range.getEndMillis(), eventTime + 1), DateTimeZone.UTC);
53  }
54 
55  public static DateTime middleOf(Interval interval) {
56  return new DateTime((interval.getStartMillis() + interval.getEndMillis()) / 2);
57  }
58 
59  public static Interval getAdjustedInterval(Interval oldInterval, TimeUnits requestedUnit) {
60  return getIntervalAround(middleOf(oldInterval), requestedUnit.getPeriod());
61  }
62 
63  static public Interval getIntervalAround(DateTime aroundInstant, ReadablePeriod period) {
64  DateTime start = aroundInstant.minus(period);
65  DateTime end = aroundInstant.plus(period);
66  Interval range = new Interval(start, end);
67  DateTime middleOf = IntervalUtils.middleOf(range);
68  long halfRange = range.toDurationMillis() / 4;
69  final Interval newInterval = new Interval(middleOf.minus(halfRange), middleOf.plus(halfRange));
70  return newInterval;
71  }
72 
73  static public Interval getIntervalAround(Instant aroundInstant, TemporalAmount temporalAmount) {
74  long start = aroundInstant.minus(temporalAmount).toEpochMilli();
75  long end = aroundInstant.plusMillis(1).plus(temporalAmount).toEpochMilli();
76  final Interval newInterval = new Interval(start, Math.max(start + 1, end));
77  return newInterval;
78  }
79 
91  static public Interval getIntervalAroundMiddle(Interval interval, ReadablePeriod period) {
92  return getIntervalAround(middleOf(interval), period);
93  }
94 }
static Interval getIntervalAround(Instant aroundInstant, TemporalAmount temporalAmount)
static Interval span(Interval range, final Interval range2)
static Interval getAdjustedInterval(Interval oldInterval, TimeUnits requestedUnit)
static Interval getIntervalAroundMiddle(Interval interval, ReadablePeriod period)
static Interval getIntervalAround(DateTime aroundInstant, ReadablePeriod period)
static Interval getSpanningInterval(Collection< DateTime > times)
static Interval extendInterval(Interval range, final Long eventTime)
static DateTime middleOf(Interval interval)

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.