com.ccc.crest.core.cache.crest.tournament.TournamentMatchFrame.java Source code

Java tutorial

Introduction

Here is the source code for com.ccc.crest.core.cache.crest.tournament.TournamentMatchFrame.java

Source

/*
**  Copyright (c) 2016, Chad Adams.
**
**  This program is free software: you can redistribute it and/or modify
**  it under the terms of the GNU Lesser General Public License as
**  published by the Free Software Foundation, either version 3 of the
**  License, or any later version.
**
**  This program is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**  GNU General Public License for more details.
    
**  You should have received copies of the GNU GPLv3 and GNU LGPLv3
**  licenses along with this program.  If not, see http://www.gnu.org/licenses
*/
package com.ccc.crest.core.cache.crest.tournament;

import java.lang.reflect.Type;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;

import com.ccc.crest.core.CrestController;
import com.ccc.crest.core.ScopeToMask;
import com.ccc.crest.core.cache.BaseEveData;
import com.ccc.crest.core.cache.CrestRequestData;
import com.ccc.crest.core.cache.EveData;
import com.ccc.crest.core.cache.crest.schema.SchemaMap;
import com.ccc.crest.core.client.CrestResponseCallback;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

@SuppressWarnings("javadoc")
public class TournamentMatchFrame extends BaseEveData implements JsonDeserializer<TournamentMatchFrame> {
    private static final long serialVersionUID = -2711682230241156568L;
    private static final AtomicBoolean continueRefresh = new AtomicBoolean(false);
    public static final String PostBase = null;
    public static final String GetBase = "application/vnd.ccp.eve.TournamentRealtimeMatchFrame";
    public static final String PutBase = null;
    public static final String DeleteBase = null;
    public static final String AccessGroup = CrestController.AnonymousGroupName;
    public static final ScopeToMask.Type ScopeType = ScopeToMask.Type.CrestOnly; //?
    private static final String ReadScope = null;
    private static final String WriteScope = null;

    private volatile Tournaments tournaments;

    public TournamentMatchFrame() {
    }

    public Tournaments getTournaments() {
        return tournaments;
    }

    public static String getVersion(VersionType type) {
        switch (type) {
        case Delete:
            return SchemaMap.schemaMap.getSchemaFromVersionBase(DeleteBase).getVersion();
        case Get:
            return SchemaMap.schemaMap.getSchemaFromVersionBase(GetBase).getVersion();
        case Post:
            return SchemaMap.schemaMap.getSchemaFromVersionBase(PostBase).getVersion();
        case Put:
            return SchemaMap.schemaMap.getSchemaFromVersionBase(PutBase).getVersion();
        default:
            return null;
        }
    }

    public static String getUrl() {
        return SchemaMap.schemaMap.getSchemaFromVersionBase(GetBase).getUri();
    }

    public static Future<EveData> getFuture(CrestResponseCallback callback) throws Exception {
        GsonBuilder gson = new GsonBuilder();
        gson.registerTypeAdapter(TournamentMatchFrame.class, new TournamentMatchFrame());

        //@formatter:off
        CrestRequestData rdata = new CrestRequestData(null, getUrl(), gson.create(), null,
                TournamentMatchFrame.class, callback, ReadScope, getVersion(VersionType.Get), continueRefresh,
                false);
        //@formatter:on
        return CrestController.getCrestController().crestClient.getCrest(rdata);
    }

    @Override
    public TournamentMatchFrame deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
            throws JsonParseException {
        tournaments = new Tournaments();
        tournaments = tournaments.deserialize(json, typeOfT, context);
        if (log.isDebugEnabled())
            log.debug(tournaments.toString());
        return this;
    }
}