cn.cuizuoli.appranking.enumeration.FeedType.java Source code

Java tutorial

Introduction

Here is the source code for cn.cuizuoli.appranking.enumeration.FeedType.java

Source

/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.cuizuoli.appranking.enumeration;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

/**
 * FeedType
 * @author cuizuoli
 */
public enum FeedType {
    TOP_FREE_APPLICATIONS("topfreeapplications", "?", MediaType.IOS_APPS), TOP_PAID_APPLICATIONS(
            "toppaidapplications", "",
            MediaType.IOS_APPS), TOP_FREE_IPAD_APPLICATIONS("topfreeipadapplications", "?iPad",
                    MediaType.IOS_APPS), TOP_PAID_IPAD_APPLICATIONS("toppaidipadapplications",
                            "iPad", MediaType.IOS_APPS), NEW_APPLICATIONS("newapplications",
                                    "", MediaType.IOS_APPS), NEW_FREE_APPLICATIONS(
                                            "newfreeapplications", "?",
                                            MediaType.IOS_APPS), TOPSELLING_FREE("topselling_free", "?",
                                                    MediaType.GOOGLE), TOPSELLING_PAID("topselling_paid",
                                                            "", MediaType.GOOGLE), TOPSELLING_NEW_FREE(
                                                                    "topselling_new_free", "??",
                                                                    MediaType.GOOGLE), TOPSELLING_NEW_PAID(
                                                                            "topselling_new_paid",
                                                                            "?", MediaType.GOOGLE);

    private final String code;
    private final String name;
    private final MediaType mediaType;

    private FeedType(String code, String name, MediaType mediaType) {
        this.code = code;
        this.name = name;
        this.mediaType = mediaType;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public MediaType getMediaType() {
        return mediaType;
    }

    /**
     * getFeedType
     * @param mediaType
     * @return
     */
    public static List<FeedType> getFeedType(MediaType mediaType) {
        List<FeedType> feedTypeList = new ArrayList<FeedType>();
        for (FeedType feedType : FeedType.values()) {
            if (feedType.getMediaType() == mediaType) {
                feedTypeList.add(feedType);
            }
        }
        return feedTypeList;
    }

    /**
     * getObject
     * @param code
     * @return
     */
    public static FeedType getObject(String code) {
        for (FeedType feedType : FeedType.values()) {
            if (StringUtils.equals(feedType.getCode(), code)) {
                return feedType;
            }
        }
        return null;
    }
}