Sleuth Kit Java Bindings (JNI)  4.12.1
Java bindings for using The Sleuth Kit
TagSet.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2020 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.datamodel;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.Comparator;
24 import java.util.List;
25 import java.util.Objects;
26 
30 public class TagSet {
31 
32  private final String setName;
33  private final long id;
34  private final List<TagName> tagNameList;
35 
42  TagSet(long id, String setName, List<TagName> tagNameList) {
43  if (setName == null || setName.isEmpty()) {
44  throw new IllegalArgumentException("TagSet name must be a non-empty string");
45  }
46  this.tagNameList = new ArrayList<>(tagNameList);
47  this.tagNameList.sort(new TagNameComparator());
48  this.id = id;
49  this.setName = setName;
50  }
51 
57  public String getName() {
58  return setName;
59  }
60 
66  public List<TagName> getTagNames() {
67  return Collections.unmodifiableList(tagNameList);
68  }
69 
75  public long getId() {
76  return id;
77  }
78 
79  @Override
80  public boolean equals(Object obj) {
81  if (obj == null) {
82  return false;
83  }
84 
85  if (getClass() != obj.getClass()) {
86  return false;
87  }
88 
89  final TagSet other = (TagSet) obj;
90 
91  return (this.id == other.getId()
92  && setName.equals(other.getName())
93  && tagNameList.equals(other.tagNameList));
94  }
95 
96  @Override
97  public int hashCode() {
98  int hash = 5;
99  hash = 89 * hash + (int) (this.id ^ (this.id >>> 32));
100  hash = 89 * hash + Objects.hashCode(this.setName);
101  hash = 89 * hash + Objects.hashCode(this.tagNameList);
102 
103  return hash;
104  }
105 
109  private class TagNameComparator implements Comparator<TagName> {
110  @Override
111  public int compare(TagName tagName1, TagName tagName2) {
112  int result = ((Integer)tagName1.getRank()).compareTo(tagName2.getRank());
113  if(result == 0) {
114  result = tagName1.getDisplayName().compareTo(tagName2.getDisplayName());
115  }
116  return result;
117  }
118  }
119 }
boolean equals(Object obj)
Definition: TagSet.java:80
List< TagName > getTagNames()
Definition: TagSet.java:66

Copyright © 2011-2021 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.