PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/ocr/ocrservice/src/com/googlecode/eyesfree/ocr/client/Language.java

http://eyes-free.googlecode.com/
Java | 106 lines | 49 code | 15 blank | 42 comment | 0 complexity | 3e22a9499100a3afe629e9307a6c565e MD5 | raw file
  1/*
  2 * Copyright (C) 2011 Google Inc.
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5 * use this file except in compliance with the License. You may obtain a copy of
  6 * the License at
  7 *
  8 * http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13 * License for the specific language governing permissions and limitations under
 14 * the License.
 15 */
 16
 17package com.googlecode.eyesfree.ocr.client;
 18
 19import android.os.Parcel;
 20import android.os.Parcelable;
 21
 22/**
 23 * This class represents a language with three different interpretations:
 24 * <ol>
 25 * <li>An English name
 26 * <li>An ISO 639-1 code, as used by Google Translate
 27 * <li>An ISO 639-2 code, as used by Tesseract
 28 * </ol>
 29 *
 30 * @author alanv@google.com (Alan Viverette)
 31 */
 32public class Language implements Comparable<Language>, Parcelable {
 33    /** The English representation of this language. */
 34    public String english;
 35
 36    /**
 37     * The ISO 639-1 representation of this language (as used by Google
 38     * Translate).
 39     */
 40    public String iso_639_1;
 41
 42    /** The ISO 639-2 representation of this language (as used by Tesseract). */
 43    public String iso_639_2;
 44
 45    /**
 46     * Constructs a new language with an English name, an ISO 639-1 code, and an
 47     * ISO 639-2 code.
 48     *
 49     * @param en The English name of the language.
 50     * @param i1 The language's ISO 639-1 code.
 51     * @param i2 The language's ISO 639-2 code.
 52     */
 53    public Language(String en, String i1, String i2) {
 54        english = en;
 55        iso_639_1 = i1;
 56        iso_639_2 = i2;
 57    }
 58
 59    @Override
 60    public int compareTo(Language another) {
 61        return english.compareTo(another.english);
 62    }
 63
 64    @Override
 65    public String toString() {
 66        return english;
 67    }
 68
 69    /************************
 70     * Parcelable functions *
 71     ************************/
 72
 73    private Language(Parcel src) {
 74        readFromParcel(src);
 75    }
 76
 77    @Override
 78    public int describeContents() {
 79        return 0;
 80    }
 81
 82    @Override
 83    public void writeToParcel(Parcel dest, int flags) {
 84        dest.writeString(english);
 85        dest.writeString(iso_639_1);
 86        dest.writeString(iso_639_2);
 87    }
 88
 89    private void readFromParcel(Parcel src) {
 90        english = src.readString();
 91        iso_639_1 = src.readString();
 92        iso_639_2 = src.readString();
 93    }
 94
 95    public static final Parcelable.Creator<Language> CREATOR = new Parcelable.Creator<Language>() {
 96        @Override
 97        public Language createFromParcel(Parcel in) {
 98            return new Language(in);
 99        }
100
101        @Override
102        public Language[] newArray(int size) {
103            return new Language[size];
104        }
105    };
106}