MimeType.java |
1 /* 2 * TextualDocumentFormat.java 3 * 4 * Copyright (c) 1998-2005, The University of Sheffield. 5 * 6 * This file is part of GATE (see http://gate.ac.uk/), and is free 7 * software, licenced under the GNU Library General Public License, 8 * Version 2, June 1991 (in the distribution as file licence.html, 9 * and also available at http://gate.ac.uk/gate/licence.html). 10 * 11 * Valentin Tablan 27 Aug 2003 12 * 13 * $Id: MimeType.java,v 1.5 2005/01/11 13:51:31 ian Exp $ 14 */ 15 16 package gate.corpora; 17 18 import java.util.HashMap; 19 import java.util.Map; 20 21 /** 22 * A very basic implementation for a MIME Type. 23 */ 24 public class MimeType { 25 /** 26 * Constructor from type and subtype. 27 * @param type 28 * @param subType 29 */ 30 public MimeType(String type, String subType){ 31 this.type = type; 32 this.subtype = subType; 33 parameters = new HashMap(); 34 } 35 36 /** 37 * Two MIME Types are equal if their types and subtypes coincide. 38 * @param other the othe MIME Type to be compared with this one. 39 * @return true if the two MIME Types are the same. 40 */ 41 public boolean equals(Object other){ 42 return type.equals(((MimeType)other).getType()) && 43 subtype.equals(((MimeType)other).getSubtype()); 44 } 45 46 /** 47 * The hashcode is composed (by addition) from the hashcodes for the type and 48 * subtype. 49 * @return and integer. 50 */ 51 public int hashCode(){ 52 return (type == null ? 0 : type.hashCode()) + 53 (subtype == null ? 0 : subtype.hashCode()); 54 } 55 56 /** 57 * Returns the type component of this MIME Type. 58 * @return a String value. 59 */ 60 public String getType() { 61 return type; 62 } 63 64 /** 65 * Sets the type component of this MIME type. 66 * @param type a String value. 67 */ 68 public void setType(String type) { 69 this.type = type; 70 } 71 72 /** 73 * Returns the subtype component of this MIME Type. 74 * @return a String value. 75 */ 76 public String getSubtype() { 77 return subtype; 78 } 79 80 /** 81 * Sets the subtype component of this MIME type. 82 * @param subtype a String value. 83 */ 84 public void setSubtype(String subtype) { 85 this.subtype = subtype; 86 } 87 88 /** 89 * Adds (and replaces if necessary) a parameter to this MIME type. 90 * @param param the name of the parameter. 91 * @param value the value of the parameter. 92 */ 93 public void addParameter(java.lang.String param, java.lang.String value){ 94 parameters.put(param, value); 95 } 96 97 /** 98 * Gets the value for a particular parameter. 99 * @param name the name of the parameter. 100 * @return a {@link java.lang.String} value. 101 */ 102 public java.lang.String getParameterValue(java.lang.String name){ 103 return (String)parameters.get(name); 104 } 105 106 /** 107 * Checks to see if this MIME type has a particular parameter. 108 * @param name the name of the parameter. 109 * @return a boolean value. 110 */ 111 public boolean hasParameter(java.lang.String name){ 112 return parameters.containsKey(name); 113 } 114 115 /** 116 * The type component 117 */ 118 protected String type; 119 120 /** 121 * The subtype component 122 */ 123 protected String subtype; 124 125 /** 126 * The parameters map. 127 */ 128 protected Map parameters; 129 }