All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.qos.logback.core.joran.spi.ElementPath Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
/**
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
 *
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *
 *   or (per the licensee's choosing)
 *
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */
package ch.qos.logback.core.joran.spi;

import java.util.ArrayList;
import java.util.List;

/**
 * A element path characterizes a traversal path in an XML document.
 *
 * @author Ceki Gulcu
 * @since 1.1.0
 */
public class ElementPath {
    // contains String instances
    ArrayList partList = new ArrayList();

    public ElementPath() {
    }

    public ElementPath(List list) {
        partList.addAll(list);
    }

    /**
     * Build an elementPath from a string.
     * 

* Note that "/x" is considered equivalent to "x" and to "x/" */ public ElementPath(String pathStr) { if (pathStr == null) { return; } String[] partArray = pathStr.split("/"); if (partArray == null) return; for (String part : partArray) { if (part.length() > 0) { partList.add(part); } } } public ElementPath duplicate() { ElementPath p = new ElementPath(); p.partList.addAll(this.partList); return p; } // Joran error skipping relies on the equals method @Override public boolean equals(Object o) { if ((o == null) || !(o instanceof ElementPath)) { return false; } ElementPath r = (ElementPath) o; if (r.size() != size()) { return false; } int len = size(); for (int i = 0; i < len; i++) { if (!equalityCheck(get(i), r.get(i))) { return false; } } // if everything matches, then the two patterns are equal return true; } private boolean equalityCheck(String x, String y) { return x.equalsIgnoreCase(y); } public List getCopyOfPartList() { return new ArrayList(partList); } public void push(String s) { partList.add(s); } public String get(int i) { return (String) partList.get(i); } public void pop() { if (!partList.isEmpty()) { partList.remove(partList.size() - 1); } } public String peekLast() { if (!partList.isEmpty()) { int size = partList.size(); return (String) partList.get(size - 1); } else { return null; } } public int size() { return partList.size(); } protected String toStableString() { StringBuilder result = new StringBuilder(); for (String current : partList) { result.append("[").append(current).append("]"); } return result.toString(); } @Override public String toString() { return toStableString(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy