Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EventStripe.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2015-16 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.datamodel;
20 
21 import com.google.common.base.Preconditions;
22 import com.google.common.collect.ImmutableSet;
23 import com.google.common.collect.ImmutableSortedSet;
24 import java.util.Comparator;
25 import java.util.Objects;
26 import java.util.Optional;
27 import java.util.SortedSet;
28 import javax.annotation.concurrent.Immutable;
31 
36 @Immutable
37 public final class EventStripe implements MultiEvent<EventCluster> {
38 
39  public static EventStripe merge(EventStripe u, EventStripe v) {
40  Preconditions.checkNotNull(u);
41  Preconditions.checkNotNull(v);
42  Preconditions.checkArgument(Objects.equals(u.description, v.description));
43  Preconditions.checkArgument(Objects.equals(u.lod, v.lod));
44  Preconditions.checkArgument(Objects.equals(u.type, v.type));
45  Preconditions.checkArgument(Objects.equals(u.parent, v.parent));
46  return new EventStripe(u, v);
47  }
48 
49  private final EventCluster parent;
50 
51  private final ImmutableSortedSet<EventCluster> clusters;
52 
56  private final EventType type;
57 
61  private final String description;
62 
66  private final DescriptionLoD lod;
67 
71  private final ImmutableSet<Long> eventIDs;
72 
77  private final ImmutableSet<Long> tagged;
78 
82  private final ImmutableSet<Long> hashHits;
83 
85  if (java.util.Objects.nonNull(this.parent)) {
86  throw new IllegalStateException("Event Stripe already has a parent!");
87  }
88  return new EventStripe(parent, this.type, this.description, this.lod, clusters, eventIDs, tagged, hashHits);
89  }
90 
91  private EventStripe(EventCluster parent, EventType type, String description, DescriptionLoD lod, SortedSet<EventCluster> clusters, ImmutableSet<Long> eventIDs, ImmutableSet<Long> tagged, ImmutableSet<Long> hashHits) {
92  this.parent = parent;
93  this.type = type;
94  this.description = description;
95  this.lod = lod;
96  this.clusters = ImmutableSortedSet.copyOf(Comparator.comparing(EventCluster::getStartMillis), clusters);
97 
98  this.eventIDs = eventIDs;
99  this.tagged = tagged;
100  this.hashHits = hashHits;
101  }
102 
103  public EventStripe(EventCluster cluster) {
104 
105  this.clusters = ImmutableSortedSet.orderedBy(Comparator.comparing(EventCluster::getStartMillis))
106  .add(cluster.withParent(this)).build();
107 
108  type = cluster.getEventType();
109  description = cluster.getDescription();
110  lod = cluster.getDescriptionLoD();
111  eventIDs = cluster.getEventIDs();
112  tagged = cluster.getEventIDsWithTags();
113  hashHits = cluster.getEventIDsWithHashHits();
114  this.parent = null;
115  }
116 
118  clusters = ImmutableSortedSet.orderedBy(Comparator.comparing(EventCluster::getStartMillis))
119  .addAll(u.getClusters())
120  .addAll(v.getClusters())
121  .build();
122 
123  type = u.getEventType();
124  description = u.getDescription();
125  lod = u.getDescriptionLoD();
126  eventIDs = ImmutableSet.<Long>builder()
127  .addAll(u.getEventIDs())
128  .addAll(v.getEventIDs())
129  .build();
130  tagged = ImmutableSet.<Long>builder()
131  .addAll(u.getEventIDsWithTags())
132  .addAll(v.getEventIDsWithTags())
133  .build();
134  hashHits = ImmutableSet.<Long>builder()
135  .addAll(u.getEventIDsWithHashHits())
136  .addAll(v.getEventIDsWithHashHits())
137  .build();
138  parent = u.getParent().orElse(v.getParent().orElse(null));
139  }
140 
141  @Override
142  public Optional<EventCluster> getParent() {
143  return Optional.ofNullable(parent);
144  }
145 
146  public Optional<EventStripe> getParentStripe() {
147  if (getParent().isPresent()) {
148  return getParent().get().getParent();
149  } else {
150  return Optional.empty();
151  }
152  }
153 
154  @Override
155  public String getDescription() {
156  return description;
157  }
158 
159  @Override
161  return type;
162  }
163 
164  @Override
166  return lod;
167  }
168 
169  @Override
170  public ImmutableSet<Long> getEventIDs() {
171  return eventIDs;
172  }
173 
174  @Override
175  public ImmutableSet<Long> getEventIDsWithHashHits() {
176  return hashHits;
177  }
178 
179  @Override
180  public ImmutableSet<Long> getEventIDsWithTags() {
181  return tagged;
182  }
183 
184  @Override
185  public long getStartMillis() {
186  return clusters.first().getStartMillis();
187  }
188 
189  @Override
190  public long getEndMillis() {
191  return clusters.last().getEndMillis();
192  }
193 
194  @Override
195  public ImmutableSortedSet< EventCluster> getClusters() {
196  return clusters;
197  }
198 
199  @Override
200  public String toString() {
201  return "EventStripe{" + "description=" + description + ", eventIDs=" + (Objects.isNull(eventIDs) ? 0 : eventIDs.size()) + '}'; //NON-NLS
202  }
203 
204  @Override
205  public int hashCode() {
206  int hash = 3;
207  hash = 79 * hash + Objects.hashCode(this.clusters);
208  hash = 79 * hash + Objects.hashCode(this.type);
209  hash = 79 * hash + Objects.hashCode(this.description);
210  hash = 79 * hash + Objects.hashCode(this.lod);
211  hash = 79 * hash + Objects.hashCode(this.eventIDs);
212  return hash;
213  }
214 
215  @Override
216  public boolean equals(Object obj) {
217  if (this == obj) {
218  return true;
219  }
220  if (obj == null) {
221  return false;
222  }
223  if (getClass() != obj.getClass()) {
224  return false;
225  }
226  final EventStripe other = (EventStripe) obj;
227  if (!Objects.equals(this.description, other.description)) {
228  return false;
229  }
230  if (!Objects.equals(this.clusters, other.clusters)) {
231  return false;
232  }
233  if (!Objects.equals(this.type, other.type)) {
234  return false;
235  }
236  if (this.lod != other.lod) {
237  return false;
238  }
239  if (!Objects.equals(this.eventIDs, other.eventIDs)) {
240  return false;
241  }
242  return true;
243  }
244 }
EventStripe(EventCluster parent, EventType type, String description, DescriptionLoD lod, SortedSet< EventCluster > clusters, ImmutableSet< Long > eventIDs, ImmutableSet< Long > tagged, ImmutableSet< Long > hashHits)
EventStripe withParent(EventCluster parent)
static EventStripe merge(EventStripe u, EventStripe v)
final ImmutableSortedSet< EventCluster > clusters
ImmutableSortedSet< EventCluster > getClusters()

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