Coverage Report - org.codeforamerica.open311.facade.data.Endpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
Endpoint
88%
15/17
50%
2/4
1.571
 
 1  
 package org.codeforamerica.open311.facade.data;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.util.Date;
 5  
 import java.util.List;
 6  
 
 7  
 import org.codeforamerica.open311.facade.EndpointType;
 8  
 import org.codeforamerica.open311.facade.Format;
 9  
 
 10  
 /**
 11  
  * Wraps the information relative to a single endpoint.
 12  
  * 
 13  
  * @author Santiago MunĂ­n <santimunin@gmail.com>
 14  
  */
 15  
 public class Endpoint implements Serializable {
 16  
         private static final long serialVersionUID = -5512681512770606630L;
 17  
         private String specificationUrl;
 18  
         private String url;
 19  
         private Date changeset;
 20  
         private EndpointType type;
 21  
         private List<Format> formats;
 22  
 
 23  
         public Endpoint(String specificationUrl, String url, Date changeset,
 24  
                         EndpointType type, List<Format> formats) {
 25  24
                 super();
 26  24
                 this.specificationUrl = specificationUrl;
 27  24
                 this.url = url;
 28  24
                 this.changeset = changeset;
 29  24
                 this.type = type;
 30  24
                 this.formats = formats;
 31  24
         }
 32  
 
 33  
         public String getSpecificationUrl() {
 34  7
                 return specificationUrl;
 35  
         }
 36  
 
 37  
         public String getUrl() {
 38  13
                 return url;
 39  
         }
 40  
 
 41  
         public Date getChangeset() {
 42  1
                 return changeset;
 43  
         }
 44  
 
 45  
         public EndpointType getType() {
 46  25
                 return type;
 47  
         }
 48  
 
 49  
         /**
 50  
          * Returns the more suitable format. Tries JSON before XML.
 51  
          * 
 52  
          * @return A format allowed by the endpoint.
 53  
          */
 54  
         public Format getBestFormat() {
 55  1
                 if (formats.contains(Format.JSON)) {
 56  0
                         return Format.JSON;
 57  
                 }
 58  1
                 if (formats.contains(Format.XML)) {
 59  1
                         return Format.XML;
 60  
                 }
 61  0
                 return null;
 62  
         }
 63  
 
 64  
         /**
 65  
          * Returns whether it allows the given format or not.
 66  
          * 
 67  
          * @param format
 68  
          *            Desired format.
 69  
          * @return <code>true</code> if it allows the given format, else
 70  
          *         <code>false</code>.
 71  
          */
 72  
         public boolean isCompatibleWithFormat(Format format) {
 73  6
                 return formats.contains(format);
 74  
         }
 75  
 }