1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 package com.hughes.android.dictionary;
17 import java.io.Serializable;
18 import java.util.ArrayList;
19 import java.util.List;
21 public class DictionaryInfo implements Serializable {
23 private static final long serialVersionUID = -6850863377577700388L;
25 public static final class IndexInfo implements Serializable {
26 private static final long serialVersionUID = 6524751236198309438L;
28 public IndexInfo(String langIso, int allTokenCount, int mainTokenCount) {
29 this.langIso = langIso;
30 this.allTokenCount = allTokenCount;
31 this.mainTokenCount = mainTokenCount;
33 public final String langIso;
34 public final int allTokenCount;
35 public final int mainTokenCount;
37 public static final int SIZE = 3;
39 public StringBuilder append(StringBuilder result) {
40 result.append(langIso);
41 result.append("\t").append(allTokenCount);
42 result.append("\t").append(mainTokenCount);
46 public IndexInfo(final String[] fields, int i) {
47 langIso = fields[i++];
48 allTokenCount = Integer.parseInt(fields[i++]);
49 mainTokenCount = Integer.parseInt(fields[i++]);
54 // Stuff populated from the text file.
55 public String uncompressedFilename;
56 public String downloadUrl;
57 public long uncompressedSize;
58 public long creationMillis;
59 public final List<IndexInfo> indexInfos = new ArrayList<DictionaryInfo.IndexInfo>();
60 public String dictInfo;
62 String name; // Determined at runtime based on locale on device--user editable?
63 String localFile; // Determined based on device's Environment.
65 public StringBuilder append(final StringBuilder result) {
66 result.append(uncompressedFilename);
67 result.append("\t").append(downloadUrl);
68 result.append("\t").append(creationMillis);
69 result.append("\t").append(uncompressedSize);
70 result.append("\t").append(indexInfos.size());
71 for (final IndexInfo indexInfo : indexInfos) {
72 indexInfo.append(result.append("\t"));
74 result.append("\t").append(dictInfo.replaceAll("\n", "\\\\n"));
78 public DictionaryInfo(final String line) {
79 final String[] fields = line.split("\t");
81 uncompressedFilename = fields[i++];
82 downloadUrl = fields[i++];
83 creationMillis = Long.parseLong(fields[i++]);
84 uncompressedSize = Long.parseLong(fields[i++]);
85 final int size = Integer.parseInt(fields[i++]);
86 for (int j = 0; j < size; ++j) {
87 indexInfos.add(new IndexInfo(fields, i));
90 dictInfo = fields[i++].replaceAll("\\n", "\n");
93 public DictionaryInfo() {
98 public String toString() {