Skip to content

Commit c383b7f

Browse files
committed
Use the new OrderedProperties in all the project.
1 parent 3f3279b commit c383b7f

File tree

10 files changed

+621
-661
lines changed

10 files changed

+621
-661
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/I18NUtils.java

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@
2929
import java.io.UnsupportedEncodingException;
3030
import java.io.Writer;
3131
import java.net.URLEncoder;
32-
import java.util.ArrayList;
33-
import java.util.Collections;
34-
import java.util.Properties;
32+
import java.util.Map.Entry;
3533
import java.util.Set;
3634

3735
import com.bladecoder.engine.i18n.I18N;
38-
import com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder;
36+
import com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder;
3937

4038
public class I18NUtils {
4139
private static final String SEPARATOR = "\t";
@@ -64,13 +62,14 @@ public boolean accept(File arg0, String arg1) {
6462
}
6563
});
6664

67-
Properties props[] = new Properties[files.length + 1];
68-
69-
props[0] = new OrderedProperties();
65+
OrderedProperties props[] = new OrderedProperties[files.length + 1];
66+
67+
props[0] = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
68+
7069
props[0].load(new InputStreamReader(new FileInputStream(defaultChapter), I18N.ENCODING));
7170

7271
for (int i = 1; i < props.length; i++) {
73-
props[i] = new OrderedProperties();
72+
props[i] = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
7473
props[i].load(new InputStreamReader(new FileInputStream(files[i - 1]), I18N.ENCODING));
7574
}
7675

@@ -94,24 +93,17 @@ public boolean accept(File arg0, String arg1) {
9493

9594
writer.write("\n");
9695

97-
Set<Object> keySet = props[0].keySet();
98-
ArrayList<String> keys = new ArrayList<>();
99-
100-
for (Object key : keySet) {
101-
keys.add((String)key);
102-
}
103-
104-
Collections.sort(keys);
96+
Set<Entry<String, String>> keySet = props[0].entrySet();
10597

106-
for (String key : keys) {
107-
writer.write(key);
98+
for (Entry<String, String> e : keySet) {
99+
writer.write(e.getKey());
108100

109-
for (Properties p : props) {
110-
if(p.getProperty((String) key) == null) {
111-
writer.write(SEPARATOR + "**" + props[0].getProperty((String) key).replace("\n", "\\n"));
112-
System.out.println("KEY NOT FOUND: " + key);
101+
for (OrderedProperties p : props) {
102+
if(p.getProperty(e.getKey()) == null) {
103+
writer.write(SEPARATOR + "**" + props[0].getProperty(e.getKey()).replace("\n", "\\n"));
104+
System.out.println("KEY NOT FOUND: " + e);
113105
} else {
114-
writer.write(SEPARATOR + p.getProperty((String) key).replace("\n", "\\n"));
106+
writer.write(SEPARATOR + p.getProperty(e.getKey()).replace("\n", "\\n"));
115107
}
116108
}
117109

@@ -131,7 +123,7 @@ public static final void importTSV(String modelPath, String tsvFile, String chap
131123

132124
if (line != null) {
133125
String[] langs = line.split(SEPARATOR);
134-
NewOrderedProperties props[] = new NewOrderedProperties[langs.length - 1];
126+
OrderedProperties props[] = new OrderedProperties[langs.length - 1];
135127

136128
for (int i = 0; i < props.length; i++) {
137129
OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder();
@@ -183,13 +175,13 @@ public static final void newLocale(String modelPath, final String chapterId, Str
183175
File defaultChapter = new File(modelPath, chapterId + PROPERTIES_EXT);
184176
File newChapter = new File(modelPath, chapterId + "_" + newLocale + PROPERTIES_EXT);
185177

186-
Properties defaultProp = new OrderedProperties();
187-
Properties newProp = new OrderedProperties();
178+
OrderedProperties defaultProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
179+
OrderedProperties newProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
188180

189181
defaultProp.load(new InputStreamReader(new FileInputStream(defaultChapter), I18N.ENCODING));
190182

191-
for (Object key : defaultProp.keySet()) {
192-
newProp.setProperty((String) key, "**" + (String) defaultProp.get(key));
183+
for (Entry<String, String> e : defaultProp.entrySet()) {
184+
newProp.setProperty(e.getKey(), "**" + (String) defaultProp.getProperty(e.getKey()));
193185
}
194186

195187
// save new .properties
@@ -203,23 +195,23 @@ public static final void compare(String modelPath, final String chapterId, Strin
203195
File defaultChapter = new File(modelPath, chapterId + PROPERTIES_EXT);
204196
File destChapter = new File(modelPath, chapterId + "_" + destLocale + PROPERTIES_EXT);
205197

206-
Properties defaultProp = new OrderedProperties();
207-
Properties destProp = new OrderedProperties();
198+
OrderedProperties defaultProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
199+
OrderedProperties destProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
208200

209201
defaultProp.load(new InputStreamReader(new FileInputStream(defaultChapter), I18N.ENCODING));
210202
destProp.load(new InputStreamReader(new FileInputStream(destChapter), I18N.ENCODING));
211203

212204
// SEARCH FOR NOT EXISTING DEST KEYS
213-
for (Object key : defaultProp.keySet()) {
214-
if(destProp.get(key) == null) {
215-
EditorLogger.error("Key not found in '" + destLocale + "' locale: " + key);
205+
for (Entry<String, String> e : defaultProp.entrySet()) {
206+
if(destProp.getProperty(e.getKey()) == null) {
207+
EditorLogger.error("Key not found in '" + destLocale + "' locale: " + e.getKey());
216208
}
217209
}
218210

219211
// SEARCH FOR NOT EXISTING DEFAULT CHAPTER KEYS
220-
for (Object key : destProp.keySet()) {
221-
if(defaultProp.get(key) == null) {
222-
EditorLogger.error("Key not found in default locale: " + key);
212+
for (Entry<String, String> e : destProp.entrySet()) {
213+
if(defaultProp.getProperty(e.getKey()) == null) {
214+
EditorLogger.error("Key not found in default locale: " + e.getKey());
223215
}
224216
}
225217
}
@@ -229,23 +221,23 @@ public static final void sync(String modelPath, final String chapterId, String d
229221
File defaultChapter = new File(modelPath, chapterId + PROPERTIES_EXT);
230222
File destChapter = new File(modelPath, chapterId + "_" + destLocale + PROPERTIES_EXT);
231223

232-
Properties defaultProp = new OrderedProperties();
233-
Properties destProp = new OrderedProperties();
224+
OrderedProperties defaultProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
225+
OrderedProperties destProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
234226

235227
defaultProp.load(new InputStreamReader(new FileInputStream(defaultChapter), I18N.ENCODING));
236228
destProp.load(new InputStreamReader(new FileInputStream(destChapter), I18N.ENCODING));
237229

238230
// SEARCH FOR NOT EXISTING DEST KEYS
239231
for (String key : defaultProp.stringPropertyNames()) {
240-
if(destProp.get(key) == null) {
232+
if(destProp.getProperty(key) == null) {
241233
System.out.println("ADDING Key not found in '" + destLocale + "' locale: " + key + "=" + defaultProp.getProperty(key));
242234
destProp.setProperty(key, "**" + defaultProp.getProperty(key));
243235
}
244236
}
245237

246238
// SEARCH FOR NOT EXISTING DEFAULT CHAPTER KEYS
247239
for (String key : destProp.stringPropertyNames()) {
248-
if(defaultProp.get(key) == null) {
240+
if(defaultProp.getProperty(key) == null) {
249241
System.out.println("DELETE MANUALLY Key not found in default locale: " + key);
250242
}
251243
}

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/ModelTools.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import com.bladecoder.engine.model.Verb;
5757
import com.bladecoder.engine.util.ActionUtils;
5858
import com.bladecoder.engineeditor.Ctx;
59-
import com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder;
59+
import com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder;
6060
import com.bladecoder.engineeditor.model.Project;
6161

6262
public class ModelTools {
@@ -453,7 +453,7 @@ public static void extractInkTexts(String story, String lang) throws IOException
453453

454454
OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder();
455455
builder.withSuppressDateInComment(true);
456-
NewOrderedProperties prop = builder.build();
456+
OrderedProperties prop = builder.build();
457457

458458
extractInkTextsInternal(root, tsvString, prop);
459459
FileUtils.writeStringToFile(new File(file + ".tsv"), tsvString.toString());
@@ -483,7 +483,7 @@ public static void extractInkTexts(String story, String lang) throws IOException
483483
//Ctx.project.setModified();
484484
}
485485

486-
private static void extractInkTextsInternal(JsonValue v, StringBuilder sb, NewOrderedProperties prop) {
486+
private static void extractInkTextsInternal(JsonValue v, StringBuilder sb, OrderedProperties prop) {
487487
if (v.isArray() || v.isObject()) {
488488
for (int i = 0; i < v.size; i++) {
489489
JsonValue aValue = v.get(i);
@@ -503,6 +503,9 @@ private static void extractInkTextsInternal(JsonValue v, StringBuilder sb, NewOr
503503
if(idx != -1) {
504504
charName = value.substring(0, idx).trim();
505505
value = value.substring(idx+1).trim();
506+
507+
if (value.length() == 0)
508+
return;
506509
}
507510

508511

0 commit comments

Comments
 (0)