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