You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2006/09/11 19:43:54 UTC

svn commit: r442276 - /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java

Author: jmsnell
Date: Mon Sep 11 10:43:53 2006
New Revision: 442276

URL: http://svn.apache.org/viewvc?view=rev&rev=442276
Log:
Provide a way of autoincrementing the ordinal when adding a new resource type
Check to make sure a new resource type does not duplicate the ordinal or name of 
an existing one.

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java?view=diff&rev=442276&r1=442275&r2=442276
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java Mon Sep 11 10:43:53 2006
@@ -48,16 +48,38 @@
   private static synchronized List<ResourceType> get_values() {
     if (values == null) {
       values = Collections.synchronizedList(
-          new ArrayList<ResourceType>());
+        new ArrayList<ResourceType>());
     }
     return values;
   }
   
   private static synchronized void add(ResourceType type) {
     List<ResourceType> values = get_values();
+    if (type.ordinal() < values().length || 
+        contains(type) || 
+        contains(type.name())) 
+          throw new IllegalArgumentException();
     values.add(type);
   }
   
+  public static boolean contains(ResourceType type) {
+    for (ResourceType rt : values()) {
+      if (rt.equals(type)) return true;
+    }
+    return false;
+  }
+  
+  public static boolean contains(String name) {
+    for (ResourceType rt : values()) {
+      if (rt.name.equals(name)) return true;
+    }
+    return false;
+  }
+  
+  public static int nextOrdinal() {
+    return values.size();
+  }
+  
   public static ResourceType[] values() {
     List<ResourceType> values = get_values();
     return values.toArray(new ResourceType[values.size()]);
@@ -70,12 +92,21 @@
     return null;
   }
   
+  public static ResourceType valueOf(int ordinal) {
+    return values()[ordinal];
+  }
+  
   private final int i;
   private final String name;
   
+  public ResourceType(String name) {
+    this(name, nextOrdinal());
+  }
+  
   public ResourceType(String name, int ordinal) {
+    if (name == null) throw new IllegalArgumentException("Name cannot be null");
     this.i = ordinal;
-    this.name = name.intern();
+    this.name = name.intern().toUpperCase();
     ResourceType.add(this);
   }