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 {
26 public IndexInfo(String langIso, int allTokenCount, int mainTokenCount) {
27 this.langIso = langIso;
28 this.allTokenCount = allTokenCount;
29 this.mainTokenCount = mainTokenCount;
31 public final String langIso;
32 public final int allTokenCount;
33 public final int mainTokenCount;
35 public static final int SIZE = 3;
37 public StringBuilder append(StringBuilder result) {
38 result.append("\t").append(langIso);
39 result.append("\t").append(allTokenCount);
40 result.append("\t").append(mainTokenCount);
44 public IndexInfo(final String[] fields, int i) {
45 langIso = fields[i++];
46 allTokenCount = Integer.parseInt(fields[i++]);
47 mainTokenCount = Integer.parseInt(fields[i++]);
52 // Stuff populated from the text file.
53 public String uncompressedFilename;
54 public String downloadUrl;
55 public long uncompressedSize;
56 public long creationMillis;
57 public String dictInfo;
58 public final List<IndexInfo> indexInfos = new ArrayList<DictionaryInfo.IndexInfo>();
60 String name; // Determined at runtime based on locale on device--user editable?
61 String localFile; // Determined based on device's Environment.
63 public StringBuilder append(final StringBuilder result) {
64 result.append(uncompressedFilename).append("\t");
65 result.append(downloadUrl).append("\t");
66 result.append(creationMillis).append("\t");
67 result.append(uncompressedSize).append("\t");
68 result.append(dictInfo).append("\t");
69 result.append(indexInfos.size()).append("\t");
70 for (final IndexInfo indexInfo : indexInfos) {
71 indexInfo.append(result);
76 public DictionaryInfo(final String line) {
77 final String[] fields = line.split("\t");
79 uncompressedFilename = fields[i++];
80 downloadUrl = fields[i++];
81 creationMillis = Long.parseLong(fields[i++]);
82 uncompressedSize = Long.parseLong(fields[i++]);
83 dictInfo = fields[i++];
84 final int size = Integer.parseInt(fields[i++]);
85 for (int j = 0; j < size; ++j) {
86 indexInfos.add(new IndexInfo(fields, i));
91 public DictionaryInfo() {
96 public String toString() {