Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
RangeDivisionInfo.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 javax.annotation.concurrent.Immutable;
22 import org.joda.time.DateTime;
23 import org.joda.time.DateTimeFieldType;
24 import org.joda.time.Days;
25 import org.joda.time.Hours;
26 import org.joda.time.Interval;
27 import org.joda.time.Minutes;
28 import org.joda.time.Months;
29 import org.joda.time.Seconds;
30 import org.joda.time.Years;
31 import org.joda.time.format.DateTimeFormat;
32 import org.joda.time.format.DateTimeFormatter;
33 import org.joda.time.format.ISODateTimeFormat;
36 
42 @Immutable
43 public class RangeDivisionInfo {
44 
46  private final TimeUnits blockSize;
47 
49  private final int numberOfBlocks;
50 
53  private final DateTimeFormatter tickFormatter;
54 
57  private final long lowerBound;
58 
61  private final long upperBound;
62 
64  private final Interval timeRange;
65 
66  public Interval getTimeRange() {
67  return timeRange;
68  }
69 
70  private RangeDivisionInfo(Interval timeRange, int periodsInRange, TimeUnits periodSize, DateTimeFormatter tickformatter, long lowerBound, long upperBound) {
71  super();
72  this.numberOfBlocks = periodsInRange;
73  this.blockSize = periodSize;
74  this.tickFormatter = tickformatter;
75 
76  this.lowerBound = lowerBound;
77  this.upperBound = upperBound;
78  this.timeRange = timeRange;
79  }
80 
91  public static RangeDivisionInfo getRangeDivisionInfo(Interval timeRange) {
92  //Check from largest to smallest unit
93 
94  //TODO: make this more generic... reduce code duplication -jm
95  DateTimeFieldType timeUnit;
96  final DateTime startWithZone = timeRange.getStart().withZone(TimeLineController.getJodaTimeZone());
97  final DateTime endWithZone = timeRange.getEnd().withZone(TimeLineController.getJodaTimeZone());
98 
99  if (Years.yearsIn(timeRange).isGreaterThan(Years.THREE)) {
100  timeUnit = DateTimeFieldType.year();
101  long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
102  long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
103  return new RangeDivisionInfo(timeRange, Years.yearsIn(timeRange).get(timeUnit.getDurationType()) + 1, TimeUnits.YEARS, ISODateTimeFormat.year(), lower, upper);
104  } else if (Months.monthsIn(timeRange).isGreaterThan(Months.THREE)) {
105  timeUnit = DateTimeFieldType.monthOfYear();
106  long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
107  long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
108  return new RangeDivisionInfo(timeRange, Months.monthsIn(timeRange).getMonths() + 1, TimeUnits.MONTHS, DateTimeFormat.forPattern("YYYY'-'MMMM"), lower, upper); // NON-NLS
109  } else if (Days.daysIn(timeRange).isGreaterThan(Days.THREE)) {
110  timeUnit = DateTimeFieldType.dayOfMonth();
111  long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
112  long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
113  return new RangeDivisionInfo(timeRange, Days.daysIn(timeRange).getDays() + 1, TimeUnits.DAYS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd"), lower, upper); // NON-NLS
114  } else if (Hours.hoursIn(timeRange).isGreaterThan(Hours.THREE)) {
115  timeUnit = DateTimeFieldType.hourOfDay();
116  long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
117  long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
118  return new RangeDivisionInfo(timeRange, Hours.hoursIn(timeRange).getHours() + 1, TimeUnits.HOURS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH"), lower, upper); // NON-NLS
119  } else if (Minutes.minutesIn(timeRange).isGreaterThan(Minutes.THREE)) {
120  timeUnit = DateTimeFieldType.minuteOfHour();
121  long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
122  long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
123  return new RangeDivisionInfo(timeRange, Minutes.minutesIn(timeRange).getMinutes() + 1, TimeUnits.MINUTES, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm"), lower, upper); // NON-NLS
124  } else {
125  timeUnit = DateTimeFieldType.secondOfMinute();
126  long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
127  long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
128  return new RangeDivisionInfo(timeRange, Seconds.secondsIn(timeRange).getSeconds() + 1, TimeUnits.SECONDS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm':'ss"), lower, upper); // NON-NLS
129  }
130  }
131 
132  public DateTimeFormatter getTickFormatter() {
133  return tickFormatter;
134  }
135 
136  public int getPeriodsInRange() {
137  return numberOfBlocks;
138  }
139 
141  return blockSize;
142  }
143 
144  public long getUpperBound() {
145  return upperBound;
146  }
147 
148  public long getLowerBound() {
149  return lowerBound;
150  }
151 }
static RangeDivisionInfo getRangeDivisionInfo(Interval timeRange)
RangeDivisionInfo(Interval timeRange, int periodsInRange, TimeUnits periodSize, DateTimeFormatter tickformatter, long lowerBound, long upperBound)

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.