001package ezvcard.parameter;
002
003import java.util.Collection;
004
005import ezvcard.property.Sound;
006
007/*
008 * Copyright 2011 George El-Haddad. All rights reserved.
009 * 
010 * Redistribution and use in source and binary forms, with or without modification, are
011 * permitted provided that the following conditions are met:
012 * 
013 *    1. Redistributions of source code must retain the above copyright notice, this list of
014 *       conditions and the following disclaimer.
015 * 
016 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
017 *       of conditions and the following disclaimer in the documentation and/or other materials
018 *       provided with the distribution.
019 * 
020 * THIS SOFTWARE IS PROVIDED BY GEORGE EL-HADDAD ''AS IS'' AND ANY EXPRESS OR IMPLIED
021 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
022 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEORGE EL-HADDAD OR
023 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
027 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
028 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 * 
030 * The views and conclusions contained in the software and documentation are those of the
031 * authors and should not be interpreted as representing official policies, either expressed
032 * or implied, of George El-Haddad.
033 */
034
035/*
036 Copyright (c) 2012-2023, Michael Angstadt
037 All rights reserved.
038
039 Redistribution and use in source and binary forms, with or without
040 modification, are permitted provided that the following conditions are met: 
041
042 1. Redistributions of source code must retain the above copyright notice, this
043 list of conditions and the following disclaimer. 
044 2. Redistributions in binary form must reproduce the above copyright notice,
045 this list of conditions and the following disclaimer in the documentation
046 and/or other materials provided with the distribution. 
047
048 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
049 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
050 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
051 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
052 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
053 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
054 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
055 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
056 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
057 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
058
059 The views and conclusions contained in the software and documentation are those
060 of the authors and should not be interpreted as representing official policies, 
061 either expressed or implied, of the FreeBSD Project.
062 */
063
064/**
065 * Represents the TYPE parameter of the {@link Sound} property.
066 * <p>
067 * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
068 * </p>
069 * @author George El-Haddad Mar 10, 2010
070 * @author Michael Angstadt
071 */
072public class SoundType extends MediaTypeParameter {
073        private static final MediaTypeCaseClasses<SoundType> enums = new MediaTypeCaseClasses<>(SoundType.class);
074
075        public static final SoundType AAC = new SoundType("AAC", "audio/aac", "aac");
076        public static final SoundType MIDI = new SoundType("MIDI", "audio/midi", "mid");
077        public static final SoundType MP3 = new SoundType("MP3", "audio/mp3", "mp3");
078        public static final SoundType MPEG = new SoundType("MPEG", "audio/mpeg", "mpeg");
079        public static final SoundType OGG = new SoundType("OGG", "audio/ogg", "ogg");
080        public static final SoundType WAV = new SoundType("WAV", "audio/wav", "wav");
081
082        private SoundType(String value, String mediaType, String extension) {
083                super(value, mediaType, extension);
084        }
085
086        /**
087         * Searches for a parameter value that is defined as a static constant in
088         * this class.
089         * @param type the TYPE parameter value to search for (e.g. "MP3") or null
090         * to not search by this value
091         * @param mediaType the media type to search for (e.g. "audio/mp3") or null
092         * to not search by this value
093         * @param extension the file extension to search for (excluding the ".",
094         * e.g. "mp3") or null to not search by this value
095         * @return the object or null if not found
096         */
097        public static SoundType find(String type, String mediaType, String extension) {
098                return enums.find(new String[] { type, mediaType, extension });
099        }
100
101        /**
102         * Searches for a parameter value and creates one if it cannot be found. All
103         * objects are guaranteed to be unique, so they can be compared with
104         * {@code ==} equality.
105         * @param type the TYPE parameter value to search for (e.g. "MP3") or null
106         * to not search by this value
107         * @param mediaType the media type to search for (e.g. "audio/mp3") or null
108         * to not search by this value
109         * @param extension the file extension to search for (excluding the ".",
110         * e.g. "mp3") or null to not search by this value
111         * @return the object
112         */
113        public static SoundType get(String type, String mediaType, String extension) {
114                return enums.get(new String[] { type, mediaType, extension });
115        }
116
117        /**
118         * Gets all of the parameter values that are defined as static constants in
119         * this class.
120         * @return the parameter values
121         */
122        public static Collection<SoundType> all() {
123                return enums.all();
124        }
125}