001/*
002 * Copyright (c) 2012, the Last.fm Java Project and Committers
003 * All rights reserved.
004 *
005 * Redistribution and use of this software in source and binary forms, with or without modification, are
006 * permitted provided that the following conditions are met:
007 *
008 * - Redistributions of source code must retain the above
009 *   copyright notice, this list of conditions and the
010 *   following disclaimer.
011 *
012 * - Redistributions in binary form must reproduce the above
013 *   copyright notice, this list of conditions and the
014 *   following disclaimer in the documentation and/or other
015 *   materials provided with the distribution.
016 *
017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
018 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
019 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
020 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
021 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
023 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
024 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
025 */
026package de.umass.lastfm.scrobble;
027
028import java.util.HashMap;
029import java.util.Map;
030
031/**
032 * Enumeration representing the ignored message code returned by scrobble and now playing requests.
033 *
034 * @author Adrian Woodhead
035 */
036public enum IgnoredMessageCode {
037
038        ARTIST_IGNORED(1),
039        TRACK_IGNORED(2),
040        TIMESTAMP_TOO_OLD(3),
041        TIMESTAMP_TOO_NEW(4),
042        DAILY_SCROBBLE_LIMIT_EXCEEDED(5);
043
044        /**
045         * The ignored message error id returned by the Last.fm API.
046         */
047        private int codeId;
048
049        /**
050         * A map which maps error codes against their corresponding enums for lookups by code.
051         */
052        private static Map<Integer, IgnoredMessageCode> idToCodeMap = new HashMap<Integer, IgnoredMessageCode>();
053
054        static {
055                for (IgnoredMessageCode code : IgnoredMessageCode.values()) {
056                        idToCodeMap.put(code.getCodeId(), code);
057                }
058        }
059
060        private IgnoredMessageCode(int code) {
061                this.codeId = code;
062        }
063
064        /**
065         * Gets the IgnoredMessage enum value for the passed Last.fm error code.
066         *
067         * @param code The Last.fm error code.
068         * @return The appopriate IgnoredMessage enum value.
069         */
070        public static IgnoredMessageCode valueOfCode(int code) {
071                IgnoredMessageCode messageCode = idToCodeMap.get(code);
072                if (messageCode != null) {
073                        return messageCode;
074                }
075                throw new IllegalArgumentException("No IgnoredMessageCode for code " + code);
076        }
077
078        private int getCodeId() {
079                return codeId;
080        }
081
082}