Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
RangeDivision.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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.util.ArrayList;
22 import java.util.List;
23 import org.joda.time.DateTime;
24 import org.joda.time.DateTimeZone;
25 import org.joda.time.Days;
26 import org.joda.time.Hours;
27 import org.joda.time.Interval;
28 import org.joda.time.Minutes;
29 import org.joda.time.Months;
30 import org.joda.time.Years;
31 import org.joda.time.format.DateTimeFormatter;
33 
41 final public class RangeDivision {
42 
46  private final TimeUnits periodSize;
47 
52  private final long lowerBound;
53 
58  private final long upperBound;
59 
63  private final Interval timeRange;
64 
65  private RangeDivision(Interval timeRange, TimeUnits periodSize, long lowerBound, long upperBound) {
66  this.periodSize = periodSize;
67  this.lowerBound = lowerBound;
68  this.upperBound = upperBound;
69  this.timeRange = timeRange;
70  }
71 
83  public static RangeDivision getRangeDivision(Interval timeRange, DateTimeZone timeZone) {
84  //Check from largest to smallest unit
85 
86  //TODO: make this more generic... reduce code duplication -jm
87  TimeUnits timeUnit;
88  final DateTime startWithZone = timeRange.getStart().withZone(timeZone);
89  final DateTime endWithZone = timeRange.getEnd().withZone(timeZone);
90  long lower;
91  long upper;
92  if (Years.yearsIn(timeRange).isGreaterThan(Years.THREE)) {
93  timeUnit = TimeUnits.YEARS;
94  } else if (Months.monthsIn(timeRange).isGreaterThan(Months.THREE)) {
95  timeUnit = TimeUnits.MONTHS;
96  } else if (Days.daysIn(timeRange).isGreaterThan(Days.THREE)) {
97  timeUnit = TimeUnits.DAYS;
98  } else if (Hours.hoursIn(timeRange).isGreaterThan(Hours.THREE)) {
99  timeUnit = TimeUnits.HOURS;
100  } else if (Minutes.minutesIn(timeRange).isGreaterThan(Minutes.THREE)) {
101  timeUnit = TimeUnits.MINUTES;
102  } else {
103  timeUnit = TimeUnits.SECONDS;
104  }
105  lower = timeUnit.propertyOf(startWithZone).roundFloorCopy().getMillis();
106  upper = timeUnit.propertyOf(endWithZone).roundCeilingCopy().getMillis();
107  return new RangeDivision(timeRange, timeUnit, lower, upper); // NON-NLS
108  }
109 
110  public Interval getOriginalTimeRange() {
111  return timeRange;
112  }
113 
119  public DateTimeFormatter getTickFormatter() {
120  return periodSize.getTickFormatter();
121  }
122 
124  return periodSize;
125  }
126 
127  public long getUpperBound() {
128  return upperBound;
129  }
130 
131  public long getLowerBound() {
132  return lowerBound;
133  }
134 
135  @SuppressWarnings("ReturnOfCollectionOrArrayField")
136  synchronized public List<Interval> getIntervals(DateTimeZone tz) {
137 
138  ArrayList<Interval> intervals = new ArrayList<>();
139  //extend range to block bounderies (ie day, month, year)
140  final Interval range = new Interval(new DateTime(lowerBound, tz), new DateTime(upperBound, tz));
141 
142  DateTime start = range.getStart();
143  while (range.contains(start)) {
144  //increment for next iteration
145  DateTime end = start.plus(getPeriodSize().toUnitPeriod());
146  final Interval interval = new Interval(start, end);
147  intervals.add(interval);
148  start = end;
149  }
150 
151  return intervals;
152  }
153 
154 }
RangeDivision(Interval timeRange, TimeUnits periodSize, long lowerBound, long upperBound)
synchronized List< Interval > getIntervals(DateTimeZone tz)
static RangeDivision getRangeDivision(Interval timeRange, DateTimeZone timeZone)
DateTime.Property propertyOf(DateTime dateTime)
Definition: TimeUnits.java:70

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.