/** * Check if path is empty */ public boolean isEmpty() { return data.size() == 0; }
/** * Get the number of path segments. * * @return */ public int numSegments() { return data.size(); }
/** * Check if path is empty */ public boolean isEmpty() { return data.size() == 0; }
/** * Get the number of path segments. * * @return */ public int numSegments() { return data.size(); }
/** * Get the number of path segments. * * @return */ public int numSegments() { return data.size(); }
/** * Check if path is empty */ public boolean isEmpty() { return data.size() == 0; }
/** * Get path segment at given index starting from the tail of the segment * list. * * @param i * @return the segment data */ public String tail(int i) { return data.get(data.size() - 1 - i); }
/** * Get path segment at given index starting from the tail of the segment * list. * * @param i * @return the segment data */ public String tail(int i) { return data.get(data.size() - 1 - i); }
/** * Get path segment at given index starting from the tail of the segment * list. * * @param i * @return the segment data */ public String tail(int i) { return data.get(data.size() - 1 - i); }
/** * Check if this path matches the path pattern argument passed in. * * @param pattern the pattern path * @return true if it matches, else false */ public boolean matches(Path pattern) { if (data.size() == pattern.data.size()) { Iterator<String> patternDataItr = pattern.data.iterator(); Iterator<String> dataItr = data.iterator(); while (patternDataItr.hasNext() && dataItr.hasNext()) { String pat = patternDataItr.next(); String val = dataItr.next(); if (!(val.equals(pat) || pat.equals(ANY))) { return false; } } return true; } return false; }
/** * Returns a new path that is a suffix of this path obtained by removing -x * elements from the beginning (if x is negative), or selecting x elements * from the end (if x is positive). If the path is a mutable path, the * returned path is a mutable path. */ public Path suffix(final int x) { Path p; if (this instanceof MutablePath) { p = new MutablePath((MutablePath) this); } else { p = new Path(this); } int n = p.data.size(); if (x >= 0) { p.data.shiftLeft(n - Math.min(n, x)); } else { p.data.shiftLeft(Math.min(n, Math.abs(x))); } return p; }
/** * Remove the last path segment from this path. * * @return the updated path */ public MutablePath pop() { try { own(); getData().remove(getData().size() - 1); } catch (IndexOutOfBoundsException e) { throw new IllegalStateException(UtilConstants.ERR_CANT_POP_EMPTY_PATH); } return this; }
/** * Remove the last path segment from this path. * * @return the updated path */ public MutablePath pop() { try { own(); getData().remove(getData().size() - 1); } catch (IndexOutOfBoundsException e) { throw new IllegalStateException(UtilConstants.ERR_CANT_POP_EMPTY_PATH); } return this; }
/** * Remove the last path segment from this path. * * @return the updated path */ public MutablePath pop() { try { own(); getData().remove(getData().size() - 1); } catch (IndexOutOfBoundsException e) { throw new IllegalStateException(UtilConstants.ERR_CANT_POP_EMPTY_PATH); } return this; }
/** * Reduces the length of the path to the given length */ public MutablePath cut(int length) { own(); int l = getData().size(); while (l > length) { getData().remove(--l); } return this; }
/** * Reduces the length of the path to the given length */ public MutablePath cut(int length) { own(); int l = getData().size(); while (l > length) { getData().remove(--l); } return this; }
/** * Reduces the length of the path to the given length */ public MutablePath cut(int length) { own(); int l = getData().size(); while (l > length) { getData().remove(--l); } return this; }
/** * Replace the last path segment with the path supplied. * * @param x the new end of the path * @return the updated path */ public Path setLast(String x) { try { own(); getData().remove(getData().size() - 1); getData().append(parse(x)); return this; } catch (IndexOutOfBoundsException e) { throw new IllegalStateException(UtilConstants.ERR_CANT_SET_LAST_SEGMENT_ON_EMPTY_PATH); } }
/** * Replace the last path segment with the path supplied. * * @param x the new end of the path * @return the updated path */ public Path setLast(String x) { try { own(); getData().remove(getData().size() - 1); getData().append(parse(x)); return this; } catch (IndexOutOfBoundsException e) { throw new IllegalStateException(UtilConstants.ERR_CANT_SET_LAST_SEGMENT_ON_EMPTY_PATH); } }
/** * Replace the last path segment with the path supplied. * * @param x the new end of the path * @return the updated path */ public Path setLast(String x) { try { own(); getData().remove(getData().size() - 1); getData().append(parse(x)); return this; } catch (IndexOutOfBoundsException e) { throw new IllegalStateException(UtilConstants.ERR_CANT_SET_LAST_SEGMENT_ON_EMPTY_PATH); } }