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;
20 public class DictionaryInfo implements Serializable {
22 private static final long serialVersionUID = -6850863377577700388L;
24 public static final class IndexInfo implements Serializable {
25 private static final long serialVersionUID = 6524751236198309438L;
27 static final int NUM_CSV_FIELDS = 3;
29 public final String shortName; // Often LangISO.
30 final int allTokenCount;
31 public final int mainTokenCount;
33 public IndexInfo(String shortName, int allTokenCount, int mainTokenCount) {
34 this.shortName = shortName;
35 this.allTokenCount = allTokenCount;
36 this.mainTokenCount = mainTokenCount;
39 void append(StringBuilder result) {
40 result.append(shortName);
41 result.append("\t").append(allTokenCount);
42 result.append("\t").append(mainTokenCount);
45 public IndexInfo(final String[] fields, int i) {
46 shortName = fields[i++];
47 allTokenCount = Integer.parseInt(fields[i++]);
48 mainTokenCount = Integer.parseInt(fields[i++]);
52 // Stuff populated from the text file.
53 public String uncompressedFilename; // used as a key throughout the program.
54 public String downloadUrl;
55 public long uncompressedBytes;
57 public long creationMillis;
58 public final ArrayList<IndexInfo> indexInfos = new ArrayList<>();
59 public String dictInfo;
61 public DictionaryInfo() {
65 public boolean isValid() {
66 return indexInfos != null && !indexInfos.isEmpty();
69 public StringBuilder append(final StringBuilder result) {
70 result.append(uncompressedFilename);
71 result.append("\t").append(downloadUrl);
72 result.append("\t").append(creationMillis);
73 result.append("\t").append(uncompressedBytes);
74 result.append("\t").append(zipBytes);
75 result.append("\t").append(indexInfos.size());
76 for (final IndexInfo indexInfo : indexInfos) {
77 indexInfo.append(result.append("\t"));
79 result.append("\t").append(dictInfo.replace("\n", "\\\\n"));
83 public DictionaryInfo(final String line) {
84 final String[] fields = line.split("\t");
86 uncompressedFilename = fields[i++];
87 downloadUrl = fields[i++];
88 creationMillis = Long.parseLong(fields[i++]);
89 uncompressedBytes = Long.parseLong(fields[i++]);
90 zipBytes = Long.parseLong(fields[i++]);
91 final int size = Integer.parseInt(fields[i++]);
92 indexInfos.ensureCapacity(size);
93 for (int j = 0; j < size; ++j) {
94 indexInfos.add(new IndexInfo(fields, i));
95 i += IndexInfo.NUM_CSV_FIELDS;
97 dictInfo = fields[i++].replace("\\\\n", "\n");
101 public String toString() {
102 return uncompressedFilename;