Package xbird.util.collections

Examples of xbird.util.collections.IntStack


    public static final byte PERCENT_CODE = 0x0;

    private final IntStack stack;

    public RevPathCoder() {
        this(new IntStack(12));
    }
View Full Code Here


        this.anyPattern = any;
        initPattern(suffix);
    }

    private void initPattern(byte[] p) {
        final IntStack typeStack = new IntStack(12);
        final ArrayList<byte[]> patternStack = new ArrayList<byte[]>();
        final FastMultiByteArrayOutputStream pending = new FastMultiByteArrayOutputStream(32);
        final int ptnlen = p.length;
        for(int i = 0; i < ptnlen; i++) {
            byte c = p[i];
            if(c == anyPattern) {
                if(!typeStack.isEmpty()) {
                    int lastType = typeStack.peek();
                    if(lastType == anyPattern) {
                        continue;
                    }
                }
                if(pending.size() > 0) {
                    typeStack.push(MATCH);
                    patternStack.add(pending.toByteArray());
                    pending.reset();
                }
                typeStack.push(ANY);
                patternStack.add(null);
            } else {
                pending.write(c);
            }
        }
        if(pending.size() > 0) {
            typeStack.push(MATCH);
            patternStack.add(pending.toByteArray());
        }
        this._patterns = patternStack.toArray(new byte[patternStack.size()][]);
        this._types = typeStack.toArray();
    }
View Full Code Here

    private final IntStack types;
    private final Stack<QualifiedName> patterns;

    public XMLPathPattern() {
        this.types = new IntStack(8);
        this.patterns = new Stack<QualifiedName>();
    }
View Full Code Here

    public boolean match(XMLPathPattern other) {
        return match(this, other, 0, 0);
    }

    private static boolean match(final XMLPathPattern verifyPattern, final XMLPathPattern targetPattern, int vi, int oi) {
        final IntStack verifyTypes = verifyPattern.types;
        final Stack<QualifiedName> verifyPatterns = verifyPattern.patterns;
        final IntStack otherTypes = targetPattern.types;
        final Stack<QualifiedName> otherPatterns = targetPattern.patterns;
        final int otherPtnlen = otherPatterns.size();
        final int verifyPtnlen = verifyPatterns.size();

        for(; vi < verifyPtnlen; vi++, oi++) {
            if(oi >= otherPtnlen) {
                return false;
            }
            final int verifyType = verifyTypes.elementAt(vi);
            if((verifyType & MATCH) == MATCH) {
                final int otherType = otherTypes.elementAt(oi);
                if((otherType & MATCH) != MATCH) {
                    throw new IllegalArgumentException("Comparing other pattern must be an AbstractPath"
                            + otherTypes.toString());
                }
                if(verifyType != otherType) {
                    return false;
                }
                if(verifyType == TEXT_MATCH) {
                    continue;
                }
                final QualifiedName otherName = otherPatterns.get(oi);
                final QualifiedName verifyName = verifyPatterns.get(vi);
                if(!verifyName.equals(otherName)) {
                    return false;
                }
            } else if(verifyType == ELEM_WILDCARD) {
                final int otherType = otherTypes.elementAt(oi);
                if((otherType & ELEMENT) != ELEMENT) {
                    return false;
                }
            } else if(verifyType == ATTR_WILDCARD) {
                final int otherType = otherTypes.elementAt(oi);
                if((otherType & ATTRIBUTE) != ATTRIBUTE) {
                    return false;
                }
            } else if(verifyType == SKIPPABLE) {
                if(++vi >= verifyPtnlen) {
View Full Code Here

        initPattern(suffix);
    }

    private void initPattern(String p) {
        final int ptnlen = p.length();
        final IntStack typeStack = new IntStack(12);
        final ArrayList<char[]> patternStack = new ArrayList<char[]>();
        final StringBuilder pending = new StringBuilder(64);
        for(int i = 0; i < ptnlen; i++) {
            char c = p.charAt(i);
            if(c == escapeChar) {
                if(i >= (ptnlen - 1)) {
                    throw new IllegalArgumentException("Illegal like expression: " + p);
                }
                c = p.charAt(++i);
                if(c != '%' && c != '_' && c != escapeChar) {
                    throw new IllegalArgumentException("Illegal like expression: " + p);
                }
                pending.append(c);
            } else if(c == '%') {
                if(!typeStack.isEmpty()) {
                    int lastType = typeStack.peek();
                    if(lastType == '%') {
                        continue;
                    }
                }
                if(pending.length() > 0) {
                    String s = pending.toString();
                    typeStack.push(MATCH);
                    patternStack.add(StringUtils.getChars(s));
                    pending.setLength(0);
                }
                typeStack.push(ANY);
                patternStack.add(null);
            } else if(c == '_') {
                if(pending.length() > 0) {
                    String s = pending.toString();
                    typeStack.push(MATCH);
                    patternStack.add(StringUtils.getChars(s));
                    pending.setLength(0);
                }
                typeStack.push(ONE);
                patternStack.add(null);
            } else {
                pending.append(c);
            }
        }
        if(pending.length() > 0) {
            String s = pending.toString();
            typeStack.push(MATCH);
            patternStack.add(StringUtils.getChars(s));
        }
        this._patterns = patternStack.toArray(new char[patternStack.size()][]);
        this._types = typeStack.toArray();
    }
View Full Code Here

TOP

Related Classes of xbird.util.collections.IntStack

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.