Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
HostGrouping.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.datamodel;
20 
21 import java.util.Objects;
22 import org.sleuthkit.datamodel.Host;
23 
27 public class HostGrouping implements AutopsyVisitableItem, Comparable<HostGrouping> {
28 
29  private final Host host;
30 
36  HostGrouping(Host host) {
37  this.host = host;
38  }
39 
43  Host getHost() {
44  return host;
45  }
46 
47  @Override
48  public <T> T accept(AutopsyItemVisitor<T> visitor) {
49  return visitor.visit(this);
50  }
51 
52  @Override
53  public int hashCode() {
54  return Objects.hashCode(this.host == null ? 0 : this.host.getHostId());
55  }
56 
57  @Override
58  public boolean equals(Object obj) {
59  if (this == obj) {
60  return true;
61  }
62  if (obj == null) {
63  return false;
64  }
65  if (getClass() != obj.getClass()) {
66  return false;
67  }
68  final HostGrouping other = (HostGrouping) obj;
69  long thisId = (this.getHost() == null) ? 0 : this.getHost().getHostId();
70  long otherId = (other.getHost() == null) ? 0 : other.getHost().getHostId();
71  return thisId == otherId;
72  }
73 
74  /*
75  * Compares two host groupings to be displayed in a list of children under
76  * the person.
77  */
78  @Override
79  public int compareTo(HostGrouping o) {
80  String thisHost = this.getHost() == null ? null : this.getHost().getName();
81  String otherHost = o == null || o.getHost() == null ? null : o.getHost().getName();
82 
83  // push unknown host to bottom
84  if (thisHost == null && otherHost == null) {
85  return 0;
86  } else if (thisHost == null) {
87  return 1;
88  } else if (otherHost == null) {
89  return -1;
90  }
91 
92  return thisHost.compareToIgnoreCase(otherHost);
93  }
94 
95 }

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