/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. package com.googlecode.eyesfree.ocr.client;
  17. import android.os.Parcel;
  18. import android.os.Parcelable;
  19. /**
  20. * This class represents a language with three different interpretations:
  21. * <ol>
  22. * <li>An English name
  23. * <li>An ISO 639-1 code, as used by Google Translate
  24. * <li>An ISO 639-2 code, as used by Tesseract
  25. * </ol>
  26. *
  27. * @author alanv@google.com (Alan Viverette)
  28. */
  29. public class Language implements Comparable<Language>, Parcelable {
  30. /** The English representation of this language. */
  31. public String english;
  32. /**
  33. * The ISO 639-1 representation of this language (as used by Google
  34. * Translate).
  35. */
  36. public String iso_639_1;
  37. /** The ISO 639-2 representation of this language (as used by Tesseract). */
  38. public String iso_639_2;
  39. /**
  40. * Constructs a new language with an English name, an ISO 639-1 code, and an
  41. * ISO 639-2 code.
  42. *
  43. * @param en The English name of the language.
  44. * @param i1 The language's ISO 639-1 code.
  45. * @param i2 The language's ISO 639-2 code.
  46. */
  47. public Language(String en, String i1, String i2) {
  48. english = en;
  49. iso_639_1 = i1;
  50. iso_639_2 = i2;
  51. }
  52. @Override
  53. public int compareTo(Language another) {
  54. return english.compareTo(another.english);
  55. }
  56. @Override
  57. public String toString() {
  58. return english;
  59. }
  60. /************************
  61. * Parcelable functions *
  62. ************************/
  63. private Language(Parcel src) {
  64. readFromParcel(src);
  65. }
  66. @Override
  67. public int describeContents() {
  68. return 0;
  69. }
  70. @Override
  71. public void writeToParcel(Parcel dest, int flags) {
  72. dest.writeString(english);
  73. dest.writeString(iso_639_1);
  74. dest.writeString(iso_639_2);
  75. }
  76. private void readFromParcel(Parcel src) {
  77. english = src.readString();
  78. iso_639_1 = src.readString();
  79. iso_639_2 = src.readString();
  80. }
  81. public static final Parcelable.Creator<Language> CREATOR = new Parcelable.Creator<Language>() {
  82. @Override
  83. public Language createFromParcel(Parcel in) {
  84. return new Language(in);
  85. }
  86. @Override
  87. public Language[] newArray(int size) {
  88. return new Language[size];
  89. }
  90. };
  91. }