001 /*
002 * TextualDocumentFormat.java
003 *
004 * Copyright (c) 1995-2010, The University of Sheffield. See the file
005 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006 *
007 * This file is part of GATE (see http://gate.ac.uk/), and is free
008 * software, licenced under the GNU Library General Public License,
009 * Version 2, June 1991 (in the distribution as file licence.html,
010 * and also available at http://gate.ac.uk/gate/licence.html).
011 *
012 * Valentin Tablan 27 Aug 2003
013 *
014 * $Id: MimeType.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015 */
016
017 package gate.corpora;
018
019 import java.util.HashMap;
020 import java.util.Map;
021
022 /**
023 * A very basic implementation for a MIME Type.
024 */
025 public class MimeType {
026 /**
027 * Constructor from type and subtype.
028 * @param type
029 * @param subType
030 */
031 public MimeType(String type, String subType){
032 this.type = type;
033 this.subtype = subType;
034 parameters = new HashMap();
035 }
036
037 /**
038 * Two MIME Types are equal if their types and subtypes coincide.
039 * @param other the othe MIME Type to be compared with this one.
040 * @return true if the two MIME Types are the same.
041 */
042 public boolean equals(Object other){
043 return type.equals(((MimeType)other).getType()) &&
044 subtype.equals(((MimeType)other).getSubtype());
045 }
046
047 /**
048 * The hashcode is composed (by addition) from the hashcodes for the type and
049 * subtype.
050 * @return and integer.
051 */
052 public int hashCode(){
053 return (type == null ? 0 : type.hashCode()) +
054 (subtype == null ? 0 : subtype.hashCode());
055 }
056
057 /**
058 * Returns the type component of this MIME Type.
059 * @return a String value.
060 */
061 public String getType() {
062 return type;
063 }
064
065 /**
066 * Sets the type component of this MIME type.
067 * @param type a String value.
068 */
069 public void setType(String type) {
070 this.type = type;
071 }
072
073 /**
074 * Returns the subtype component of this MIME Type.
075 * @return a String value.
076 */
077 public String getSubtype() {
078 return subtype;
079 }
080
081 /**
082 * Sets the subtype component of this MIME type.
083 * @param subtype a String value.
084 */
085 public void setSubtype(String subtype) {
086 this.subtype = subtype;
087 }
088
089 /**
090 * Adds (and replaces if necessary) a parameter to this MIME type.
091 * @param param the name of the parameter.
092 * @param value the value of the parameter.
093 */
094 public void addParameter(java.lang.String param, java.lang.String value){
095 parameters.put(param, value);
096 }
097
098 /**
099 * Gets the value for a particular parameter.
100 * @param name the name of the parameter.
101 * @return a {@link java.lang.String} value.
102 */
103 public java.lang.String getParameterValue(java.lang.String name){
104 return (String)parameters.get(name);
105 }
106
107 /**
108 * Checks to see if this MIME type has a particular parameter.
109 * @param name the name of the parameter.
110 * @return a boolean value.
111 */
112 public boolean hasParameter(java.lang.String name){
113 return parameters.containsKey(name);
114 }
115
116 /**
117 * The type component
118 */
119 protected String type;
120
121 /**
122 * The subtype component
123 */
124 protected String subtype;
125
126 /**
127 * The parameters map.
128 */
129 protected Map parameters;
130 }
|