Author: tfmorris
Date: 2008-08-18 14:41:39-0700
New Revision: 15579
Added:
trunk/src/argouml-app/src/org/argouml/uml/PredicateSearch.java (contents, props changed)
trunk/src/argouml-app/src/org/argouml/util/ChildGenerator.java (contents, props changed)
trunk/src/argouml-app/src/org/argouml/util/Predicate.java (contents, props changed)
trunk/src/argouml-app/src/org/argouml/util/PredicateEquals.java (contents, props changed)
trunk/src/argouml-app/src/org/argouml/util/PredicateGefWrapper.java (contents, props changed)
trunk/src/argouml-app/src/org/argouml/util/PredicateStringMatch.java (contents, props changed)
trunk/src/argouml-app/src/org/argouml/util/PredicateTrue.java (contents, props changed)
trunk/src/argouml-app/src/org/argouml/util/PredicateType.java (contents, props changed)
Modified:
trunk/src/argouml-app/src/org/argouml/cognitive/ListSet.java
trunk/src/argouml-app/src/org/argouml/cognitive/checklist/CheckItem.java
trunk/src/argouml-app/src/org/argouml/uml/PredicateFind.java
trunk/src/argouml-app/tests/org/argouml/cognitive/checklist/TestCheckItem.java
Log:
Issue 5325: Create public API for Find/Search which doesn't expose internals (GEF). Additional work required to use the newly created API and to do similar work for Predicate usage in Cognitive subsystem.
Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ListSet.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ListSet.java?view=diff&rev=15579&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ListSet.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ListSet.java&r1=15578&r2=15579
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/cognitive/ListSet.java (original)
+++ trunk/src/argouml-app/src/org/argouml/cognitive/ListSet.java 2008-08-18 14:41:39-0700
@@ -34,29 +34,19 @@
import java.util.Set;
import java.util.Vector;
-import org.tigris.gef.util.ChildGenerator;
-import org.tigris.gef.util.Predicate;
-import org.tigris.gef.util.PredicateTrue;
-
/**
* An Ordered, non-duplicated collection of objects (not exactly a
- * mathemetical set because it is ordered).
+ * mathematical set because it is ordered).
*
* @param <T> The type of objects this ListSet is to contain.
*/
public class ListSet<T extends Object>
implements Serializable, Set<T>, List<T> {
- ////////////////////////////////////////////////////////////////
- // constants
+
private static final int TC_LIMIT = 50;
- ////////////////////////////////////////////////////////////////
- // instance variables
private List<T> list;
- ////////////////////////////////////////////////////////////////
- // constructors
-
/**
* The constructor.
*/
@@ -129,9 +119,13 @@
/**
* @param iter an iterator of objects to be added
* @param p the predicate the objects have to fulfill to be added
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #addAllElementsSuchThat(Iterator, org.argouml.util.Predicate)}.
*/
- public void addAllElementsSuchThat(Iterator<T> iter, Predicate p) {
- if (p instanceof PredicateTrue) {
+ @Deprecated
+ public void addAllElementsSuchThat(Iterator<T> iter,
+ org.tigris.gef.util.Predicate p) {
+ if (p instanceof org.tigris.gef.util.PredicateTrue) {
addAllElements(iter);
} else {
while (iter.hasNext()) {
@@ -144,6 +138,24 @@
}
/**
+ * @param iter an iterator of objects to be added
+ * @param p the predicate the objects have to fulfill to be added
+ */
+ public void addAllElementsSuchThat(Iterator<T> iter,
+ org.argouml.util.Predicate p) {
+ if (p instanceof org.argouml.util.PredicateTrue) {
+ addAllElements(iter);
+ } else {
+ while (iter.hasNext()) {
+ T e = iter.next();
+ if (p.evaluate(e)) {
+ add(e);
+ }
+ }
+ }
+ }
+
+ /**
* @param s a listset of objects to be added
* @deprecated for 0.25.4 by tfmorris. Use {@link #addAll(Collection)}.
*/
@@ -155,11 +167,25 @@
/**
* @param s a listset of objects to be added
* @param p the predicate the objects have to fulfill to be added
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #addAllElementsSuchThat(ListSet, org.argouml.util.Predicate)}.
*/
- public void addAllElementsSuchThat(ListSet<T> s, Predicate p) {
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public void addAllElementsSuchThat(ListSet<T> s,
+ org.tigris.gef.util.Predicate p) {
addAllElementsSuchThat(s.iterator(), p);
}
+ /**
+ * @param s a listset of objects to be added
+ * @param p the predicate the objects have to fulfill to be added
+ */
+ public void addAllElementsSuchThat(ListSet<T> s,
+ org.argouml.util.Predicate p) {
+ addAllElementsSuchThat(s.iterator(), p);
+ }
+
/*
* @see java.util.Collection#remove(java.lang.Object)
*/
@@ -200,19 +226,34 @@
/**
* @param p the predicate the objects have to fulfill
* @return true if at least one object in the listset fulfills the predicate
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #containsSuchThat(org.argouml.util.Predicate)}.
*/
- public boolean containsSuchThat(Predicate p) {
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public boolean containsSuchThat(org.tigris.gef.util.Predicate p) {
return findSuchThat(p) != null;
}
/**
+ * @param p the predicate the objects have to fulfill
+ * @return true if at least one object in the listset fulfills the predicate
+ */
+ public boolean containsSuchThat(org.argouml.util.Predicate p) {
+ return findSuchThat(p) != null;
+ }
+
+ /**
* Return the first object that causes the given predicate to return
* true.
*
* @param p the predicate the objects have to fulfill
* @return the found object or null
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #findSuchThat(org.argouml.util.Predicate)}.
*/
- public Object findSuchThat(Predicate p) {
+ @Deprecated
+ public Object findSuchThat(org.tigris.gef.util.Predicate p) {
for (Object o : list) {
if (p.predicate(o)) {
return o;
@@ -221,6 +262,23 @@
return null;
}
+
+ /**
+ * Return the first object that causes the given predicate to return
+ * true.
+ *
+ * @param p the predicate the objects have to fulfill
+ * @return the found object or null
+ */
+ public Object findSuchThat(org.argouml.util.Predicate p) {
+ for (Object o : list) {
+ if (p.evaluate(o)) {
+ return o;
+ }
+ }
+ return null;
+ }
+
/**
* @return all the objects as enumeration
* @deprecated for 0.25.4 by tfmorris. Use {@link #iterator()}.
@@ -244,9 +302,14 @@
/**
* @param iter an enumeration of objects to be added
* @param p the predicate the objects have to fulfill to be added
+ * @deprecated for 02.6 by tfmorris. Use
+ * {@link #addAllElementsSuchThat(Iterator, org.argouml.util.Predicate)} or
+ * {@link #addAllElementsSuchThat(ListSet, org.argouml.util.Predicate)}.
*/
- public void addAllElementsSuchThat(Enumeration<T> iter, Predicate p) {
- if (p instanceof PredicateTrue) {
+ @Deprecated
+ public void addAllElementsSuchThat(Enumeration<T> iter,
+ org.tigris.gef.util.Predicate p) {
+ if (p instanceof org.tigris.gef.util.PredicateTrue) {
addAllElements(iter);
} else {
while (iter.hasMoreElements()) {
@@ -258,6 +321,7 @@
}
}
+
/**
* @return all the objects as vector
* @deprecated for 0.25.4 by tfmorris. Use List methods instead of Vector
@@ -274,6 +338,7 @@
* This will result in rather bad performance but at least we will
* not violate the contract together with {@link #equals(Object)}.
*/
+ @Override
public int hashCode() {
return 0;
}
@@ -336,29 +401,71 @@
* Set. In order to avoid very deep searches which are often
* programming mistakes, only paths of length TC_LIMIT or less are
* considered.
- *
+ *
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #transitiveClosure(org.argouml.util.ChildGenerator)}.
* @param cg the given childgenerator
* @return the resulting listset
*/
- public ListSet<T> transitiveClosure(ChildGenerator cg) {
- return transitiveClosure(cg, TC_LIMIT, PredicateTrue.theInstance());
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public ListSet<T> transitiveClosure(org.tigris.gef.util.ChildGenerator cg) {
+ return transitiveClosure(cg, TC_LIMIT,
+ org.tigris.gef.util.PredicateTrue.theInstance());
}
/**
+ * Reply the Set of all objects that can be reached from the receiving Set
+ * by taking steps defined by the given ChildGenerator. The result includes
+ * the elements of the original Set. In order to avoid very deep searches
+ * which are often programming mistakes, only paths of length TC_LIMIT or
+ * less are considered.
+ *
+ * @param cg the given childgenerator
+ * @return the resulting listset
+ */
+ public ListSet<T> transitiveClosure(org.argouml.util.ChildGenerator cg) {
+ return transitiveClosure(cg, TC_LIMIT,
+ org.argouml.util.PredicateTrue.getInstance());
+ }
+
+ /**
* Reply the Set of all objects that can be reached from the
* receiving Set by taking steps defined by the given
* ChildGenerator. The result DOES NOT include the elements of the
* original Set. In order to avoid very deep searches which are
* often programming mistakes, only paths of length TC_LIMIT or less
* are considered.
- *
+ *
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #reachable(org.argouml.util.ChildGenerator)}.
+ *
+ * @param cg the given childgenerator
+ * @return the resulting listset
+ */
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public ListSet<T> reachable(org.tigris.gef.util.ChildGenerator cg) {
+ return reachable(cg, TC_LIMIT,
+ org.tigris.gef.util.PredicateTrue.theInstance());
+ }
+
+ /**
+ * Reply the Set of all objects that can be reached from the receiving Set
+ * by taking steps defined by the given ChildGenerator. The result DOES NOT
+ * include the elements of the original Set. In order to avoid very deep
+ * searches which are often programming mistakes, only paths of length
+ * TC_LIMIT or less are considered.
+ *
* @param cg the given childgenerator
* @return the resulting listset
*/
- public ListSet<T> reachable(ChildGenerator cg) {
- return reachable(cg, TC_LIMIT, PredicateTrue.theInstance());
+ public ListSet<T> reachable(org.argouml.util.ChildGenerator cg) {
+ return reachable(cg, TC_LIMIT,
+ org.argouml.util.PredicateTrue.getInstance());
}
+
/**
* Reply the Set of all objects that can be reached from the
* receiving Set by taking steps defined by the given
@@ -367,19 +474,50 @@
* often programming mistakes, only paths of given max length or
* less are considered. Only paths consisting of elements which all
* cause p.predicate() to return true are considered.
- *
+ *
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #reachable(org.argouml.util.ChildGenerator, int,
+ * org.argouml.util.Predicate)}.
+ *
* @param cg the given childgenerator
* @param max the maximum depth
* @param p the predicate the objects have to fulfill
* @return the resulting listset
*/
- public ListSet<T> reachable(ChildGenerator cg, int max, Predicate p) {
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public ListSet<T> reachable(org.tigris.gef.util.ChildGenerator cg, int max,
+ org.tigris.gef.util.Predicate p) {
ListSet<T> kids = new ListSet<T>();
for (Object r : list) {
kids.addAllElementsSuchThat(cg.gen(r), p);
}
return kids.transitiveClosure(cg, max, p);
}
+
+
+ /**
+ * Reply the Set of all objects that can be reached from the receiving Set
+ * by taking steps defined by the given ChildGenerator. The result DOES NOT
+ * include the elements of the original Set. In order to avoid very deep
+ * searches which are often programming mistakes, only paths of given max
+ * length or less are considered. Only paths consisting of elements which
+ * all cause predicate.evaluate() to return true are considered.
+ *
+ * @param cg the given childgenerator
+ * @param max the maximum depth
+ * @param predicate the predicate the objects have to fulfill
+ * @return the resulting listset
+ */
+ public ListSet<T> reachable(org.argouml.util.ChildGenerator cg, int max,
+ org.argouml.util.Predicate predicate) {
+ ListSet<T> kids = new ListSet<T>();
+ for (Object r : list) {
+ kids.addAllElementsSuchThat(cg.childIterator(r), predicate);
+ }
+ return kids.transitiveClosure(cg, max, predicate);
+ }
+
/**
* Reply the Set of all objects that can be reached from the
@@ -390,16 +528,20 @@
* considered. Only paths consisting of elements which all cause
* p.predicate() to return true are considered.
*
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #transitiveClosure(org.argouml.util.ChildGenerator, int,
+ * org.argouml.util.Predicate)}.
+ *
* @param cg the given childgenerator
* @param max the maximum depth
* @param p the predicate the objects have to fulfill
* @return the resulting listset
- *
- * TODO: This shouldn't depend on GEF. Replace ChildGenerator in this API.
- * - tfm 20070630
*/
- public ListSet<T> transitiveClosure(ChildGenerator cg, int max,
- Predicate p) {
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public ListSet<T> transitiveClosure(org.tigris.gef.util.ChildGenerator cg,
+ int max,
+ org.tigris.gef.util.Predicate p) {
int iterCount = 0;
int lastSize = -1;
ListSet<T> touched = new ListSet<T>();
@@ -421,6 +563,43 @@
return touched;
}
+
+ /**
+ * Reply the Set of all objects that can be reached from the receiving Set
+ * by taking steps defined by the given ChildGenerator. The result includes
+ * the elements of the original Set. In order to avoid very deep searches
+ * which are often programming mistakes, only paths of given max length or
+ * less are considered. Only paths consisting of elements which all cause
+ * predicate.evaluate() to return true are considered.
+ *
+ * @param cg the given childgenerator
+ * @param max the maximum depth
+ * @param predicate the predicate the objects have to fulfill
+ * @return the resulting listset
+ */
+ public ListSet<T> transitiveClosure(org.argouml.util.ChildGenerator cg,
+ int max, org.argouml.util.Predicate predicate) {
+ int iterCount = 0;
+ int lastSize = -1;
+ ListSet<T> touched = new ListSet<T>();
+ ListSet<T> frontier;
+ ListSet<T> recent = this;
+
+ touched.addAll(this);
+ while ((iterCount < max) && (touched.size() > lastSize)) {
+ iterCount++;
+ lastSize = touched.size();
+ frontier = new ListSet<T>();
+ for (T recentElement : recent) {
+ Iterator frontierChildren = cg.childIterator(recentElement);
+ frontier.addAllElementsSuchThat(frontierChildren, predicate);
+ }
+ touched.addAll(frontier);
+ recent = frontier;
+ }
+ return touched;
+ }
+
/*
* @see java.util.Collection#isEmpty()
*/
Modified: trunk/src/argouml-app/src/org/argouml/cognitive/checklist/CheckItem.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/checklist/CheckItem.java?view=diff&rev=15579&p1=trunk/src/argouml-app/src/org/argouml/cognitive/checklist/CheckItem.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/checklist/CheckItem.java&r1=15578&r2=15579
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/cognitive/checklist/CheckItem.java (original)
+++ trunk/src/argouml-app/src/org/argouml/cognitive/checklist/CheckItem.java 2008-08-18 14:41:39-0700
@@ -25,14 +25,16 @@
package org.argouml.cognitive.checklist;
import java.io.Serializable;
-import org.tigris.gef.util.Predicate;
-import org.tigris.gef.util.PredicateTrue;
+
+import org.argouml.util.Predicate;
+import org.argouml.util.PredicateGefWrapper;
+import org.argouml.util.PredicateTrue;
/**
* This class defines an item that can be placed on a Checklist.
* This is a short piece of text to prompt the designer to think of a
- * specific design issue. CheckItems are similiar to critics in that
+ * specific design issue. CheckItems are similar to critics in that
* they are categorized to be relevant to issues the designer is
* interested in, they have a guarding condition that returns true if
* the CheckItem should be presented, and they have a piece of text
@@ -52,8 +54,6 @@
* @author jrobbins
*/
public class CheckItem implements Serializable {
- ////////////////////////////////////////////////////////////////
- // instance variables
private String category;
@@ -72,10 +72,8 @@
* The predicate is the condition under which
* the checkitem should be listed.
*/
- private Predicate pred = PredicateTrue.theInstance();
+ private Predicate predicate = PredicateTrue.getInstance();
- ////////////////////////////////////////////////////////////////
- // constructors
/**
* The constructor.
@@ -95,15 +93,32 @@
* @param d the description
* @param m the more-info-url
* @param p the predicate
+ *
+ * @deprecated for 0.26 by tfmorris. Use
+ * {@link #CheckItem(String, String, String, Predicate)}.
*/
- public CheckItem(String c, String d, String m, Predicate p) {
+ public CheckItem(String c, String d, String m,
+ org.tigris.gef.util.Predicate p) {
this(c, d);
setMoreInfoURL(m);
- pred = p;
+ predicate = new PredicateGefWrapper(p);
}
- ////////////////////////////////////////////////////////////////
- // accessors
+
+ /**
+ * The constructor.
+ *
+ * @param c the category
+ * @param d the description
+ * @param m the more-info-url
+ * @param p the predicate
+ */
+ public CheckItem(String c, String d, String m,
+ Predicate p) {
+ this(c, d);
+ setMoreInfoURL(m);
+ predicate = p;
+ }
/**
* @return the category
@@ -143,18 +158,43 @@
public void setMoreInfoURL(String m) { moreInfoURL = m; }
/**
+ * @return the GEF predicate
+ * @deprecated for 0.26 by tfmorris. Use {@link #getPredicate2()}.
+ */
+ @Deprecated
+ public org.tigris.gef.util.Predicate getPredicate() {
+ if (predicate instanceof PredicateGefWrapper) {
+ return ((PredicateGefWrapper) predicate).getGefPredicate();
+ }
+ throw new IllegalStateException("Mixing legacy API and new API is not"
+ + "supported. Please update your code.");
+ }
+
+ /**
* @return the predicate
*/
- public Predicate getPredicate() { return pred; }
+ public Predicate getPredicate2() {
+ return predicate;
+ }
/**
* @param p the predicate
*/
- public void setPredicate(Predicate p) { pred = p; }
+ public void setPredicate(org.tigris.gef.util.Predicate p) {
+ predicate = new PredicateGefWrapper(p);
+ }
+ /**
+ * @param p the predicate
+ */
+ public void setPredicate(Predicate p) {
+ predicate = p;
+ }
+
/*
* @see java.lang.Object#hashCode()
*/
+ @Override
public int hashCode() {
return getDescription().hashCode();
}
@@ -162,6 +202,7 @@
/*
* @see java.lang.Object#equals(java.lang.Object)
*/
+ @Override
public boolean equals(Object o) {
if (!(o instanceof CheckItem)) {
return false;
@@ -173,6 +214,7 @@
/*
* @see java.lang.Object#toString()
*/
+ @Override
public String toString() { return getDescription(); }
/**
@@ -186,4 +228,4 @@
*/
public String expand(String desc, Object dm) { return desc; }
-} /* end class CheckItem */
+}
Modified: trunk/src/argouml-app/src/org/argouml/uml/PredicateFind.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/PredicateFind.java?view=diff&rev=15579&p1=trunk/src/argouml-app/src/org/argouml/uml/PredicateFind.java&p2=trunk/src/argouml-app/src/org/argouml/uml/PredicateFind.java&r1=15578&r2=15579
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/PredicateFind.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/PredicateFind.java 2008-08-18 14:41:39-0700
@@ -32,6 +32,8 @@
/**
* Class to find out if a given object fulfills certain given predicates.
*
+ * @deprecated for 0.26 by tfmorris. Use {@link PredicateSearch} which has an
+ * API that doesn't depend on GEF.
*/
public class PredicateFind implements Predicate {
Added: trunk/src/argouml-app/src/org/argouml/uml/PredicateSearch.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/PredicateSearch.java?view=auto&rev=15579
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/uml/PredicateSearch.java 2008-08-18 14:41:39-0700
@@ -0,0 +1,100 @@
+// $Id$
+// Copyright (c) 2000-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.uml;
+
+import org.argouml.model.Model;
+import org.argouml.uml.diagram.ArgoDiagram;
+import org.argouml.util.Predicate;
+import org.argouml.util.PredicateTrue;
+
+/**
+ * Class to find out if a given object fulfills certain given predicates. This
+ * replaces {@link PredicateFind} by 1sturm with an implementation using the
+ * new GEF-free interfaces.
+ *
+ * @author 1sturm
+ * @author Tom Morris
+ */
+public class PredicateSearch implements Predicate {
+
+ private Predicate elementName;
+ private Predicate packageName;
+ private Predicate diagramName;
+ private Predicate theType;
+
+ private Predicate specific = PredicateTrue.getInstance();
+
+ /**
+ * The constructor.
+ *
+ * @param elementNamePredicate Predicate for the element name
+ * @param packageNamePredicate Predicate for the package name
+ * @param diagramNamePredicate Predicate for the diagram name
+ * @param typePredicate Predicate for the type
+ */
+ public PredicateSearch(Predicate elementNamePredicate,
+ Predicate packageNamePredicate, Predicate diagramNamePredicate,
+ Predicate typePredicate) {
+ elementName = elementNamePredicate;
+ packageName = packageNamePredicate;
+ diagramName = diagramNamePredicate;
+ theType = typePredicate;
+ }
+
+ /**
+ * @param diagram the given diagram
+ * @return true if the name of the given diagram equals
+ */
+ public boolean matchDiagram(ArgoDiagram diagram) {
+ return matchDiagram(diagram.getName());
+ }
+
+
+ /**
+ * @param name the name to match
+ * @return true if the name of the given diagram equals
+ */
+ public boolean matchDiagram(String name) {
+ return diagramName.evaluate(name);
+ }
+
+ /**
+ * @param pkg the given package
+ * @return true if the name of the given package is equal
+ */
+ public boolean matchPackage(Object pkg) {
+ boolean res = packageName.evaluate(Model.getFacade().getName(pkg));
+ return res;
+ }
+
+ public boolean evaluate(Object element) {
+ if (!(Model.getFacade().isAUMLElement(element))) {
+ return false;
+ }
+ Object me = element;
+ return theType.evaluate(me) && specific.evaluate(me)
+ && elementName.evaluate(Model.getFacade().getName(me));
+ }
+}
\ No newline at end of file
Added: trunk/src/argouml-app/src/org/argouml/util/ChildGenerator.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/util/ChildGenerator.java?view=auto&rev=15579
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/util/ChildGenerator.java 2008-08-18 14:41:39-0700
@@ -0,0 +1,52 @@
+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.util;
+
+import java.util.Iterator;
+
+/**
+ * Interface used in {@link org.argouml.cognitive.ListSet} to compute transitive
+ * closures. it is based on the GEF interface of the same name by Jason Robbins
+ * {@link org.tigris.gef.util.ChildGenerator}, but uses an Iterator instead of
+ * an Enumeration for better compatibility with Collections.
+ * <p>
+ * The iterator method is given a unique name to allow it to be used in
+ * combination with other interfaces of a similar style, but if a class only
+ * implements this interface, it may want to implement {@link Iterable} for
+ * greater usage convenience and make this the default iterator.
+ *
+ * @author Tom Morris
+ */
+public interface ChildGenerator {
+
+ /**
+ * Get an Iterator which iterates through the children of the given object
+ *
+ * @param parent the parent of the children to be iterated through
+ * @return an iterator for the children of the given parent
+ */
+ public Iterator childIterator(Object parent);
+
+}
Added: trunk/src/argouml-app/src/org/argouml/util/Predicate.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/util/Predicate.java?view=auto&rev=15579
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/util/Predicate.java 2008-08-18 14:41:39-0700
@@ -0,0 +1,44 @@
+// $Id$
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.util;
+
+/**
+ * Interface for objects that act as predicate functions. Based on
+ * {@link gef.util.Predicate} by Jason Robbins, but uses <code>evaluate</code>
+ * instead of <code>predicate</code> for better compatibility with other
+ * implementations.
+ *
+ * @author Tom Morris
+ */
+public interface Predicate {
+
+ /**
+ * Evaluate the predicate for the given object and return true or false.
+ *
+ * @param object object to be tested
+ * @return boolean indicating whether predicate evaluated true or false.
+ */
+ public boolean evaluate(Object object);
+}
Added: trunk/src/argouml-app/src/org/argouml/util/PredicateEquals.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/util/PredicateEquals.java?view=auto&rev=15579
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/util/PredicateEquals.java 2008-08-18 14:41:39-0700
@@ -0,0 +1,51 @@
+// $Id$
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.util;
+
+/**
+ * A predicate which uses the Java equals operator to compare a pattern object
+ * with a candidate object. Based on the org.gef.util class of the same name.
+ */
+public class PredicateEquals implements Predicate {
+
+ private Object pattern;
+
+ /**
+ * Construct a new predicate which will test equality against the given
+ * pattern object using the Java equals method.
+ *
+ * @param patternObject the object to test for equality with.
+ */
+ public PredicateEquals(Object patternObject) {
+ pattern = patternObject;
+ }
+
+ public boolean evaluate(Object object) {
+ if (pattern == null) {
+ return object == null;
+ }
+ return pattern.equals(object);
+ }
+}
Added: trunk/src/argouml-app/src/org/argouml/util/PredicateGefWrapper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/util/PredicateGefWrapper.java?view=auto&rev=15579
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/util/PredicateGefWrapper.java 2008-08-18 14:41:39-0700
@@ -0,0 +1,53 @@
+// $Id$
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.util;
+
+/**
+ * A Predicate which wraps an old style GEF predicate for compatibility during
+ * the transition period. <em>Not to be used for new implementations</em>.
+ *
+ * @author Tom Morris <[email protected]>
+ */
+public class PredicateGefWrapper implements Predicate {
+
+ private org.tigris.gef.util.Predicate predicate;
+
+ /**
+ * Construct a new Predicate which evaluates the given GEF predication.
+ *
+ * @param gefPredicate predicate to be evaluated
+ */
+ public PredicateGefWrapper(org.tigris.gef.util.Predicate gefPredicate) {
+ predicate = gefPredicate;
+ }
+
+ public boolean evaluate(Object object) {
+ return predicate.predicate(object);
+ }
+
+ public org.tigris.gef.util.Predicate getGefPredicate() {
+ return predicate;
+ }
+}
Added: trunk/src/argouml-app/src/org/argouml/util/PredicateStringMatch.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/util/PredicateStringMatch.java?view=auto&rev=15579
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/util/PredicateStringMatch.java 2008-08-18 14:41:39-0700
@@ -0,0 +1,87 @@
+// $Id$
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.util;
+
+import java.util.StringTokenizer;
+
+public class PredicateStringMatch implements Predicate {
+
+ public static int MAX_PATS = 10;
+
+ private String patterns[];
+
+ private int patternCount;
+
+ protected PredicateStringMatch(String matchPatterns[], int count) {
+ patterns = matchPatterns;
+ patternCount = count;
+ }
+
+ public static Predicate create(String pattern) {
+ pattern = pattern.trim();
+ String pats[] = new String[MAX_PATS];
+ int count = 0;
+ if (pattern.startsWith("*")) {
+ pats[count++] = "";
+ }
+ StringTokenizer st = new StringTokenizer(pattern, "*");
+ while (st.hasMoreElements()) {
+ String token = st.nextToken();
+ pats[count++] = token;
+ }
+ if (pattern.endsWith("*")) {
+ pats[count++] = "";
+ }
+ if (count == 0) {
+ return PredicateTrue.getInstance();
+ }
+ if (count == 1) {
+ return new PredicateEquals(pats[0]);
+ }
+ return new PredicateStringMatch(pats, count);
+ }
+
+ public boolean evaluate(Object o) {
+ if (o == null) {
+ return false;
+ }
+ String target = o.toString();
+ if (!target.startsWith(patterns[0])) {
+ return false;
+ }
+ if (!target.endsWith(patterns[patternCount - 1])) {
+ return false;
+ }
+ for (String pattern : patterns) {
+ int index = (target + "*").indexOf(pattern);
+ if (index == -1) {
+ return false;
+ }
+ target = target.substring(index + pattern.length());
+ }
+ return true;
+ }
+
+}
Added: trunk/src/argouml-app/src/org/argouml/util/PredicateTrue.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/util/PredicateTrue.java?view=auto&rev=15579
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/util/PredicateTrue.java 2008-08-18 14:41:39-0700
@@ -0,0 +1,74 @@
+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.util;
+
+//Copyright (c) 1996-99 The Regents of the University of California. All
+//Rights Reserved. Permission to use, copy, modify, and distribute this
+//software and its documentation without fee, and without a written
+//agreement is hereby granted, provided that the above copyright notice
+//and this paragraph appear in all copies. This software program and
+//documentation are copyrighted by The Regents of the University of
+//California. The software program and documentation are supplied "AS
+//IS", without any accompanying services from The Regents. The Regents
+//does not warrant that the operation of the program will be
+//uninterrupted or error-free. The end-user understands that the program
+//was developed for research purposes and is advised not to rely
+//exclusively on the program for any reason. IN NO EVENT SHALL THE
+//UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+//SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+//ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+//THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+//SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+//PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+//CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+//UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+/**
+ * A Predicate that always returns true. Based on GEF utility class of the same
+ * name. This is implemented as a singleton with a private constructor.
+ *
+ * @author Jason Robbins
+ */
+public class PredicateTrue implements Predicate {
+
+ private PredicateTrue() {
+ }
+
+ public boolean evaluate(Object obj) {
+ return true;
+ }
+
+ private static PredicateTrue theInstance = new PredicateTrue();
+
+ /**
+ * @return the instance
+ */
+ public static PredicateTrue getInstance() {
+ return theInstance;
+ }
+}
+
Added: trunk/src/argouml-app/src/org/argouml/util/PredicateType.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/util/PredicateType.java?view=auto&rev=15579
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/util/PredicateType.java 2008-08-18 14:41:39-0700
@@ -0,0 +1,111 @@
+// $Id$
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.util;
+
+public class PredicateType implements Predicate {
+
+ private Class patterns[];
+
+ private int patternCount;
+
+ private String printString = null;
+
+ protected PredicateType(Class pats[]) {
+ this(pats, pats.length);
+ }
+
+ protected PredicateType(Class pats[], int numPats) {
+ patterns = pats;
+ patternCount = numPats;
+ }
+
+ public static PredicateType create() {
+ return new PredicateType(null, 0);
+ }
+
+ public static PredicateType create(Class c0) {
+ Class classes[] = new Class[1];
+ classes[0] = c0;
+ return new PredicateType(classes);
+ }
+
+ public static PredicateType create(Class c0, Class c1) {
+ Class classes[] = new Class[2];
+ classes[0] = c0;
+ classes[1] = c1;
+ return new PredicateType(classes);
+ }
+
+ public static PredicateType create(Class c0, Class c1, Class c2) {
+ Class classes[] = new Class[3];
+ classes[0] = c0;
+ classes[1] = c1;
+ classes[2] = c2;
+ return new PredicateType(classes);
+ }
+
+ public boolean evaluate(Object o) {
+ if (patternCount == 0) {
+ return true;
+ }
+ for (int i = 0; i < patternCount; i++) {
+ if (patterns[i].isInstance(o)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean isPredicateFor(Object o) {
+ for (int i = 0; i < patternCount; i++) {
+ if (patterns[i].equals(o)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ if (printString != null) {
+ return printString;
+ }
+ if (patternCount == 0) {
+ return "Any Type";
+ }
+ String res = "";
+ for (int i = 0; i < patternCount; i++) {
+ String clsName = patterns[i].getName();
+ int lastDot = clsName.lastIndexOf(".");
+ clsName = clsName.substring(lastDot + 1);
+ res += clsName;
+ if (i < patternCount - 1) {
+ res += ", ";
+ }
+ }
+ printString = res;
+ return res;
+ }
+}
Modified: trunk/src/argouml-app/tests/org/argouml/cognitive/checklist/TestCheckItem.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/cognitive/checklist/TestCheckItem.java?view=diff&rev=15579&p1=trunk/src/argouml-app/tests/org/argouml/cognitive/checklist/TestCheckItem.java&p2=trunk/src/argouml-app/tests/org/argouml/cognitive/checklist/TestCheckItem.java&r1=15578&r2=15579
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/cognitive/checklist/TestCheckItem.java (original)
+++ trunk/src/argouml-app/tests/org/argouml/cognitive/checklist/TestCheckItem.java 2008-08-18 14:41:39-0700
@@ -25,7 +25,6 @@
package org.argouml.cognitive.checklist;
import junit.framework.TestCase;
-import org.tigris.gef.util.PredicateTrue;
/**
* Tests initialization of CheckItem.
@@ -54,9 +53,9 @@
String description = "TestCheckItem Description";
String moreInfo = "http://argouml.tigris.org/test";
- // Construct a CheckItem
+ // Construct a CheckItem using the old API
CheckItem item = new CheckItem(category, description,
- moreInfo, PredicateTrue.theInstance());
+ moreInfo, org.tigris.gef.util.PredicateTrue.theInstance());
// (1) test that the properties were correctly initialized
assertTrue("CheckItem.getDescription() incorrect "
@@ -70,7 +69,8 @@
item.getCategory() == category);
assertTrue("CheckItem.getPredicate() incorrect after "
+ "initialization (1)",
- item.getPredicate() == PredicateTrue.theInstance());
+ item.getPredicate() ==
+ org.tigris.gef.util.PredicateTrue.theInstance());
// reset the values to something different
category += "- Set Test";
@@ -81,16 +81,16 @@
item.setCategory(category);
item.setDescription(description);
item.setMoreInfoURL(moreInfo);
- item.setPredicate(null);
+ item.setPredicate((org.tigris.gef.util.Predicate) null);
- assertTrue("CheckItem.getDescription() incorrect after set",
- item.getDescription() == description);
- assertTrue("CheckItem.getMoreInfoURL() incorrect after set",
- item.getMoreInfoURL() == moreInfo);
- assertTrue("CheckItem.getCategory() incorrect after set",
- item.getCategory() == category);
- assertTrue("CheckItem.getPredicate() incorrect after set",
- item.getPredicate() == null);
+ assertEquals("CheckItem.getDescription() incorrect after set",
+ item.getDescription(), description);
+ assertEquals("CheckItem.getMoreInfoURL() incorrect after set",
+ item.getMoreInfoURL(), moreInfo);
+ assertEquals("CheckItem.getCategory() incorrect after set",
+ item.getCategory(), category);
+ assertNull("CheckItem.getPredicate() incorrect after set",
+ item.getPredicate());
// (2) Construct another CheckItem
CheckItem item2 = new CheckItem(category, description);
@@ -107,7 +107,50 @@
item.getCategory() == category);
// verify that the equivalence test works
- assertTrue("CheckItem.equals(o) incorrect", item2.equals(item));
+ assertEquals("CheckItem.equals(o) incorrect", item, item2);
+
+ // Test again with the new API
+ item = new CheckItem(category, description,
+ moreInfo, org.argouml.util.PredicateTrue.getInstance());
+
+ // test that the properties were correctly initialized
+ assertEquals("CheckItem.getDescription() incorrect "
+ + "after initialization (1a)",
+ item.getDescription(),description);
+ assertEquals("CheckItem.getMoreInfoURL() incorrect "
+ + "after initialization (1a)",
+ item.getMoreInfoURL(), moreInfo);
+ assertEquals("CheckItem.getCategory() incorrect after "
+ + "initialization (1a)",
+ item.getCategory(), category);
+ assertEquals("CheckItem.getPredicate2() incorrect after "
+ + "initialization (1a)",
+ item.getPredicate2(),
+ org.argouml.util.PredicateTrue.getInstance());
+
+ // reset the values to something different
+ category += "- Set Test";
+ description += "- Set Test";
+ moreInfo += "- Set Test";
+
+ // update the values
+ item.setCategory(category);
+ item.setDescription(description);
+ item.setMoreInfoURL(moreInfo);
+ item.setPredicate((org.argouml.util.Predicate) null);
+ assertEquals("CheckItem.getDescription() incorrect after set",
+ item.getDescription(), description);
+ assertEquals("CheckItem.getMoreInfoURL() incorrect after set",
+ item.getMoreInfoURL(), moreInfo);
+ assertEquals("CheckItem.getCategory() incorrect after set",
+ item.getCategory(), category);
+ assertNull("CheckItem.getPredicate() incorrect after set",
+ item.getPredicate2());
+
+ // verify that the equivalence test works again
+ item2 = new CheckItem(category, description);
+ assertEquals("CheckItem.equals(o) incorrect", item, item2);
+
}
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.