Sleuth Kit Java Bindings (JNI)  4.12.1
Java bindings for using The Sleuth Kit
Score.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2020-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.datamodel;
20 
21 import java.util.Arrays;
22 import java.util.Comparator;
23 import java.util.ResourceBundle;
24 
64 public class Score implements Comparable<Score> {
65 
66  private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
75  public enum Significance {
76 
77  // Enum name must not have any spaces.
78 
79  /* Notes on the ordinal numbers: We defined these so that we could easily
80  * compare values while also have some concept of grouping.
81  * The 1x values are a higher confidence than the 0x files.
82  * NOTABLE (x9) has priority over NOT NOTABLE (x8).
83  * If we need to make this more complicated in the future, we can add
84  * other groupings, such as 14 and 15.
85  */
86 
88  UNKNOWN(0, "Unknown", "Significance.Unknown.displayName.text"),
89 
91  LIKELY_NONE(8, "LikelyNone", "Significance.LikelyNone.displayName.text"),
92 
94  LIKELY_NOTABLE(9, "LikelyNotable", "Significance.LikelyNotable.displayName.text"),
95 
97  NONE(18, "None", "Significance.None.displayName.text"),
98 
100  NOTABLE(19, "Notable", "Significance.Notable.displayName.text");
101 
102  private final int id;
103  private final String name; // name must not have spaces
104  private final String displayNameKey; // display name is loaded from resource bundle using this key.
105 
106  private Significance(int id, String name, String displayNameKey) {
107  this.id = id;
108  this.name = name;
109  this.displayNameKey = displayNameKey;
110  }
111 
112  public static Significance fromString(String name) {
113  return Arrays.stream(values())
114  .filter(val -> val.getName().equals(name))
115  .findFirst().orElse(NONE);
116  }
117 
118  static public Significance fromID(int id) {
119  return Arrays.stream(values())
120  .filter(val -> val.getId() == id)
121  .findFirst().orElse(NONE);
122  }
123 
129  public int getId() {
130  return id;
131  }
132 
139  public String getName() {
140  return name;
141  }
142 
149  public String getDisplayName() {
150  return bundle.getString(displayNameKey);
151  }
152 
153  @Override
154  public String toString() {
155  return name;
156  }
157  }
158 
162  public enum Priority {
163 
164  // Name must not have any spaces.
165  NORMAL(0, "Normal", "Score.Priority.Normal.displayName.text"),
166  OVERRIDE(10, "Override", "Score.Priority.Override.displayName.text");
167 
168  private final int id;
169  private final String name;
170  private final String displayNameKey; // display name is loaded from resource bundle using this key.
171 
172  private Priority(int id, String name, String displayNameKey) {
173  this.id = id;
174  this.name = name;
175  this.displayNameKey = displayNameKey;
176  }
177 
178  public static Priority fromString(String name) {
179  return Arrays.stream(values())
180  .filter(val -> val.getName().equals(name))
181  .findFirst().orElse(NORMAL);
182  }
183 
184  static public Priority fromID(int id) {
185  return Arrays.stream(values())
186  .filter(val -> val.getId() == id)
187  .findFirst().orElse(NORMAL);
188  }
189 
190  public int getId() {
191  return id;
192  }
193 
194  public String getName() {
195  return name;
196  }
197 
198  public String getDisplayName() {
199  return bundle.getString(displayNameKey);
200  }
201 
202  @Override
203  public String toString() {
204  return name;
205  }
206  }
207 
211  public static final Score SCORE_NONE= new Score(Significance.NONE, Priority.NORMAL);
212 
214 
215  // Score is a combination of significance and priority.
216  private final Significance significance;
217  private final Priority priority;
218 
219  public Score(Significance significance, Priority priority) {
220  this.significance = significance;
221  this.priority = priority;
222  }
223 
225  return significance;
226  }
227 
229  return priority;
230  }
231 
232  @Override
233  public int compareTo(Score other) {
234  // A score is a combination of significance & priority.
235  // Priority Override overrides Normal.
236  // If two results have same priority, then the higher significance wins.
237  if (this.getPriority() != other.getPriority()) {
238  return this.getPriority().ordinal() - other.getPriority().ordinal();
239  } else {
240  return this.getSignificance().ordinal() - other.getSignificance().ordinal();
241  }
242  }
243 
244  public static final Comparator<Score> getScoreComparator() {
245  return (Score score1, Score score2) -> {
246  return score1.compareTo(score2);
247  };
248  }
249 }
UNKNOWN
no significance assigned yet.
Definition: Score.java:88
static Priority fromID(int id)
Definition: Score.java:184
static Significance fromID(int id)
Definition: Score.java:118
Significance getSignificance()
Definition: Score.java:224
static final Score SCORE_UNKNOWN
Definition: Score.java:213
static final Score SCORE_NOTABLE
Definition: Score.java:208
Score(Significance significance, Priority priority)
Definition: Score.java:219
int compareTo(Score other)
Definition: Score.java:233
static Priority fromString(String name)
Definition: Score.java:178
static final Score SCORE_LIKELY_NONE
Definition: Score.java:210
static final Score SCORE_NONE
Definition: Score.java:211
static final Comparator< Score > getScoreComparator()
Definition: Score.java:244
static final Score SCORE_LIKELY_NOTABLE
Definition: Score.java:209
static Significance fromString(String name)
Definition: Score.java:112
LIKELY_NOTABLE
likely bad, suspicious
Definition: Score.java:94

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.