commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/impl BasicMessageList.java
Date Tue, 19 Aug 2003 23:34:22 GMT
dgraham     2003/08/19 16:34:22

  Modified:    resources/src/java/org/apache/commons/resources/impl
                        BasicMessageList.java
  Log:
  Moved Comparator implementation to a constant variable to avoid creating
  a new object on each call, removed hungarian notation on variables, 
  fixed variable scopes.
  
  Revision  Changes    Path
  1.5       +35 -44    jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/impl/BasicMessageList.java
  
  Index: BasicMessageList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/impl/BasicMessageList.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BasicMessageList.java	19 Apr 2003 18:46:43 -0000	1.4
  +++ BasicMessageList.java	19 Aug 2003 23:34:22 -0000	1.5
  @@ -87,6 +87,15 @@
   public class BasicMessageList implements Serializable, MessageList {
   
       /**
  +     * Compares MessageItems.
  +     */
  +    private static final Comparator actionItemComparator = new Comparator() {
  +        public int compare(Object o1, Object o2) {
  +            return ((MessageItem) o1).getOrder() - ((MessageItem) o2).getOrder();
  +        }
  +    };
  +
  +    /**
        * The accumulated set of <code>Message</code> objects (represented
        * as an ArrayList) for each property, keyed by property name.
        */
  @@ -96,7 +105,7 @@
        * The current number of the property/key being added.  This is used
        * to maintain the order messages are added.
        */
  -    private int iCount = 0;
  +    private int count = 0;
   
       // --------------------------------------------------------- Public Methods
   
  @@ -115,7 +124,7 @@
        */
       public BasicMessageList(String globalMessageKey) {
           super();
  -        setGlobalMessageKey(globalMessageKey);
  +        this.setGlobalMessageKey(globalMessageKey);
       }
   
       /**
  @@ -165,7 +174,7 @@
   
           if (item == null) {
               list = new ArrayList();
  -            item = new MessageItem(list, iCount++);
  +            item = new MessageItem(list, this.count++);
   
               messages.put(property, item);
           } else {
  @@ -179,8 +188,7 @@
   
       // See interface for JavaDoc
       public void add(Message message) {
  -
  -        add(MessageList.GLOBAL_MESSAGE_KEY, message);
  +        this.add(MessageList.GLOBAL_MESSAGE_KEY, message);
       }
   
   
  @@ -208,14 +216,14 @@
   
       // See interface for JavaDoc
       public boolean isEmpty() {
  -        return (messages.isEmpty());
  +        return messages.isEmpty();
       }
   
       // See interface for JavaDoc
       public Iterator get() {
   
  -        if (messages.size() == 0) {
  -            return (Collections.EMPTY_LIST.iterator());
  +        if (messages.isEmpty()) {
  +            return Collections.EMPTY_LIST.iterator();
           }
   
           ArrayList results = new ArrayList();
  @@ -227,11 +235,7 @@
   
           // Sort MessageItems based on the initial order the
           // property/key was added to MessageList.
  -        Collections.sort(actionItems, new Comparator() {
  -            public int compare(Object o1, Object o2) {
  -                return ((MessageItem) o1).getOrder() - ((MessageItem) o2).getOrder();
  -            }
  -        });
  +        Collections.sort(actionItems, actionItemComparator);
   
           for (Iterator i = actionItems.iterator(); i.hasNext();) {
               MessageItem ami = (MessageItem) i.next();
  @@ -241,28 +245,21 @@
               }
           }
   
  -        return (results.iterator());
  -
  +        return results.iterator();
       }
   
       // See interface for JavaDoc
       public Iterator get(String property) {
   
           MessageItem item = (MessageItem) messages.get(property);
  -
  -        if (item == null) {
  -            return (Collections.EMPTY_LIST.iterator());
  -        } else {
  -            return (item.getList().iterator());
  -        }
  -
  +        return (item == null)
  +            ? Collections.EMPTY_LIST.iterator()
  +            : item.getList().iterator();
       }
   
       // See interface for JavaDoc
       public Iterator properties() {
  -
  -        return (messages.keySet().iterator());
  -
  +        return messages.keySet().iterator();
       }
   
       // See interface for JavaDoc
  @@ -275,8 +272,7 @@
               total += ami.getList().size();
           }
   
  -        return (total);
  -
  +        return total;
       }
   
       // See interface for JavaDoc
  @@ -284,12 +280,7 @@
   
           MessageItem ami = (MessageItem) messages.get(property);
   
  -        if (ami == null) {
  -            return (0);
  -        } else {
  -            return (ami.getList().size());
  -        }
  -
  +        return (ami == null) ? 0 : ami.getList().size();
       }
   
       // See interface for JavaDoc
  @@ -298,16 +289,16 @@
           /**
            * The list of <code>Message</code>s.
            */
  -        List list = null;
  +        private List list = null;
   
           /**
            * The position in the list of messages.
            */
  -        int iOrder = 0;
  +        private int order = 0;
   
  -        public MessageItem(List list, int iOrder) {
  +        public MessageItem(List list, int order) {
               this.list = list;
  -            this.iOrder = iOrder;
  +            this.order = order;
           }
   
           public List getList() {
  @@ -319,11 +310,11 @@
           }
   
           public int getOrder() {
  -            return iOrder;
  +            return order;
           }
   
  -        public void setOrder(int iOrder) {
  -            this.iOrder = iOrder;
  +        public void setOrder(int order) {
  +            this.order = order;
           }
   
       }
  
  
  

Mime
View raw message