⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 path.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
         *                                  format is invalid         */        public static PathElement fromString(String s) throws IllegalArgumentException {            if (s == null) {                throw new IllegalArgumentException("null PathElement literal");            }            if (s.equals(RootElement.LITERAL)) {                return ROOT_ELEMENT;            } else if (s.equals(CurrentElement.LITERAL)) {                return CURRENT_ELEMENT;            } else if (s.equals(ParentElement.LITERAL)) {                return PARENT_ELEMENT;            }            int pos = s.indexOf('[');            if (pos == -1) {                QName name = QName.valueOf(s);                return new NameElement(name, INDEX_UNDEFINED);            }            QName name = QName.valueOf(s.substring(0, pos));            int pos1 = s.indexOf(']');            if (pos1 == -1) {                throw new IllegalArgumentException("invalid PathElement literal: " + s + " (missing ']')");            }            try {                int index = Integer.valueOf(s.substring(pos + 1, pos1)).intValue();                if (index < 1) {                    throw new IllegalArgumentException("invalid PathElement literal: " + s + " (index is 1-based)");                }                return new NameElement(name, index);            } catch (Throwable t) {                throw new IllegalArgumentException("invalid PathElement literal: " + s + " (" + t.getMessage() + ")");            }        }        /**         * Computes a hash code for this path element.         *         * @return hash code         */        public int hashCode() {            int h = 17;            h = 37 * h + normalizeIndex(index);            h = 37 * h + name.hashCode();            return h;        }        /**         * Check for path element equality. Returns true if the given         * object is a PathElement and contains the same name and index         * as this one.         *         * @param obj the object to compare with         * @return <code>true</code> if the path elements are equal         */        public boolean equals(Object obj) {            if (this == obj) {                return true;            }            if (obj instanceof PathElement) {                PathElement other = (PathElement) obj;                return name.equals(other.name)                        && normalizeIndex(index) == normalizeIndex(other.index);            }            return false;        }        /**         * Normalizes index value {@link Path#INDEX_UNDEFINED} to         * {@link Path#INDEX_DEFAULT} for {@link #equals(Object)} and         * {@link #hashCode()}.         * @param index         * @return normalized index         */        private int normalizeIndex(int index) {            return index == Path.INDEX_UNDEFINED ? Path.INDEX_DEFAULT : index;        }              /**         * Returns <code>true</code> if this element denotes the <i>root</i> element,         * otherwise returns <code>false</code>.         *         * @return <code>true</code> if this element denotes the <i>root</i>         *         element; otherwise <code>false</code>         */        abstract public boolean denotesRoot();        /**         * Returns <code>true</code> if this element denotes the <i>parent</i>         * ('..') element, otherwise returns <code>false</code>.         *         * @return <code>true</code> if this element denotes the <i>parent</i>         *         element; otherwise <code>false</code>         */        abstract public boolean denotesParent();        /**         * Returns <code>true</code> if this element denotes the <i>current</i>         * ('.') element, otherwise returns <code>false</code>.         *         * @return <code>true</code> if this element denotes the <i>current</i>         *         element; otherwise <code>false</code>         */        abstract public boolean denotesCurrent();        /**         * Returns <code>true</code> if this element represents a regular name         * (i.e. neither root, '.' nor '..'), otherwise returns <code>false</code>.         *         * @return <code>true</code> if this element represents a regular name;         *         otherwise <code>false</code>         */        abstract public boolean denotesName();    }    public static final class RootElement extends PathElement {        // use a literal that is an illegal name character to avoid collisions        static final String LITERAL = "*";        private RootElement() {            super(QName.ROOT, Path.INDEX_UNDEFINED);        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesName()         */        public boolean denotesName() {            return false;        }        /**         * Returns true.         *         * @return true         * @see Path.PathElement#denotesRoot()         */        public boolean denotesRoot() {            return true;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesParent()         */        public boolean denotesParent() {            return false;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesCurrent()         */        public boolean denotesCurrent() {            return false;        }        /**         * {@inheritDoc}         * <p/>         * Returns <code>""</code>         * @return <code>""</code>         */        public String toJCRName(NamespaceResolver resolver) {            return "";        }        /**         * {@inheritDoc}         */        public void toJCRName(NamespaceResolver resolver, StringBuffer buf) {            // append empty string, i.e. nothing.        }        /**         * @return {@link #LITERAL}         * @see Object#toString()         */        public String toString() {            return LITERAL;        }    }    public static final class CurrentElement extends PathElement {        static final String LITERAL = ".";        private CurrentElement() {            super(new QName(QName.NS_DEFAULT_URI, LITERAL), Path.INDEX_UNDEFINED);        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesName()         */        public boolean denotesName() {            return false;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesRoot()         */        public boolean denotesRoot() {            return false;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesParent()         */        public boolean denotesParent() {            return false;        }        /**         * Returns true.         *         * @return true         * @see Path.PathElement#denotesCurrent()         */        public boolean denotesCurrent() {            return true;        }        /**         * {@inheritDoc}         * <p/>         * Returns <code>"."</code>         * @return <code>"."</code>         */        public String toJCRName(NamespaceResolver resolver) {            return LITERAL;        }        /**         * {@inheritDoc}         */        public void toJCRName(NamespaceResolver resolver, StringBuffer buf) {            buf.append(LITERAL);        }        /**         * @return {@link #LITERAL}         * @see Object#toString()         */        public String toString() {            return LITERAL;        }    }    public static final class ParentElement extends PathElement {        static final String LITERAL = "..";        private ParentElement() {            super(new QName(QName.NS_DEFAULT_URI, LITERAL), Path.INDEX_UNDEFINED);        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesName()         */        public boolean denotesName() {            return false;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesRoot()         */        public boolean denotesRoot() {            return false;        }        /**         * Returns true.         *         * @return true         * @see Path.PathElement#denotesParent()         */        public boolean denotesParent() {            return true;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesCurrent()         */        public boolean denotesCurrent() {            return false;        }        /**         * {@inheritDoc}         * <p/>         * Returns <code>".."</code>         * @return <code>".."</code>         */        public String toJCRName(NamespaceResolver resolver) {            return LITERAL;        }        /**         * {@inheritDoc}         */        public void toJCRName(NamespaceResolver resolver, StringBuffer buf) {            buf.append(LITERAL);        }        /**         * @return {@link #LITERAL}         * @see Object#toString()         */        public String toString() {            return LITERAL;        }    }    public static final class NameElement extends PathElement {        private NameElement(QName name, int index) {            super(name, index);        }        /**         * Returns true.         *         * @return true         * @see Path.PathElement#denotesName()         */        public boolean denotesName() {            return true;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesRoot()         */        public boolean denotesRoot() {            return false;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesParent()         */        public boolean denotesParent() {            return false;        }        /**         * Returns false.         *         * @return false         * @see Path.PathElement#denotesCurrent()         */        public boolean denotesCurrent() {            return false;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -