Debian Codegraph @

src/main/java/ezvcard/parameter/MediaTypeParameter.java

raw symbols SCIP
1 package ezvcard.parameter;
2
3 /*
4 Copyright (c) 2012-2023, Michael Angstadt
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 The views and conclusions contained in the software and documentation are those
28 of the authors and should not be interpreted as representing official policies,
29 either expressed or implied, of the FreeBSD Project.
30 */
31
32 /**
33 * Represents a TYPE parameter that also has a media type associated with it.
34 * The TYPE parameter value is used in 2.1 and 3.0 vCards, while the media type
35 * value is used in 4.0 vCards.
36 * @author Michael Angstadt
37 */
38 public class MediaTypeParameter extends VCardParameter {
39 protected final String mediaType;
40 protected final String extension;
41
42 /**
43 * @param value the TYPE parameter value (e.g. "JPEG")
44 * @param mediaType the media type (e.g. "image/jpeg")
45 * @param extension the file extension (e.g. "jpg")
46 */
47 public MediaTypeParameter(String value, String mediaType, String extension) {
48 super(value);
49 this.mediaType = mediaType;
50 this.extension = extension;
51 }
52
53 /**
54 * Gets the media type.
55 * @return the media type (e.g. "image/jpeg")
56 */
57 public String getMediaType() {
58 return mediaType;
59 }
60
61 /**
62 * Gets the file extension.
63 * @return the file extension (e.g. "jpg")
64 */
65 public String getExtension() {
66 return extension;
67 }
68
69 @Override
70 public int hashCode() {
71 final int prime = 31;
72 int result = super.hashCode();
73 result = prime * result + ((extension == null) ? 0 : extension.hashCode());
74 result = prime * result + ((mediaType == null) ? 0 : mediaType.hashCode());
75 return result;
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj)
81 return true;
82 if (!super.equals(obj))
83 return false;
84 if (getClass() != obj.getClass())
85 return false;
86 MediaTypeParameter other = (MediaTypeParameter) obj;
87 if (extension == null) {
88 if (other.extension != null)
89 return false;
90 } else if (!extension.equals(other.extension))
91 return false;
92 if (mediaType == null) {
93 if (other.mediaType != null)
94 return false;
95 } else if (!mediaType.equals(other.mediaType))
96 return false;
97 return true;
98 }
99 }