public static Path parse(String path) throws NullPointerException, IllegalArgumentException { boolean absolute = path.length() > 0 && path.charAt(0) == '/'; String[] atoms = Lexers.parsePath(Lexers.PARSE_CANONICAL, EMPTY_STRING_ARRAY, 0, path, 0); if (absolute) { return new Absolute(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); } else { return new Relative(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); } }
public static Path parse(String path) throws NullPointerException, IllegalArgumentException { boolean absolute = path.length() > 0 && path.charAt(0) == '/'; String[] atoms = Lexers.parsePath(Lexers.PARSE_CANONICAL, EMPTY_STRING_ARRAY, 0, path, 0); if (absolute) { return new Absolute(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); } else { return new Relative(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); } }
public Name subName(int l) throws IllegalArgumentException { if (l < 0) { throw new IllegalArgumentException("No negative argument " + l + " accepted"); } else if (l == 0) { return this; } else { int remaining = size - l; if (remaining < 0) { throw new IllegalArgumentException("Argument " + l + " can't be greater than size " + size); } else if (remaining == 0) { return EMPTY; } else { String[] identifiers = new String[remaining]; System.arraycopy(this.identifiers, l, identifiers, 0, remaining); return new Name(identifiers); } } }
public Name subName(int l) throws IllegalArgumentException { if (l < 0) { throw new IllegalArgumentException("No negative argument " + l + " accepted"); } else if (l == 0) { return this; } else { int remaining = size - l; if (remaining < 0) { throw new IllegalArgumentException("Argument " + l + " can't be greater than size " + size); } else if (remaining == 0) { return EMPTY; } else { String[] identifiers = new String[remaining]; System.arraycopy(this.identifiers, l, identifiers, 0, remaining); return new Name(identifiers); } } }
public Path as(String rawName, String ext) { String[] tmp = new String[name.size]; System.arraycopy(name.identifiers, 0, tmp, 0, name.size - 1); tmp[tmp.length - 1] = rawName; return create(new Name(tmp, tmp.length), ext); }
public Path.Absolute resolve(String path) { String[] atoms = Lexers.parsePath(Lexers.PARSE_ANY, identifiers, size, path, 0); return new Path.Absolute(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); }
public Path as(String rawName, String ext) { String[] tmp = new String[name.size]; System.arraycopy(name.identifiers, 0, tmp, 0, name.size - 1); tmp[tmp.length - 1] = rawName; return create(new Name(tmp, tmp.length), ext); }
public Name getParent() { if (parent == null) { if (size == 1) { parent = EMPTY; } else if (size() > 1) { parent = new Name(value.substring(0, value.length() - 1 - identifiers[size - 1].length()), identifiers, size - 1); } } return parent; }
public Name getParent() { if (parent == null) { if (size == 1) { parent = EMPTY; } else if (size() > 1) { parent = new Name(value.substring(0, value.length() - 1 - identifiers[size - 1].length()), identifiers, size - 1); } } return parent; }
public Path.Absolute resolve(String path) { String[] atoms = Lexers.parsePath(Lexers.PARSE_ANY, identifiers, size, path, 0); return new Path.Absolute(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); }
/** * Returns the common prefix between this qualified name and the provided qualified name. * * @param name the qualified name * @return the common prefix */ public Name getPrefix(Name name) { int size = Math.min(this.size, name.size); int a = 0; int len = 0; for (int i = 0;i < size;i++) { if (!identifiers[i].equals(name.identifiers[i])) { break; } else { a++; if (i > 0) { len++; } len += identifiers[i].length(); } } return a == this.size ? this : new Name(value.substring(0, len), identifiers, a); }
/** * Returns the common prefix between this qualified name and the provided qualified name. * * @param name the qualified name * @return the common prefix */ public Name getPrefix(Name name) { int size = Math.min(this.size, name.size); int a = 0; int len = 0; for (int i = 0;i < size;i++) { if (!identifiers[i].equals(name.identifiers[i])) { break; } else { a++; if (i > 0) { len++; } len += identifiers[i].length(); } } return a == this.size ? this : new Name(value.substring(0, len), identifiers, a); }
/** * Parse the name. * * @param s the char sequence to parse * @param from the index of the first char of the name * @param end the index of the char after the last char of the name * @return the name * @throws IllegalArgumentException if the name is not valid */ public static Name parse(CharSequence s, int from, int end) throws IllegalArgumentException { if (end > s.length()) { throw new IllegalArgumentException("End bound " + end + " cannot be greater than the sequence length " + s.length()); } String[] segments = Lexers.parseName(s, from, end); if (segments.length == 0) { return EMPTY; } else { return new Name(s.subSequence(from, end).toString(), segments); } }
public Path append(String path) throws NullPointerException, IllegalArgumentException { if (path == null) { throw new NullPointerException("No null path accepted"); } if (path.length() > 0 && path.charAt(0) == '/') { throw new IllegalArgumentException("Cannot append absolute path " + path); } String[] atoms = Lexers.parsePath(Lexers.PARSE_ANY, name.identifiers, name.size - 1, path, 0); return create(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); }
public Path append(String path) throws NullPointerException, IllegalArgumentException { if (path == null) { throw new NullPointerException("No null path accepted"); } if (path.length() > 0 && path.charAt(0) == '/') { throw new IllegalArgumentException("Cannot append absolute path " + path); } String[] atoms = Lexers.parsePath(Lexers.PARSE_ANY, name.identifiers, name.size - 1, path, 0); return create(new Name(atoms, atoms.length - 1), atoms[atoms.length - 1]); }
private Name append(String[] suffixIdentifiers, int suffixSize) throws NullPointerException, IllegalArgumentException { if (size == 0) { return this; } else { String[] tmp = new String[size + suffixSize]; System.arraycopy(identifiers, 0, tmp, 0, this.size); System.arraycopy(suffixIdentifiers, 0, tmp, this.size, suffixSize); int len = value.length(); for (int i = 0;i < suffixSize;i++) { if (suffixIdentifiers[i] == null) { throw new IllegalArgumentException("Cannot accept null suffix segment"); } if (suffixIdentifiers[i].isEmpty()) { throw new IllegalArgumentException("Cannot accept empty suffix segment"); } if (suffixIdentifiers[i].indexOf('.') != -1) { throw new IllegalArgumentException("Cannot accept '.' in suffix segment"); } len += 1 + suffixIdentifiers[i].length(); } StringBuilder sb = new StringBuilder(len).append(value); for (int i = 0;i < suffixSize;i++) { sb.append('.').append(suffixIdentifiers[i]); } return new Name(sb.toString(), tmp, tmp.length); } }
/** * Parse the name. * * @param s the char sequence to parse * @param from the index of the first char of the name * @param end the index of the char after the last char of the name * @return the name * @throws IllegalArgumentException if the name is not valid */ public static Name parse(CharSequence s, int from, int end) throws IllegalArgumentException { if (end > s.length()) { throw new IllegalArgumentException("End bound " + end + " cannot be greater than the sequence length " + s.length()); } String[] segments = Lexers.parseName(s, from, end); if (segments.length == 0) { return EMPTY; } else { return new Name(s.subSequence(from, end).toString(), segments); } }
private Name append(String[] suffixIdentifiers, int suffixSize) throws NullPointerException, IllegalArgumentException { if (size == 0) { return this; } else { String[] tmp = new String[size + suffixSize]; System.arraycopy(identifiers, 0, tmp, 0, this.size); System.arraycopy(suffixIdentifiers, 0, tmp, this.size, suffixSize); int len = value.length(); for (int i = 0;i < suffixSize;i++) { if (suffixIdentifiers[i] == null) { throw new IllegalArgumentException("Cannot accept null suffix segment"); } if (suffixIdentifiers[i].isEmpty()) { throw new IllegalArgumentException("Cannot accept empty suffix segment"); } if (suffixIdentifiers[i].indexOf('.') != -1) { throw new IllegalArgumentException("Cannot accept '.' in suffix segment"); } len += 1 + suffixIdentifiers[i].length(); } StringBuilder sb = new StringBuilder(len).append(value); for (int i = 0;i < suffixSize;i++) { sb.append('.').append(suffixIdentifiers[i]); } return new Name(sb.toString(), tmp, tmp.length); } }