Skip to content

Commit

Permalink
Add API methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Werner Randelshofer committed Feb 15, 2024
1 parent ae09fa5 commit 1a9b831
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ public interface IdResolver {
* @param id the id
* @return the object
*/
@Nullable Object getObject(String id);
@Nullable Object getObject(@Nullable String id);

/**
* Gets the object of the specified class for the specified id.
* Returns null if the id has no object of this type.
*
* @param clazz the clazz
* @param id the id
* @return the object
*/
default <T> @Nullable T getObject(@NonNull Class<T> clazz, @Nullable String id) {
Object object = getObject(id);
if (clazz.isInstance(object)) return clazz.cast(object);
return null;
}

/**
* Absolutize the given external URI, so that it can be used inside
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
* @author Werner Randelshofer
*/
public interface UnorderedPair<V> {
/**
* Returns other() if someone is equal to either(),
* returns either() otherwise.
*
* @param someone either or other
* @return
*/
default V getOther(V someone) {
V either = either();
return Objects.equals(either, someone) ? other() : either;
}

V either();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ default T getChild(int index) {
return path;
}

/**
* Returns the depth of this node.
*
* @return depth (0 if the node is the root)
*/
default @NonNull int getDepth() {
int depth = 0;
for (T node = getParent(); node != null; node = node.getParent()) {
depth++;
}
return depth;
}

/**
* Returns an iterable which can iterate through this figure and all its
* descendants in postorder sequence.
Expand Down

0 comments on commit 1a9b831

Please sign in to comment.