Coverage Report - org.codeforamerica.open311.facade.data.AttributeInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
AttributeInfo
75%
18/24
0%
0/2
2.182
AttributeInfo$Datatype
100%
15/15
100%
12/12
2.182
 
 1  
 package org.codeforamerica.open311.facade.data;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.util.Map;
 5  
 import java.util.Map.Entry;
 6  
 
 7  
 /**
 8  
  * Represents a single attribute of a service definition.
 9  
  * 
 10  
  * @author Santiago MunĂ­n <santimunin@gmail.com>
 11  
  * 
 12  
  */
 13  
 public class AttributeInfo implements Serializable {
 14  
 
 15  
         private static final long serialVersionUID = -6704474615491645869L;
 16  
         private Boolean variable;
 17  
         private String code;
 18  
         private Datatype datatype;
 19  
         private Boolean required;
 20  
         private String datatypeDescription;
 21  
         private Integer order;
 22  
         private String description;
 23  
         /**
 24  
          * Pair key, name. Check the attribute section of the <a
 25  
          * href="http://wiki.open311.org/GeoReport_v2#GET_Service_Definition"
 26  
          * >Service Definition</a>.
 27  
          */
 28  
         private Map<String, String> values;
 29  
 
 30  
         public AttributeInfo(Boolean variable, String code, Datatype datatype,
 31  
                         Boolean required, String datatypeDescription, Integer order,
 32  
                         String description, Map<String, String> values) {
 33  5
                 super();
 34  5
                 this.variable = variable;
 35  5
                 this.code = code;
 36  5
                 this.datatype = datatype;
 37  5
                 this.required = required;
 38  5
                 this.datatypeDescription = datatypeDescription;
 39  5
                 this.order = order;
 40  5
                 this.description = description;
 41  5
                 this.values = values;
 42  5
         }
 43  
 
 44  
         public Boolean isVariable() {
 45  3
                 return variable;
 46  
         }
 47  
 
 48  
         public String getCode() {
 49  3
                 return code;
 50  
         }
 51  
 
 52  
         public Datatype getDatatype() {
 53  3
                 return datatype;
 54  
         }
 55  
 
 56  
         public Integer getOrder() {
 57  3
                 return order;
 58  
         }
 59  
 
 60  
         public String getDescription() {
 61  3
                 return description;
 62  
         }
 63  
 
 64  
         public Map<String, String> getValues() {
 65  6
                 return values;
 66  
         }
 67  
 
 68  
         public Boolean isRequired() {
 69  3
                 return required;
 70  
         }
 71  
 
 72  
         public String getDatatypeDescription() {
 73  3
                 return datatypeDescription;
 74  
         }
 75  
 
 76  
         /**
 77  
          * Returns a string of the form <code>ATTRIBUTE[key1][key2]...[keyN]=value1,
 78  
          * value2,...valueN</code>.
 79  
          */
 80  
         public String toString() {
 81  0
                 StringBuilder strBuilder = new StringBuilder("code: " + code + "\n");
 82  0
                 strBuilder.append("values: ");
 83  0
                 for (Entry<String, String> pair : values.entrySet()) {
 84  0
                         strBuilder.append("\n");
 85  0
                         strBuilder.append("\t" + pair.getKey() + " -> " + pair.getValue());
 86  
                 }
 87  0
                 return strBuilder.toString();
 88  
         }
 89  
 
 90  8
         public static enum Datatype {
 91  1
                 STRING, NUMBER, DATETIME, TEXT, SINGLEVALUELIST, MULTIVALUELIST;
 92  
 
 93  
                 /**
 94  
                  * Returns an instance of this class from a given string.
 95  
                  * 
 96  
                  * @param datatype
 97  
                  *            String representation of the datatype.
 98  
                  * @return <code>null</code> if the string is not one of the contained
 99  
                  *         types.
 100  
                  */
 101  
                 public static Datatype getFromString(String datatype) {
 102  25
                         if (datatype.toLowerCase().equals("string")) {
 103  4
                                 return STRING;
 104  
                         }
 105  21
                         if (datatype.toLowerCase().equals("number")) {
 106  4
                                 return NUMBER;
 107  
                         }
 108  17
                         if (datatype.toLowerCase().equals("datetime")) {
 109  4
                                 return DATETIME;
 110  
                         }
 111  13
                         if (datatype.toLowerCase().equals("text")) {
 112  2
                                 return TEXT;
 113  
                         }
 114  11
                         if (datatype.toLowerCase().equals("singlevaluelist")) {
 115  7
                                 return SINGLEVALUELIST;
 116  
                         }
 117  4
                         if (datatype.toLowerCase().equals("multivaluelist")) {
 118  2
                                 return MULTIVALUELIST;
 119  
                         }
 120  2
                         return null;
 121  
                 }
 122  
         }
 123  
 }