Autopsy  4.20.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 2018-2019 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.ui.detailview.datamodel;
20 
21 import com.google.common.base.Preconditions;
22 import com.google.common.collect.Sets;
23 import static java.util.Collections.singleton;
24 import static java.util.Comparator.comparing;
25 import java.util.Objects;
26 import java.util.Optional;
27 import java.util.Set;
28 import java.util.SortedSet;
29 import org.sleuthkit.datamodel.TimelineLevelOfDetail;
30 import org.sleuthkit.datamodel.TimelineEventType;
31 
36 public final class EventStripe implements MultiEvent<EventCluster> {
37 
38  private final EventCluster parent;
39 
40  private final SortedSet<EventCluster> clusters;
41 
45  private final TimelineEventType type;
46 
50  private final String description;
51 
55  private final TimelineLevelOfDetail lod;
56 
60  private final Set<Long> eventIDs;
61 
66  private final Set<Long> tagged;
67 
71  private final Set<Long> hashHits;
72 
73  public static EventStripe merge(EventStripe stripeA, EventStripe stripeB) {
74  Preconditions.checkNotNull(stripeA);
75  Preconditions.checkNotNull(stripeB);
76  Preconditions.checkArgument(Objects.equals(stripeA.description, stripeB.description));
77  Preconditions.checkArgument(Objects.equals(stripeA.lod, stripeB.lod));
78  Preconditions.checkArgument(Objects.equals(stripeA.type, stripeB.type));
79  Preconditions.checkArgument(Objects.equals(stripeA.parent, stripeB.parent));
80  return new EventStripe(stripeA, stripeB);
81  }
82 
84  if (Objects.nonNull(this.parent)) {
85  throw new IllegalStateException("Event Stripe already has a parent!");
86  }
87  return new EventStripe(parent, this.type, this.description, this.lod, clusters, eventIDs, tagged, hashHits);
88  }
89 
90  private EventStripe(EventCluster parent, TimelineEventType type, String description,
91  TimelineLevelOfDetail lod, SortedSet<EventCluster> clusters,
92  Set<Long> eventIDs, Set<Long> tagged, Set<Long> hashHits) {
93  this.parent = parent;
94  this.type = type;
95  this.description = description;
96  this.lod = lod;
97  this.clusters = clusters;
98 
99  this.eventIDs = eventIDs;
100  this.tagged = tagged;
101  this.hashHits = hashHits;
102  }
103 
104  public EventStripe(EventCluster cluster) {
105  this.clusters = DetailsViewModel.copyAsSortedSet(singleton(cluster.withParent(this)),
106  comparing(EventCluster::getStartMillis));
107 
108  type = cluster.getEventType();
109  description = cluster.getDescription();
110  lod = cluster.getDescriptionLevel();
111  eventIDs = cluster.getEventIDs();
112  tagged = cluster.getEventIDsWithTags();
113  hashHits = cluster.getEventIDsWithHashHits();
114  this.parent = null;
115  }
116 
117  private EventStripe(EventStripe stripeA, EventStripe stripeB) {
118  clusters = DetailsViewModel.copyAsSortedSet(Sets.union(stripeA.getClusters(), stripeB.getClusters()), comparing(EventCluster::getStartMillis));
119 
120  type = stripeA.getEventType();
121  description = stripeA.getDescription();
122  lod = stripeA.getDescriptionLevel();
123  eventIDs = Sets.union(stripeA.getEventIDs(), stripeB.getEventIDs());
124  tagged = Sets.union(stripeA.getEventIDsWithTags(), stripeB.getEventIDsWithTags());
125  hashHits = Sets.union(stripeA.getEventIDsWithHashHits(), stripeB.getEventIDsWithHashHits());
126  parent = stripeA.getParent().orElse(stripeB.getParent().orElse(null));
127  }
128 
129  @Override
130  public Optional<EventCluster> getParent() {
131  return Optional.ofNullable(parent);
132  }
133 
134  @Override
135  public Optional<EventStripe> getParentStripe() {
136  if (getParent().isPresent()) {
137  return getParent().get().getParent();
138  } else {
139  return Optional.empty();
140  }
141  }
142 
143  @Override
144  public String getDescription() {
145  return description;
146  }
147 
148  @Override
149  public TimelineEventType getEventType() {
150  return type;
151  }
152 
153  @Override
154  public TimelineLevelOfDetail getDescriptionLevel() {
155  return lod;
156  }
157 
158  @Override
159  public Set<Long> getEventIDs() {
160  return eventIDs;
161  }
162 
163  @Override
164  public Set<Long> getEventIDsWithHashHits() {
165  return hashHits;
166  }
167 
168  @Override
169  public Set<Long> getEventIDsWithTags() {
170  return tagged;
171  }
172 
173  @Override
174  public long getStartMillis() {
175  return clusters.first().getStartMillis();
176  }
177 
178  @Override
179  public long getEndMillis() {
180  return clusters.last().getEndMillis();
181  }
182 
183  @Override
184  public SortedSet< EventCluster> getClusters() {
185  return clusters;
186  }
187 
188  @Override
189  public String toString() {
190  return "EventStripe{" + "description=" + description + ", eventIDs=" + (Objects.isNull(eventIDs) ? 0 : eventIDs.size()) + '}'; //NON-NLS
191  }
192 
193  @Override
194  public int hashCode() {
195  int hash = 3;
196  hash = 79 * hash + Objects.hashCode(this.clusters);
197  hash = 79 * hash + Objects.hashCode(this.type);
198  hash = 79 * hash + Objects.hashCode(this.description);
199  hash = 79 * hash + Objects.hashCode(this.lod);
200  hash = 79 * hash + Objects.hashCode(this.eventIDs);
201  return hash;
202  }
203 
204  @Override
205  public boolean equals(Object obj) {
206  if (this == obj) {
207  return true;
208  }
209  if (obj == null) {
210  return false;
211  }
212  if (getClass() != obj.getClass()) {
213  return false;
214  }
215  final EventStripe other = (EventStripe) obj;
216  if (!Objects.equals(this.description, other.description)) {
217  return false;
218  }
219  if (!Objects.equals(this.clusters, other.clusters)) {
220  return false;
221  }
222  if (!Objects.equals(this.type, other.type)) {
223  return false;
224  }
225  if (this.lod != other.lod) {
226  return false;
227  }
228  return Objects.equals(this.eventIDs, other.eventIDs);
229  }
230 
231 }
static EventStripe merge(EventStripe stripeA, EventStripe stripeB)
EventStripe(EventCluster parent, TimelineEventType type, String description, TimelineLevelOfDetail lod, SortedSet< EventCluster > clusters, Set< Long > eventIDs, Set< Long > tagged, Set< Long > hashHits)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.