commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roxspr...@apache.org
Subject cvs commit: jakarta-commons/cli/src/java/org/apache/commons/cli2/util Comparators.java
Date Tue, 20 Apr 2004 21:43:33 GMT
roxspring    2004/04/20 14:43:33

  Modified:    cli/src/java/org/apache/commons/cli2/util Tag:
                        RESEARCH_CLI_2_ROXSPRING Comparators.java
  Log:
  Added requiredFirst(..) and requiredLast(..) to Comparators to allow required options to
be sorted to one end of a list
  PR:26926
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.4   +30 -0     jakarta-commons/cli/src/java/org/apache/commons/cli2/util/Attic/Comparators.java
  
  Index: Comparators.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/util/Attic/Comparators.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- Comparators.java	14 Apr 2004 18:31:16 -0000	1.1.2.3
  +++ Comparators.java	20 Apr 2004 21:43:33 -0000	1.1.2.4
  @@ -434,4 +434,34 @@
               return left.getPreferredName().compareTo(right.getPreferredName());
           }
       }
  +
  +    public static Comparator requiredFirst() {
  +        return new Required();
  +    }
  +    
  +    public static Comparator requiredLast() {
  +        return reverse(requiredFirst());
  +    }
  +    
  +    public static class Required implements Comparator {
  +        public int compare(final Object oleft, final Object oright) {
  +            final Option left = (Option)oleft;
  +            final Option right = (Option)oright;
  +            
  +            final boolean l = left.isRequired();
  +            final boolean r = right.isRequired();
  +
  +            if (l ^ r) {
  +                if (l) {
  +                    return -1;
  +                }
  +                else {
  +                    return 1;
  +                }
  +            }
  +            else {
  +                return 0;
  +            }
  +        }
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message