]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/DictionaryInfo.java
Fixed themes, fixing DictionaryInfo, DictionaryVersion 2. Better
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryInfo.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 package com.hughes.android.dictionary;
16
17 import java.io.Serializable;
18 import java.util.ArrayList;
19 import java.util.List;
20
21 public class DictionaryInfo implements Serializable {
22   
23   private static final long serialVersionUID = -6850863377577700388L;
24   
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;
30     }
31     public final String langIso;
32     public final int allTokenCount;
33     public final int mainTokenCount;
34     
35     public static final int SIZE = 3;
36     
37     public StringBuilder append(StringBuilder result) {
38       result.append("\t").append(langIso);
39       result.append("\t").append(allTokenCount);
40       result.append("\t").append(mainTokenCount);
41       return result;
42     }
43
44     public IndexInfo(final String[] fields, int i) {
45       langIso = fields[i++];
46       allTokenCount = Integer.parseInt(fields[i++]);
47       mainTokenCount = Integer.parseInt(fields[i++]);
48     }
49
50   }
51   
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>();
59
60   String name;  // Determined at runtime based on locale on device--user editable?
61   String localFile;  // Determined based on device's Environment.
62   
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);
72     }
73     return result;
74   }
75
76   public DictionaryInfo(final String line) {
77     final String[] fields = line.split("\t");
78     int i = 0;
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));
87       i += IndexInfo.SIZE;
88     }
89   }
90
91   public DictionaryInfo() {
92     // Blank object.
93   }
94
95   @Override
96   public String toString() {
97     return name;
98   }
99
100
101 }