Sleuth Kit Java Bindings (JNI)  4.11.0
Java bindings for using The Sleuth Kit
Relationship.java
Go to the documentation of this file.
1 /*
2  * SleuthKit Java Bindings
3  *
4  * Copyright 2017-18 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.Collections;
23 import static java.util.Collections.singleton;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.Set;
31 import static org.sleuthkit.datamodel.CollectionUtils.hashSetOf;
32 
37 public final class Relationship {
38 
39  public static final class Type {
40 
41  private final String displayName;
42  private final String typeName;
43  private final int typeID;
44 
45  public static final Relationship.Type MESSAGE = new Type("MESSAGE", "Message", 1);
46  public static final Relationship.Type CALL_LOG = new Type("CALL_LOG", "Call Log", 2);
47  public static final Relationship.Type CONTACT = new Type("CONTACT", "Contact", 3);
48 
49  private final static HashMap<Type, Set<Integer>> typesToArtifactTypeIDs = new HashMap<Type, Set<Integer>>();
50 
51  static {
52  typesToArtifactTypeIDs.put(MESSAGE, hashSetOf(
53  TSK_EMAIL_MSG.getTypeID(),
54  TSK_MESSAGE.getTypeID()));
55  typesToArtifactTypeIDs.put(CALL_LOG, singleton(
56  TSK_CALLLOG.getTypeID()));
57  typesToArtifactTypeIDs.put(CONTACT, singleton(
58  TSK_CONTACT.getTypeID()));
59  }
60 
61  private static final Set<Type> PREDEFINED_COMMUNICATION_TYPES
62  = Collections.unmodifiableSet(new HashSet<Relationship.Type>(Arrays.asList(
63  MESSAGE, CALL_LOG)));
64 
71  static Set<Relationship.Type> getPredefinedCommunicationTypes() {
72  return PREDEFINED_COMMUNICATION_TYPES;
73  }
74 
75  private Type(String name, String displayName, int id) {
76  this.typeName = name;
77  this.displayName = displayName;
78  this.typeID = id;
79  }
80 
86  public String getDisplayName() {
87  return displayName;
88  }
89 
95  public String getTypeName() {
96  return typeName;
97  }
98 
104  public int getTypeID() {
105  return typeID;
106  }
107 
108  @Override
109  public int hashCode() {
110  int hash = 7;
111  hash = 37 * hash + (this.typeName != null ? this.typeName.hashCode() : 0);
112  hash = 37 * hash + this.typeID;
113  return hash;
114  }
115 
116  @Override
117  public boolean equals(Object obj) {
118  if (this == obj) {
119  return true;
120  }
121  if (obj == null) {
122  return false;
123  }
124  if (getClass() != obj.getClass()) {
125  return false;
126  }
127  final Type other = (Type) obj;
128  if (this.typeID != other.typeID) {
129  return false;
130  }
131  if ((this.typeName == null) ? (other.typeName != null) : !this.typeName.equals(other.typeName)) {
132  return false;
133  }
134  return true;
135  }
136 
137  @Override
138  public String toString() {
139  return "{" + this.getClass().getName() + ": typeID=" + typeName + ", displayName=" + this.displayName + ", typeName=" + this.typeName + "}";
140  }
141 
152  boolean isCreatableFrom(BlackboardArtifact relationshipArtifact) {
153  Set<Integer> get = typesToArtifactTypeIDs.get(this);
154  return get != null && get.contains(relationshipArtifact.getArtifactTypeID());
155  }
156  }
157 }
static final Relationship.Type CALL_LOG
static final Relationship.Type MESSAGE
static final Relationship.Type CONTACT

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.