Coverage Report - net.sourceforge.pebble.domain.Attachment
 
Classes in this File Line Coverage Branch Coverage Complexity
Attachment
90%
27/30
41%
5/12
1.727
 
 1  
 /*
 2  
  * Copyright (c) 2003-2011, Simon Brown
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions are met:
 7  
  *
 8  
  *   - Redistributions of source code must retain the above copyright
 9  
  *     notice, this list of conditions and the following disclaimer.
 10  
  *
 11  
  *   - Redistributions in binary form must reproduce the above copyright
 12  
  *     notice, this list of conditions and the following disclaimer in
 13  
  *     the documentation and/or other materials provided with the
 14  
  *     distribution.
 15  
  *
 16  
  *   - Neither the name of Pebble nor the names of its contributors may
 17  
  *     be used to endorse or promote products derived from this software
 18  
  *     without specific prior written permission.
 19  
  *
 20  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 21  
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22  
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23  
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 24  
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 25  
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 26  
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 28  
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 29  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 30  
  * POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 package net.sourceforge.pebble.domain;
 33  
 
 34  
 
 35  
 /**
 36  
  * Represents a blog entry attachment (such as that used within an RSS
 37  
  * enclosure).
 38  
  *
 39  
  * @author Simon Brown
 40  
  */
 41  
 public class Attachment implements Cloneable {
 42  
 
 43  
   /** the URL of the attachment */
 44  
   private String url;
 45  
 
 46  
   /** the content size (length in bytes) */
 47  
   private long size;
 48  
 
 49  
   /** the content type */
 50  
   private String type;
 51  
 
 52  
   /**
 53  
    * Default, no args constructor.
 54  
    */
 55  8
   public Attachment() {
 56  8
   }
 57  
 
 58  
   /**
 59  
    * Creates an instance with the specified properties.
 60  
    *
 61  
    * @param url   a URL as a String
 62  
    * @param size    the size in bytes
 63  
    * @param type    a content type as a String
 64  
    */
 65  16
   public Attachment(String url, long size, String type) {
 66  16
     setUrl(url);
 67  16
     setSize(size);
 68  16
     setType(type);
 69  16
   }
 70  
 
 71  
   /**
 72  
    * Gets the URL.
 73  
    *
 74  
    * @return  the URL as a String
 75  
    */
 76  
   public String getUrl() {
 77  20
     return url;
 78  
   }
 79  
 
 80  
   /**
 81  
    * Sets the URL.
 82  
    *
 83  
    * @param url   a URL as a String
 84  
    */
 85  
   public void setUrl(String url) {
 86  28
     this.url = url;
 87  28
   }
 88  
 
 89  
   /**
 90  
    * Gets the size in bytes.
 91  
    *
 92  
    * @return  the size of the attachement in bytes
 93  
    */
 94  
   public long getSize() {
 95  4
     return size;
 96  
   }
 97  
 
 98  
   /**
 99  
    * Sets the size of the attachement in bytes.
 100  
    *
 101  
    * @param size    the size in bytes
 102  
    */
 103  
   public void setSize(long size) {
 104  24
     this.size = size;
 105  24
   }
 106  
 
 107  
   /**
 108  
    * Gets the content type.
 109  
    *
 110  
    * @return  a MIME type as a String
 111  
    */
 112  
   public String getType() {
 113  4
     return type;
 114  
   }
 115  
 
 116  
   /**
 117  
    * Sets the content type.
 118  
    *
 119  
    * @param type    a content type as a String
 120  
    */
 121  
   public void setType(String type) {
 122  24
     this.type = type;
 123  24
   }
 124  
 
 125  
   public boolean equals(Object o) {
 126  24
     if (this == o) {
 127  12
       return true;
 128  
     }
 129  
 
 130  12
     if (!(o instanceof Attachment)) {
 131  0
       return false;
 132  
     }
 133  
 
 134  12
     final Attachment attachment = (Attachment) o;
 135  12
     if (url == null || url.length() == 0) {
 136  0
       return attachment.url == null || attachment.url.length() == 0;
 137  
     } else {
 138  12
       return url.equals(attachment.url);
 139  
     }
 140  
   }
 141  
 
 142  
   public int hashCode() {
 143  0
     return url.hashCode();
 144  
   }
 145  
 
 146  
   /**
 147  
    * Creates and returns a copy of this object.
 148  
    *
 149  
    * @return a clone of this instance.
 150  
    * @see Cloneable
 151  
    */
 152  
   public Object clone() {
 153  4
     Attachment attachment = new Attachment();
 154  4
     attachment.setUrl(url);
 155  4
     attachment.setSize(size);
 156  4
     attachment.setType(type);
 157  
 
 158  4
     return attachment;
 159  
   }
 160  
 
 161  
 }