applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / utils / Properties.java
index 4d5c874..039096e 100644 (file)
@@ -1,3 +1,24 @@
+/*\r
+ * This file is part of the Vamsas Client version 0.1. \r
+ * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
+ *  Andrew Waterhouse and Dominik Lindner.\r
+ * \r
+ * Earlier versions have also been incorporated into Jalview version 2.4 \r
+ * since 2008, and TOPALi version 2 since 2007.\r
+ * \r
+ * The Vamsas Client is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *  \r
+ * The Vamsas Client is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
 package uk.ac.vamsas.objects.utils;\r
 \r
 import java.util.Enumeration;\r
@@ -6,152 +27,150 @@ import java.util.Vector;
 import uk.ac.vamsas.objects.core.Property;\r
 \r
 public class Properties {\r
-  public static Property newProperty(String name, String type, String content)\r
-  {\r
+  public static Property newProperty(String name, String type, String content) {\r
     Property vProperty = new Property();\r
     vProperty.setName(name);\r
-    if (type != null)\r
-    {\r
+    if (type != null) {\r
       vProperty.setType(type);\r
-    }\r
-    else\r
-    {\r
+    } else {\r
       vProperty.setType(STRINGTYPE);\r
     }\r
     vProperty.setContent(content);\r
     return vProperty;\r
   }\r
-  final public static String STRINGTYPE="string";\r
-  final public static String FLOATTYPE="float";\r
-  final public static String INTEGERTYPE="integer";\r
-  final public static String BOOLEANTYPE="boolean";\r
+\r
+  final public static String STRINGTYPE = "string";\r
+\r
+  final public static String FLOATTYPE = "float";\r
+\r
+  final public static String INTEGERTYPE = "integer";\r
+\r
+  final public static String BOOLEANTYPE = "boolean";\r
+\r
   /**\r
-   * add newprop to properties, or update the value of an existing property with the same exact name and type.\r
-   * Note - this routine will stop after encounting the first occurance of a Property with the same name and type, no others will be affected.   \r
+   * add newprop to properties, or update the value of an existing property with\r
+   * the same exact name and type. Note - this routine will stop after\r
+   * encounting the first occurance of a Property with the same name and type,\r
+   * no others will be affected.\r
+   * \r
    * @param properties\r
-   * @param newprop \r
-   * @return true if property was added or its value updated. false if no change was made.\r
+   * @param newprop\r
+   * @return true if property was added or its value updated. false if no change\r
+   *         was made.\r
    */\r
-  public static boolean addOrReplace(Vector properties, Property newprop)\r
-  {\r
-    if (properties.size()>0)\r
-    {\r
+  public static boolean addOrReplace(Vector properties, Property newprop) {\r
+    if (properties.size() > 0) {\r
       Enumeration en = properties.elements();\r
-      while (en.hasMoreElements())\r
-      {\r
+      while (en.hasMoreElements()) {\r
         Object el = en.nextElement();\r
-        if (el instanceof Property)\r
-        {\r
+        if (el instanceof Property) {\r
           Property prop = (Property) el;\r
-          if (prop.getName().equals(newprop.getName()) && \r
-                  prop.getType().equals(newprop.getType()))\r
-          {\r
-            if (prop.getContent().equals(newprop.getContent()))\r
-            {\r
+          if (prop.getName().equals(newprop.getName())\r
+              && prop.getType().equals(newprop.getType())) {\r
+            if (prop.getContent().equals(newprop.getContent())) {\r
               return false;\r
-            }  else {\r
+            } else {\r
               prop.setContent(newprop.getContent());\r
               return true;\r
             }\r
           }\r
         } else {\r
-          throw new Error("Implementation Error: properties must be a Vector of uk.ac.vamsas.objects.core.Property objects only.");\r
+          throw new Error(\r
+              "Implementation Error: properties must be a Vector of uk.ac.vamsas.objects.core.Property objects only.");\r
         }\r
       }\r
-    } \r
+    }\r
     properties.addElement(newprop);\r
     return true;\r
   }\r
+\r
   /**\r
-   * validate property p against the known type strings and try to parse the content string accordingly \r
+   * validate property p against the known type strings and try to parse the\r
+   * content string accordingly\r
+   * \r
    * @param p\r
-   * @return true if the content parses as the given type (if it is known)\r
-   * TODO: decide if an isValidType method is also necessary.\r
+   * @return true if the content parses as the given type (if it is known) TODO:\r
+   *         decide if an isValidType method is also necessary.\r
    */\r
-  public static boolean isValid(Property p)\r
-  {\r
-    if (p.getType().equalsIgnoreCase(STRINGTYPE))\r
-    {\r
+  public static boolean isValid(Property p) {\r
+    if (p.getType().equalsIgnoreCase(STRINGTYPE)) {\r
       return true;\r
-    } else\r
-      if (p.getType().equalsIgnoreCase(BOOLEANTYPE))\r
-      {\r
-        try {\r
-          Boolean bool = new Boolean(p.getContent());\r
-          return true;\r
-        } catch (Exception e)\r
-        {\r
-          return false;\r
-        }\r
-      } else\r
-      if (p.getType().equalsIgnoreCase(FLOATTYPE))\r
-      {\r
-        try {\r
-          Float fv = new Float(p.getContent());\r
-          return true;\r
-        } catch (Exception e)\r
-        {\r
-          return false;\r
-        }\r
+    } else if (p.getType().equalsIgnoreCase(BOOLEANTYPE)) {\r
+      try {\r
+        Boolean bool = new Boolean(p.getContent());\r
+        return true;\r
+      } catch (Exception e) {\r
+        return false;\r
       }\r
-      else\r
-        if( p.getType().equalsIgnoreCase(INTEGERTYPE))\r
-        {\r
-\r
-          try {\r
-            Integer fv = new Integer(p.getContent());\r
-            return true;\r
-          } catch (Exception e)\r
-          {\r
-            return false;\r
-          } \r
-        }\r
+    } else if (p.getType().equalsIgnoreCase(FLOATTYPE)) {\r
+      try {\r
+        Float fv = new Float(p.getContent());\r
+        return true;\r
+      } catch (Exception e) {\r
+        return false;\r
+      }\r
+    } else if (p.getType().equalsIgnoreCase(INTEGERTYPE)) {\r
+\r
+      try {\r
+        Integer fv = new Integer(p.getContent());\r
+        return true;\r
+      } catch (Exception e) {\r
+        return false;\r
+      }\r
+    }\r
     return false;\r
   }\r
+\r
   /**\r
-   * String content test \r
+   * String content test\r
+   * \r
    * @param p\r
-   * @return true if the property is a string \r
+   * @return true if the property is a string\r
    */\r
-  public static boolean isString(Property p)\r
-  {\r
+  public static boolean isString(Property p) {\r
     return isType(p, STRINGTYPE);\r
   }\r
+\r
   /**\r
-   * Float content test \r
+   * Float content test\r
+   * \r
    * @param p\r
-   * @return true if the property is a string \r
+   * @return true if the property is a string\r
    */\r
-  public static boolean isFloat(Property p)\r
-  {\r
+  public static boolean isFloat(Property p) {\r
     return isType(p, FLOATTYPE);\r
   }\r
+\r
   /**\r
-   * Integer content test \r
+   * Integer content test\r
+   * \r
    * @param p\r
-   * @return true if the property is a string \r
+   * @return true if the property is a string\r
    */\r
-  public static boolean isInteger(Property p)\r
-  {\r
+  public static boolean isInteger(Property p) {\r
     return isType(p, INTEGERTYPE);\r
   }\r
+\r
   /**\r
-   * Boolean content test \r
+   * Boolean content test\r
+   * \r
    * @param p\r
-   * @return true if the property is a string \r
+   * @return true if the property is a string\r
    */\r
-  public static boolean isBoolean(Property p)\r
-  {\r
+  public static boolean isBoolean(Property p) {\r
     return isType(p, BOOLEANTYPE);\r
   }\r
+\r
   /**\r
    * \r
-   * @param p the property to test for type\r
-   * @param typeString one of the string constants in this class\r
+   * @param p\r
+   *          the property to test for type\r
+   * @param typeString\r
+   *          one of the string constants in this class\r
    * @return true if p is of type 'typeString'\r
    */\r
   public static boolean isType(Property p, String typeString) {\r
-    return (p==null) ? false : (p.getType().toLowerCase().equals(typeString));\r
+    return (p == null) ? false : (p.getType().toLowerCase().equals(typeString));\r
   }\r
-  \r
+\r
 }\r