package net.dean.jraw.models;

import java.util.EnumMap;

/**
 * Hints at where some data in a tree structure might be. The "top" of the tree is the root node, while the "bottom" is
 * the deepest level in the tree. There will only be (at maximum) one instance of this class for every value in
 * {@link TraversalMethod}. Instances of this class are immutable.
 */
public final class LocationHint {
    private final TraversalMethod method;
    private static final EnumMap<TraversalMethod, LocationHint> instances = new EnumMap<>(TraversalMethod.class);

    private LocationHint(TraversalMethod method) {
        this.method = method;
    }

    /** Creates a LocationHint with a custom TraversalMethod */
    public static LocationHint of(TraversalMethod method) {
        if (!instances.containsKey(method)) {
            LocationHint hint = new LocationHint(method);
            instances.put(method, hint);
            return hint;
        }

        return instances.get(method);
    }

    /** The data is near the top of the tree structure. Uses breadth-first traversal. */
    public static LocationHint nearTop() {
        return of(TraversalMethod.BREADTH_FIRST);
    }

    /** The data is near the bottom of the tree structure. Uses post-order traversal. */
    public static LocationHint nearBottom() {
        return of(TraversalMethod.POST_ORDER);
    }

    /** The data's location is unknown. Uses pre-order traversal. */
    public static LocationHint anywhere() {
        return of(TraversalMethod.PRE_ORDER);
    }

    TraversalMethod getTraversalMethod() {
        return method;
    }
}

@@ -592,32 +592,139 @@
 ethod method) %7B%0A
+        if (method == null)%0A            throw new NullPointerException(%22Traversal method cannot be null%22);%0A
         this.met
@@ -1709,11 +1709,486 @@
 d;%0A    %7D
+%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (o == null %7C%7C getClass() != o.getClass()) return false;%0A%0A        LocationHint that = (LocationHint) o;%0A%0A        return method == that.method;%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return method.hashCode();%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return %22LocationHint %7B%22 +%0A                %22method=%22 + method +%0A                '%7D';%0A    %7D
 %0A%7D%0A

Create equals(), hashCode(), and toString() for LocationHint