jp.zippyzip.Pref.java Source code

Java tutorial

Introduction

Here is the source code for jp.zippyzip.Pref.java

Source

/*
 * zippyzipjp
 * 
 * Copyright 2008-2010 Michinobu Maeda.
 * 
 * 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 jp.zippyzip;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONStringer;

/**
 * ??
 * 
 * @author Michinobu Maeda
 */
public class Pref {

    /** */
    protected static Logger log = Logger.getLogger(Pref.class.getName());

    /**  */
    private String code;

    /** ?? */
    private String name;

    /** ? */
    private String yomi;

    /**
     * JSON ???
     * 
     * @param json JSON
     * @return 
     */
    public static Pref fromJson(String json) {

        Pref ret = null;

        try {

            JSONObject jo = new JSONObject(json);

            ret = new Pref(jo.optString("code", ""), jo.optString("name", ""), jo.optString("yomi", ""));

        } catch (JSONException e) {
            log.log(Level.WARNING, "", e);
        }

        return ret;
    }

    /**
     * 
     */
    public Pref() {
        this("", "", "");
    }

    /**
     * ???
     * 
     * @param code 
     * @param name ??
     * @param yomi ?
     */
    public Pref(String code, String name, String yomi) {

        this.code = code;
        this.name = name;
        this.yomi = yomi;
    }

    /**
     * ??
     * 
     * @return 
     */
    public String getCode() {
        return code;
    }

    /**
     * ?
     * 
     * @param code 
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * ????
     * 
     * @return ??
     */
    public String getName() {
        return name;
    }

    /**
     * ???
     * 
     * @param name ??
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * ???
     * 
     * @return ?
     */
    public String getYomi() {
        return yomi;
    }

    /**
     * ??
     * 
     * @param yomi ?
     */
    public void setYomi(String yomi) {
        this.yomi = yomi;
    }

    /**
     * JSON ??
     * 
     * @returnJSON
     */
    public String toJson() {

        String ret = null;

        try {

            ret = new JSONStringer().object().key("code").value(code).key("name").value(name).key("yomi")
                    .value(yomi).endObject().toString();

        } catch (JSONException e) {
            log.log(Level.WARNING, "", e);
        }

        return ret;
    }
}