📄 abstractconstraint.java
字号:
/* * File: AbstractConstraint.java * Project: MPI Linguistic Application * Date: 02 May 2007 * * Copyright (C) 2001-2007 Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package mpi.search.content.query.model;import java.util.Enumeration;import java.util.HashMap;import java.util.Vector;import javax.swing.tree.MutableTreeNode;import javax.swing.tree.TreeNode;/** * Super class for AnchorConstraint and DepedentConstraint * * @author Alexander Klassmann * @version November 2004 */public abstract class AbstractConstraint implements Constraint { /** Holds TEMPORAL or STRUCTURAL */ protected String mode = Constraint.TEMPORAL; /** Holds ANY or NONE */ protected String quantifier = Constraint.ANY; /** Holds value of property DOCUMENT ME! */ protected String[] tierNames = new String[0]; /** holds parent node */ private Constraint parent = null; /** Holds value of property DOCUMENT ME! */ private HashMap attributes; /** Holds value of property DOCUMENT ME! */ private String patternString = ""; /** Holds value of property DOCUMENT ME! */ private String unit; /** holds node children of this node */ private Vector children = new Vector(); /** Holds value of property DOCUMENT ME! */ private boolean isCaseSensitive = false; /** Holds value of property DOCUMENT ME! */ private boolean isRegEx = false; /** Holds value of property DOCUMENT ME! */ private long lowerBoundary = Long.MIN_VALUE; /** Holds value of property DOCUMENT ME! */ private long upperBoundary = Long.MAX_VALUE; /** * Creates a new AbstractConstraint object. */ public AbstractConstraint() { } /** * DOCUMENT ME! * * @param tierNames constraint number within a query * @param patternString string/regular expression to be searched * @param lowerBoundary negative number (of units) (e.g. 0, -1, -2, ... -X) * @param upperBoundary positive number (of units) (e.g. 0, 1, 2 ... +X) * @param unit search unit in which should be searched (in respect to * referential constraint) * @param isRegEx string or regular expression ? * @param isCaseSensitive case sensitive string search ? * @param attributes should contain (as strings) attribute names (key) and * values (value) */ public AbstractConstraint(String[] tierNames, String patternString, long lowerBoundary, long upperBoundary, String unit, boolean isRegEx, boolean isCaseSensitive, HashMap attributes) { this.tierNames = tierNames; this.patternString = patternString; this.lowerBoundary = lowerBoundary; this.upperBoundary = upperBoundary; this.unit = unit; this.isRegEx = isRegEx; this.isCaseSensitive = isCaseSensitive; this.attributes = attributes; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean getAllowsChildren() { return true; } /** * DOCUMENT ME! * * @param h DOCUMENT ME! */ public void setAttributes(HashMap h) { attributes = h; } /** * @see mpi.search.content.query.model.Constraint#getAttributes() */ public HashMap getAttributes() { return attributes; } /** * DOCUMENT ME! * * @param b DOCUMENT ME! */ public void setCaseSensitive(boolean b) { isCaseSensitive = b; } /** * @see mpi.search.content.query.model.Constraint#isCaseSensitive() */ public boolean isCaseSensitive() { return isCaseSensitive; } /** * DOCUMENT ME! * * @param i DOCUMENT ME! * * @return DOCUMENT ME! */ public TreeNode getChildAt(int i) { return (MutableTreeNode) children.get(i); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public int getChildCount() { return children.size(); } /** * * * @return DOCUMENT ME! */ public boolean isEditable() { return true; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getId() { return (parent != null) ? (parent.getId() + "." + parent.getIndex(this)) : "C"; } /** * DOCUMENT ME! * * @param node DOCUMENT ME! * * @return DOCUMENT ME! */ public int getIndex(TreeNode node) { return children.indexOf(node); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean isLeaf() { return (getChildCount() == 0); } /** * DOCUMENT ME! * * @param l DOCUMENT ME! */ public void setLowerBoundary(long l) { lowerBoundary = l; } /** * @see mpi.search.content.query.model.Constraint#getLowerBoundary() */ public long getLowerBoundary() { return lowerBoundary; } /** * @see mpi.search.content.query.model.Constraint#getLowerBoundaryAsString() */ public String getLowerBoundaryAsString() { return (lowerBoundary == Long.MIN_VALUE) ? "-X" : ("" + lowerBoundary); } /** * @see mpi.search.content.query.model.Constraint#getMode() */ public String getMode() { return mode; } /** * DOCUMENT ME! * * @param parent DOCUMENT ME! */ public void setParent(MutableTreeNode parent) { this.parent = (Constraint) parent; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public TreeNode getParent() { return parent; } /** * DOCUMENT ME! * * @param s DOCUMENT ME! */ public void setPattern(String s) { patternString = s; } /** * @see mpi.search.content.query.model.Constraint#getPattern() */ public String getPattern() { return patternString; } /** * returns Quantifier like ("ANY" or "NONE") * * @return String */ public String getQuantifier() { return quantifier; } /** * DOCUMENT ME! * * @param b DOCUMENT ME! */ public void setRegEx(boolean b) { isRegEx = b; } /** * @see mpi.search.content.query.model.Constraint#isRegEx() */ public boolean isRegEx() { return isRegEx; } /** * DOCUMENT ME! * * @param s DOCUMENT ME! */ public void setTierName(String s) { tierNames = new String[] { s }; } /** * for Corex compatibility * * @return first element of tierNames[] */ public String getTierName() { return (tierNames.length > 0) ? tierNames[0] : null; } /** * DOCUMENT ME! * * @param s DOCUMENT ME! */ public void setTierNames(String[] s) { tierNames = s; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] getTierNames() { return tierNames; } /** * DOCUMENT ME! * * @param s DOCUMENT ME! */ public void setUnit(String s) { unit = s; } /** * @see mpi.search.content.query.model.Constraint#getUnit() */ public String getUnit() { return unit; } /** * DOCUMENT ME! * * @param l DOCUMENT ME! */ public void setUpperBoundary(long l) { upperBoundary = l; } /** * @see mpi.search.content.query.model.Constraint#getUpperBoundary() */ public long getUpperBoundary() { return upperBoundary; } /** * @see mpi.search.content.query.model.Constraint#getUpperBoundaryAsString() */ public String getUpperBoundaryAsString() { return (upperBoundary == Long.MAX_VALUE) ? "+X" : ("" + upperBoundary); } /** * dummy function; DefaultTreeModel uses it; has further no implication * * @param object DOCUMENT ME! */ public void setUserObject(Object object) { } /** * @see mpi.search.content.query.model.Constraint#addAttribute(String, * String) */ public void addAttribute(String name, String value) { attributes.put(name, value); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public Enumeration children() { return children.elements(); } /** * Overridden to make clone public. Returns a shallow copy of this node; * the new node has no parent or children and has a reference to the same * user object, if any. * * @return a copy of this node */ public Object clone() { AbstractConstraint newConstraint = null; try { newConstraint = (AbstractConstraint) super.clone(); newConstraint.setTierNames(getTierNames()); newConstraint.setPattern(getPattern()); newConstraint.setCaseSensitive(isCaseSensitive()); newConstraint.setRegEx(isRegEx()); newConstraint.setUnit(getUnit()); newConstraint.setLowerBoundary(getLowerBoundary()); newConstraint.setUpperBoundary(getUpperBoundary()); newConstraint.setAttributes(getAttributes()); newConstraint.children = new Vector(); newConstraint.parent = null; } catch (CloneNotSupportedException e) { } return newConstraint; } /** * @see java.lang.Object#equals(Object) */ public boolean equals(Object object) { if (!(object instanceof AbstractConstraint)) { return false; } AbstractConstraint constraint = (AbstractConstraint) object; if (constraint.isCaseSensitive() != isCaseSensitive()) { return false; } if (constraint.isRegEx() != isRegEx()) { return false; } if (!constraint.getPattern().equals(getPattern())) { return false; } if (constraint.getLowerBoundary() != getLowerBoundary()) { return false; } if (constraint.getUpperBoundary() != getUpperBoundary()) { return false; } if (((constraint.getUnit() == null) && (getUnit() != null)) || ((constraint.getUnit() != null) && !constraint.getUnit().equals(getUnit()))) { return false; } if (((constraint.getAttributes() == null) && (constraint.getAttributes() != null)) || ((constraint.getAttributes() != null) && !constraint.getAttributes().equals(getAttributes()))) { return false; } return true; } /** * DOCUMENT ME! * * @param child DOCUMENT ME! * @param index DOCUMENT ME! */ public void insert(MutableTreeNode child, int index) { children.insertElementAt(child, index); child.setParent(this); } /** * DOCUMENT ME! * * @param index DOCUMENT ME! */ public void remove(int index) { MutableTreeNode child = (MutableTreeNode) children.get(index); children.remove(index); child.setParent(null); } /** * DOCUMENT ME! * * @param node DOCUMENT ME! */ public void remove(MutableTreeNode node) { children.remove(node); node.setParent(null); } /** * */ public void removeFromParent() { if (parent != null) { parent.remove(this); } } /** * only for debugging * * @return DOCUMENT ME! */ public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Quantifier:\t" + quantifier + "\n"); for (int i = 0; i < tierNames.length; i++) { sb.append("Tier name:\t" + tierNames[i] + "\n"); } sb.append("Pattern:\t" + patternString + "\n"); sb.append("Unit:\t" + unit + "\n"); sb.append("Lower boundary:\t" + lowerBoundary + "\n"); sb.append("Upper boundary:\t" + upperBoundary + "\n"); return sb.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -