Coverage Report - org.codeforamerica.open311.facade.data.MultiValueAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiValueAttribute
100%
8/8
100%
2/2
1.5
 
 1  
 package org.codeforamerica.open311.facade.data;
 2  
 
 3  
 import java.util.HashMap;
 4  
 import java.util.Map;
 5  
 
 6  
 /**
 7  
  * Multi valued attribute useful for the <a
 8  
  * href="http://wiki.open311.org/GeoReport_v2#POST_Service_Request">POST Service
 9  
  * Request</a> operation.
 10  
  * 
 11  
  * @author Santiago MunĂ­n <santimunin@gmail.com>
 12  
  * 
 13  
  */
 14  
 public class MultiValueAttribute implements Attribute {
 15  
         /**
 16  
          * Code of the attribute.
 17  
          */
 18  
         private String code;
 19  
         /**
 20  
          * Values of the attribute.
 21  
          */
 22  
         private String[] values;
 23  
 
 24  
         public MultiValueAttribute(String code, String... values) {
 25  2
                 super();
 26  2
                 this.code = code;
 27  2
                 this.values = values;
 28  2
         }
 29  
 
 30  
         /**
 31  
          * @return A list of pairs (attribute[CODE][], value1), (attribute[CODE][],
 32  
          *         value2), ... in a <code>Map<String, String></code>.
 33  
          */
 34  
         @Override
 35  
         public Map<String, String> generatePOSTRequestParameter() {
 36  2
                 Map<String, String> result = new HashMap<String, String>();
 37  7
                 for (int i = 0; i < values.length; i++) {
 38  5
                         result.put("attribute[" + code + "][" + i + "]", values[i]);
 39  
                 }
 40  2
                 return result;
 41  
         }
 42  
 }