diff options
author | wisberg <wisberg> | 2003-04-19 08:14:00 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2003-04-19 08:14:00 +0000 |
commit | 5d8dd96b88f02386f3c2bb587e4846a691b01d36 (patch) | |
tree | 4afd87b6ee81b5ce66ca84ede2ad60d766eb16bd /bridge | |
parent | 7fbdd52e8f5a4a24aa56468612a718b2ada7bf6f (diff) | |
download | aspectj-5d8dd96b88f02386f3c2bb587e4846a691b01d36.tar.gz aspectj-5d8dd96b88f02386f3c2bb587e4846a691b01d36.zip |
More readable API than comparator for common floor operation (semantics-preserving)
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/src/org/aspectj/bridge/CountingMessageHandler.java | 2 | ||||
-rw-r--r-- | bridge/src/org/aspectj/bridge/IMessage.java | 16 | ||||
-rw-r--r-- | bridge/src/org/aspectj/bridge/MessageHandler.java | 11 | ||||
-rw-r--r-- | bridge/src/org/aspectj/bridge/MessageUtil.java | 12 | ||||
-rw-r--r-- | bridge/testsrc/org/aspectj/bridge/MessageTest.java | 18 |
5 files changed, 42 insertions, 17 deletions
diff --git a/bridge/src/org/aspectj/bridge/CountingMessageHandler.java b/bridge/src/org/aspectj/bridge/CountingMessageHandler.java index 8c565a7b4..6c05253ee 100644 --- a/bridge/src/org/aspectj/bridge/CountingMessageHandler.java +++ b/bridge/src/org/aspectj/bridge/CountingMessageHandler.java @@ -95,7 +95,7 @@ public class CountingMessageHandler implements IMessageHandler { } else { for (Iterator iter = IMessage.KINDS.iterator(); iter.hasNext();) { IMessage.Kind k = (IMessage.Kind) iter.next(); - if (0 >= IMessage.Kind.COMPARATOR.compare(kind, k)) { + if (kind.isSameOrLessThan(k)) { result += numMessages(k); } } diff --git a/bridge/src/org/aspectj/bridge/IMessage.java b/bridge/src/org/aspectj/bridge/IMessage.java index 7cb22910c..7f7407e0f 100644 --- a/bridge/src/org/aspectj/bridge/IMessage.java +++ b/bridge/src/org/aspectj/bridge/IMessage.java @@ -81,9 +81,9 @@ public interface IMessage { Kind one = (Kind) o1; Kind two = (Kind) o2; if (null == one) { - return (null == two ? 0 : 1); + return (null == two ? 0 : -1); } else if (null == two) { - return -1; + return 1; } else if (one == two) { return 0; } else { @@ -91,7 +91,17 @@ public interface IMessage { } } }; - + + /** + * @param kind the Kind floor + * @return false if kind is null or this + * has less precedence than kind, + * true otherwise. + */ + public boolean isSameOrLessThan(Kind kind) { + return (0 >= COMPARATOR.compare(this, kind)); + } + public int compareTo(Object other) { return COMPARATOR.compare(this, other); } diff --git a/bridge/src/org/aspectj/bridge/MessageHandler.java b/bridge/src/org/aspectj/bridge/MessageHandler.java index 4bdb8a6ce..bc68a0a43 100644 --- a/bridge/src/org/aspectj/bridge/MessageHandler.java +++ b/bridge/src/org/aspectj/bridge/MessageHandler.java @@ -158,10 +158,9 @@ public class MessageHandler implements IMessageHolder { } } } else { - final Comparator c = IMessage.Kind.COMPARATOR; for (Iterator iter = messages.iterator(); iter.hasNext();) { IMessage m = (IMessage) iter.next(); - if (0 >= c.compare(kind, m.getKind())) { + if (kind.isSameOrLessThan(m.getKind())) { return true; } } @@ -184,10 +183,9 @@ public class MessageHandler implements IMessageHolder { } } } else { - final Comparator c = IMessage.Kind.COMPARATOR; for (Iterator iter = messages.iterator(); iter.hasNext();) { IMessage m = (IMessage) iter.next(); - if (0 >= c.compare(kind, m.getKind())) { + if (kind.isSameOrLessThan(m.getKind())) { result++; } } @@ -221,10 +219,9 @@ public class MessageHandler implements IMessageHolder { } } } else { - final Comparator c = IMessage.Kind.COMPARATOR; for (Iterator iter = messages.iterator(); iter.hasNext();) { - IMessage m = (IMessage) iter.next(); - if (0 >= c.compare(kind, m.getKind())) { + IMessage m = (IMessage) iter.next(); + if (kind.isSameOrLessThan(m.getKind())) { result.add(m); } } diff --git a/bridge/src/org/aspectj/bridge/MessageUtil.java b/bridge/src/org/aspectj/bridge/MessageUtil.java index ddb93b476..516ab09bf 100644 --- a/bridge/src/org/aspectj/bridge/MessageUtil.java +++ b/bridge/src/org/aspectj/bridge/MessageUtil.java @@ -522,15 +522,15 @@ public class MessageUtil { final IMessage.Kind sought; final boolean floor; final String infix; - + KindSelector(IMessage.Kind sought) { this(sought, false); } - + KindSelector(IMessage.Kind sought, boolean floor) { this(sought, floor, null); } - + KindSelector(IMessage.Kind sought, boolean floor, String infix) { this.sought = sought; this.floor = floor; @@ -542,11 +542,11 @@ public class MessageUtil { * or if this has the exact kind we seek * and this has any text sought */ - public boolean handleMessage(IMessage message) { + public boolean handleMessage(IMessage message) { return ((null != message) && !isIgnoring(message.getKind()) && textIn(message)); - } - + } + /** @return true if handleMessage would return false for a message of this kind */ public boolean isIgnoring(IMessage.Kind kind) { if (!floor) { diff --git a/bridge/testsrc/org/aspectj/bridge/MessageTest.java b/bridge/testsrc/org/aspectj/bridge/MessageTest.java index 61488c8ef..8688f44b4 100644 --- a/bridge/testsrc/org/aspectj/bridge/MessageTest.java +++ b/bridge/testsrc/org/aspectj/bridge/MessageTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.util.Arrays; import java.util.BitSet; import java.util.Comparator; +import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -70,6 +71,23 @@ public class MessageTest extends TestCase { checkListOrder(IMessage.KINDS, IMessage.Kind.COMPARATOR); } + public void testKind_isSameOrLessThan() { + IMessage.Kind last; + IMessage.Kind next = null; + for (Iterator iter = IMessage.KINDS.iterator(); iter.hasNext();) { + last = next; + next = (IMessage.Kind) iter.next(); + if (null == last) { + continue; + } + String label = "last: " + last + " next: " + next; + assertTrue(label, !next.isSameOrLessThan(null)); + assertTrue(label, !next.isSameOrLessThan(last)); + assertTrue(label, last.isSameOrLessThan(next)); + assertTrue(label, next.isSameOrLessThan(next)); + } + } + public void testMessageHandler() { boolean handleMessageResult = true; checkEmptyMessageHolder(new MessageHandler(handleMessageResult), handleMessageResult); |