001 package ezvcard.parameter;
002
003 /*
004 Copyright (c) 2013, Michael Angstadt
005 All rights reserved.
006
007 Redistribution and use in source and binary forms, with or without
008 modification, are permitted provided that the following conditions are met:
009
010 1. Redistributions of source code must retain the above copyright notice, this
011 list of conditions and the following disclaimer.
012 2. Redistributions in binary form must reproduce the above copyright notice,
013 this list of conditions and the following disclaimer in the documentation
014 and/or other materials provided with the distribution.
015
016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
020 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026
027 The views and conclusions contained in the software and documentation are those
028 of the authors and should not be interpreted as representing official policies,
029 either expressed or implied, of the FreeBSD Project.
030 */
031
032 /**
033 * Represents a TYPE parameter that also has a media type associated with it.
034 * The TYPE parameter value is used in 2.1 and 3.0 vCards, while the media type
035 * value is used in 4.0 vCards.
036 * @author Michael Angstadt
037 */
038 public class MediaTypeParameter extends VCardParameter {
039 protected final String mediaType;
040 protected final String extension;
041
042 /**
043 * @param value the TYPE parameter value (e.g. "JPEG")
044 * @param mediaType the media type (e.g. "image/jpeg")
045 * @param extension the file extension (e.g. "jpg")
046 */
047 public MediaTypeParameter(String value, String mediaType, String extension) {
048 super(value);
049 this.mediaType = mediaType;
050 this.extension = extension;
051 }
052
053 /**
054 * Gets the media type.
055 * @return the media type (e.g. "image/jpeg")
056 */
057 public String getMediaType() {
058 return mediaType;
059 }
060
061 /**
062 * Gets the file extension.
063 * @return the file extension (e.g. "jpg")
064 */
065 public String getExtension() {
066 return extension;
067 }
068
069 @Override
070 public int hashCode() {
071 final int prime = 31;
072 int result = super.hashCode();
073 result = prime * result + ((extension == null) ? 0 : extension.hashCode());
074 result = prime * result + ((mediaType == null) ? 0 : mediaType.hashCode());
075 return result;
076 }
077
078 @Override
079 public boolean equals(Object obj) {
080 if (this == obj)
081 return true;
082 if (!super.equals(obj))
083 return false;
084 if (getClass() != obj.getClass())
085 return false;
086 MediaTypeParameter other = (MediaTypeParameter) obj;
087 if (extension == null) {
088 if (other.extension != null)
089 return false;
090 } else if (!extension.equals(other.extension))
091 return false;
092 if (mediaType == null) {
093 if (other.mediaType != null)
094 return false;
095 } else if (!mediaType.equals(other.mediaType))
096 return false;
097 return true;
098 }
099 }