mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-02 20:04:37 +00:00
More documentation.
This commit is contained in:
@@ -22,93 +22,159 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
* Represents a path in a graph.
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class GraphPath implements Serializable {
|
||||
|
||||
private final List<Integer> keys = new ArrayList<>();
|
||||
/**
|
||||
* List of IPs where the Path branched
|
||||
*/
|
||||
private final List<Integer> branchIps = new ArrayList<>();
|
||||
|
||||
private final List<Integer> vals = new ArrayList<>();
|
||||
/**
|
||||
* List of branch indices of which way the path went
|
||||
*/
|
||||
private final List<Integer> branchIndices = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Name of the root
|
||||
*/
|
||||
public final String rootName;
|
||||
|
||||
public GraphPath(String rootName, List<Integer> keys, List<Integer> vals) {
|
||||
/**
|
||||
* Constructs a GraphPath with the given root name, branch IPs and branch indices.
|
||||
* @param rootName Root name
|
||||
* @param branchIps Branch IPs
|
||||
* @param branchIndices Branch indices
|
||||
*/
|
||||
public GraphPath(String rootName, List<Integer> branchIps, List<Integer> branchIndices) {
|
||||
this.rootName = rootName;
|
||||
this.keys.addAll(keys);
|
||||
this.vals.addAll(vals);
|
||||
this.branchIps.addAll(branchIps);
|
||||
this.branchIndices.addAll(branchIndices);
|
||||
}
|
||||
|
||||
public GraphPath(List<Integer> keys, List<Integer> vals) {
|
||||
/**
|
||||
* Constructs a GraphPath with the given branch IPs and branch indices.
|
||||
* @param branchIps Branch IPs
|
||||
* @param branchIndices Branch indices
|
||||
*/
|
||||
public GraphPath(List<Integer> branchIps, List<Integer> branchIndices) {
|
||||
rootName = "";
|
||||
this.keys.addAll(keys);
|
||||
this.vals.addAll(vals);
|
||||
this.branchIps.addAll(branchIps);
|
||||
this.branchIndices.addAll(branchIndices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a GraphPath
|
||||
*/
|
||||
public GraphPath() {
|
||||
rootName = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the path starts with the given path.
|
||||
* @param p
|
||||
* @return True if the path starts with the given path, false otherwise
|
||||
*/
|
||||
public boolean startsWith(GraphPath p) {
|
||||
if (p.length() > length()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Integer> otherKeys = new ArrayList<>(p.keys);
|
||||
List<Integer> otherVals = new ArrayList<>(p.vals);
|
||||
List<Integer> otherKeys = new ArrayList<>(p.branchIps);
|
||||
List<Integer> otherVals = new ArrayList<>(p.branchIndices);
|
||||
|
||||
for (int i = 0; i < p.length(); i++) {
|
||||
if (!Objects.equals(keys.get(i), otherKeys.get(i))) {
|
||||
if (!Objects.equals(branchIps.get(i), otherKeys.get(i))) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(vals.get(i), otherVals.get(i))) {
|
||||
if (!Objects.equals(branchIndices.get(i), otherVals.get(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new parent GraphPath with the given length.
|
||||
* @param len Length
|
||||
* @return
|
||||
*/
|
||||
public GraphPath parent(int len) {
|
||||
GraphPath par = new GraphPath(rootName);
|
||||
for (int i = 0; i < len; i++) {
|
||||
par.keys.add(keys.get(i));
|
||||
par.vals.add(vals.get(i));
|
||||
par.branchIps.add(branchIps.get(i));
|
||||
par.branchIndices.add(branchIndices.get(i));
|
||||
}
|
||||
return par;
|
||||
}
|
||||
|
||||
public GraphPath sub(int part, int codePos) {
|
||||
GraphPath next = new GraphPath(rootName, this.keys, this.vals);
|
||||
next.keys.add(codePos);
|
||||
next.vals.add(part);
|
||||
/**
|
||||
* Returns a new sub GraphPath with the given branch index and code position.
|
||||
* @param branchIndex Branch index
|
||||
* @param codePos Code position
|
||||
* @return New sub GraphPath
|
||||
*/
|
||||
public GraphPath sub(int branchIndex, int codePos) {
|
||||
GraphPath next = new GraphPath(rootName, this.branchIps, this.branchIndices);
|
||||
next.branchIps.add(codePos);
|
||||
next.branchIndices.add(branchIndex);
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a GraphPath with the given root name.
|
||||
* @param rootName Root name
|
||||
*/
|
||||
public GraphPath(String rootName) {
|
||||
this.rootName = rootName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets length of the path.
|
||||
* @return Length
|
||||
*/
|
||||
public int length() {
|
||||
return vals.size();
|
||||
return branchIndices.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the branch index at the given index.
|
||||
* @param index Index
|
||||
* @return Branch index
|
||||
*/
|
||||
public int get(int index) {
|
||||
return vals.get(index);
|
||||
return branchIndices.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the IP at the given index.
|
||||
* @param index Index
|
||||
* @return IP
|
||||
*/
|
||||
public int getKey(int index) {
|
||||
return keys.get(index);
|
||||
return branchIps.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash code.
|
||||
* @return Hash code
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 23 * hash + arrHashCode(keys);
|
||||
hash = 23 * hash + arrHashCode(vals);
|
||||
hash = 23 * hash + arrHashCode(branchIps);
|
||||
hash = 23 * hash + arrHashCode(branchIndices);
|
||||
hash = 23 * hash + Objects.hashCode(rootName);
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals.
|
||||
* @param obj Eq
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
@@ -126,17 +192,22 @@ public class GraphPath implements Serializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!arrMatch(keys, other.keys)) {
|
||||
if (!arrMatch(branchIps, other.branchIps)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!arrMatch(vals, other.vals)) {
|
||||
if (!arrMatch(branchIndices, other.branchIndices)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash code for a list of integers.
|
||||
* @param arr List of integers
|
||||
* @return Hash code
|
||||
*/
|
||||
private static int arrHashCode(List<Integer> arr) {
|
||||
if (arr == null || arr.isEmpty()) {
|
||||
return 0;
|
||||
@@ -150,6 +221,12 @@ public class GraphPath implements Serializable {
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether two lists of integers match.
|
||||
* @param arr List of integers
|
||||
* @param arr2 List of integers
|
||||
* @return True if the lists match, false otherwise
|
||||
*/
|
||||
private static boolean arrMatch(List<Integer> arr, List<Integer> arr2) {
|
||||
if (arr.size() != arr2.size()) {
|
||||
return false;
|
||||
@@ -162,11 +239,15 @@ public class GraphPath implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the GraphPath.
|
||||
* @return String representation
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = rootName;
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
ret += "/" + keys.get(i) + ":" + vals.get(i);
|
||||
for (int i = 0; i < branchIps.size(); i++) {
|
||||
ret += "/" + branchIps.get(i) + ":" + branchIndices.get(i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user