mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
1) создаю меньше стрингов в геттерах
2) табы вместо пробелов git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@279 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
361f26a483
commit
db93c97f19
18 changed files with 136 additions and 132 deletions
|
@ -10,7 +10,7 @@ import org.zlibrary.core.options.util.*;
|
|||
*/
|
||||
public final class ZLBoolean3Option extends ZLSimpleOption {
|
||||
|
||||
private ZLBoolean3 myValue;
|
||||
private ZLBoolean3 myValue;
|
||||
private final ZLBoolean3 myDefaultValue;
|
||||
|
||||
public ZLBoolean3Option(String category, String group, String optionName, ZLBoolean3 defaultValue) {
|
||||
|
@ -26,8 +26,10 @@ public final class ZLBoolean3Option extends ZLSimpleOption {
|
|||
public ZLBoolean3 getValue() {
|
||||
if (!myIsSynchronized) {
|
||||
String value = myConfig.getValue(myGroup, myOptionName,
|
||||
myDefaultValue.toString());
|
||||
myValue = ZLFromStringConverter.getBoolean3Value(value);
|
||||
null);
|
||||
if (value != null) {
|
||||
myValue = ZLFromStringConverter.getBoolean3Value(value);
|
||||
}
|
||||
myIsSynchronized = true;
|
||||
}
|
||||
return myValue;
|
||||
|
|
|
@ -16,13 +16,11 @@ public final class ZLBooleanOption extends ZLSimpleOption {
|
|||
|
||||
public boolean getValue() {
|
||||
if (!myIsSynchronized) {
|
||||
String value;
|
||||
if (myDefaultValue) {
|
||||
value = myConfig.getValue(myGroup, myOptionName, "true");
|
||||
} else {
|
||||
value = myConfig.getValue(myGroup, myOptionName, "false");
|
||||
}
|
||||
myValue = ZLFromStringConverter.getBooleanValue(value);
|
||||
|
||||
String value = myConfig.getValue(myGroup, myOptionName, null);
|
||||
if (value != null) {
|
||||
myValue = ZLFromStringConverter.getBooleanValue(value);
|
||||
}
|
||||
myIsSynchronized = true;
|
||||
}
|
||||
return myValue;
|
||||
|
@ -37,11 +35,11 @@ public final class ZLBooleanOption extends ZLSimpleOption {
|
|||
if (myValue == myDefaultValue) {
|
||||
myConfig.unsetValue(myGroup, myOptionName);
|
||||
} else {
|
||||
if (myValue) {
|
||||
myConfig.setValue(myGroup, myOptionName, "true", myCategory);
|
||||
} else {
|
||||
myConfig.setValue(myGroup, myOptionName, "false", myCategory);
|
||||
}
|
||||
if (myValue) {
|
||||
myConfig.setValue(myGroup, myOptionName, "true", myCategory);
|
||||
} else {
|
||||
myConfig.setValue(myGroup, myOptionName, "false", myCategory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,10 @@ public final class ZLColorOption extends ZLOption {
|
|||
|
||||
public int getValue() {
|
||||
if (!myIsSynchronized) {
|
||||
String strDefaultValue = ((Integer)myDefaultValue).toString();
|
||||
String value = myConfig.getValue(myGroup, myOptionName, strDefaultValue);
|
||||
myIntValue = ZLFromStringConverter.getIntegerValue(value);
|
||||
String value = myConfig.getValue(myGroup, myOptionName, null);
|
||||
if (value != null) {
|
||||
myIntValue = ZLFromStringConverter.getIntegerValue(value);
|
||||
}
|
||||
myIsSynchronized = true;
|
||||
}
|
||||
return myIntValue;
|
||||
|
|
|
@ -17,9 +17,11 @@ public final class ZLDoubleOption extends ZLOption{
|
|||
|
||||
public double getValue() {
|
||||
if (!myIsSynchronized) {
|
||||
String strDefaultValue = ((Double)myDefaultValue).toString();
|
||||
String value = myConfig.getValue(myGroup, myOptionName, strDefaultValue);
|
||||
myValue = ZLFromStringConverter.getDoubleValue(value);
|
||||
String value = myConfig.getValue(myGroup, myOptionName,
|
||||
null);
|
||||
if (value != null) {
|
||||
myValue = ZLFromStringConverter.getDoubleValue(value);
|
||||
}
|
||||
myIsSynchronized = true;
|
||||
}
|
||||
return myValue;
|
||||
|
|
|
@ -5,14 +5,14 @@ import org.zlibrary.core.options.util.ZLColor;
|
|||
|
||||
/*package*/ class ZLFromStringConverter {
|
||||
|
||||
public static ZLBoolean3 getBoolean3Value(String input){
|
||||
public static ZLBoolean3 getBoolean3Value(String input){
|
||||
if (input.toLowerCase().equals("true")) {
|
||||
return ZLBoolean3.B3_TRUE;
|
||||
}
|
||||
if (input.toLowerCase().equals("false")) {
|
||||
if (input.toLowerCase().equals("false")) {
|
||||
return ZLBoolean3.B3_FALSE;
|
||||
}
|
||||
return ZLBoolean3.B3_UNDEFINED;
|
||||
}
|
||||
return ZLBoolean3.B3_UNDEFINED;
|
||||
}
|
||||
|
||||
public static boolean getBooleanValue(String input){
|
||||
|
@ -24,22 +24,23 @@ import org.zlibrary.core.options.util.ZLColor;
|
|||
}
|
||||
|
||||
public static double getDoubleValue(String input){
|
||||
try {
|
||||
double value = Double.parseDouble(input);
|
||||
return value;
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("wrong format : " + input);
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
double value = Double.parseDouble(input);
|
||||
return value;
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("wrong format : " + input);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getIntegerValue(String input){
|
||||
try {
|
||||
int value = Integer.parseInt(input);
|
||||
return value;
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("wrong format : " + input);
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
int value = Integer.parseInt(input);
|
||||
return value;
|
||||
} catch (NumberFormatException e) {
|
||||
//e.printStackTrace();
|
||||
System.err.println("wrong format : " + input);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,10 @@ public final class ZLIntegerOption extends ZLOption{
|
|||
|
||||
public int getValue() {
|
||||
if (!myIsSynchronized) {
|
||||
String strDefaultValue = ((Integer)myDefaultValue).toString();
|
||||
String value = myConfig.getValue(myGroup, myOptionName, strDefaultValue);
|
||||
myValue = ZLFromStringConverter.getIntegerValue(value);
|
||||
String value = myConfig.getValue(myGroup, myOptionName, null);
|
||||
if (value != null) {
|
||||
myValue = ZLFromStringConverter.getIntegerValue(value);
|
||||
}
|
||||
myIsSynchronized = true;
|
||||
}
|
||||
return myValue;
|
||||
|
|
|
@ -30,10 +30,10 @@ public final class ZLIntegerRangeOption extends ZLOption {
|
|||
|
||||
public int getValue() {
|
||||
if (!myIsSynchronized) {
|
||||
String strDefaultValue = ((Integer)myDefaultValue).toString();
|
||||
String value = myConfig.getValue(myGroup,
|
||||
myOptionName, strDefaultValue);
|
||||
myValue = ZLFromStringConverter.getIntegerValue(value);
|
||||
String value = myConfig.getValue(myGroup, myOptionName, null);
|
||||
if (value != null) {
|
||||
myValue = ZLFromStringConverter.getIntegerValue(value);
|
||||
}
|
||||
myIsSynchronized = true;
|
||||
}
|
||||
return myValue;
|
||||
|
|
|
@ -26,8 +26,8 @@ public abstract class ZLOption {
|
|||
myCategory = category;
|
||||
myGroup = group;
|
||||
myOptionName = name;
|
||||
myIsSynchronized = false;
|
||||
myConfig.setCategory(group, name, category);
|
||||
myIsSynchronized = false;
|
||||
myConfig.setCategory(group, name, category);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,6 @@ package org.zlibrary.core.options.config;
|
|||
public interface ZLConfig extends ZLSimpleConfig {
|
||||
public void applyDelta();
|
||||
public void clearDelta();
|
||||
public ZLDeltaConfig getDelta();
|
||||
public void setCategory(String group, String name, String category);
|
||||
public ZLDeltaConfig getDelta();
|
||||
public void setCategory(String group, String name, String category);
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import java.util.Map;
|
|||
myDeltaConfig = new ZLDeltaConfig();
|
||||
}
|
||||
|
||||
public ZLDeltaConfig getDelta() {
|
||||
return myDeltaConfig;
|
||||
}
|
||||
|
||||
public ZLDeltaConfig getDelta() {
|
||||
return myDeltaConfig;
|
||||
}
|
||||
|
||||
public Map<String, ZLGroup> getGroups() {
|
||||
return myMainConfig.getGroups();
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ import java.util.Map;
|
|||
public String getValue(String group, String name, String defaultValue) {
|
||||
String value = myDeltaConfig.getValue(group, name, defaultValue);
|
||||
if (value == defaultValue) {
|
||||
value = myMainConfig.getValue(group, name, defaultValue);
|
||||
value = myMainConfig.getValue(group, name, defaultValue);
|
||||
}
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setCategory(String group, String name, String cat) {
|
||||
|
@ -55,9 +55,9 @@ import java.util.Map;
|
|||
|
||||
Map<String, ZLGroup> deletedValues = myDeltaConfig.getDeletedValues().getGroups();
|
||||
for (String group : deletedValues.keySet()) {
|
||||
for (ZLOptionValue option : deletedValues.get(group).getValues()) {
|
||||
myMainConfig.unsetValue(group, option.getName());
|
||||
}
|
||||
for (ZLOptionValue option : deletedValues.get(group).getValues()) {
|
||||
myMainConfig.unsetValue(group, option.getName());
|
||||
}
|
||||
}
|
||||
|
||||
ZLSimpleConfigImpl setValues = myDeltaConfig.getSetValues();
|
||||
|
|
|
@ -30,13 +30,13 @@ import java.util.*;
|
|||
public void setValue(String group, String name, String value, String category) {
|
||||
mySetValues.setValue(group, name, value, category);
|
||||
}
|
||||
|
||||
public void setCategory(String group, String name, String cat) {
|
||||
mySetValues.setCategory(group, name, cat);
|
||||
}
|
||||
|
||||
public void setCategory(String group, String name, String cat) {
|
||||
mySetValues.setCategory(group, name, cat);
|
||||
}
|
||||
|
||||
public void unsetValue(String group, String name) {
|
||||
//TODO ÝÒÎ ÏËÎÕÎ??
|
||||
//TODO ÝÒÎ ÏËÎÕÎ??
|
||||
myDeletedValues.setValue(group, name, null, null);
|
||||
mySetValues.unsetValue(group, name);
|
||||
}
|
||||
|
@ -51,34 +51,34 @@ import java.util.*;
|
|||
myDeletedGroups.clear();
|
||||
mySetValues.clear();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("<delta>\n <delete>\n");
|
||||
for (String group : myDeletedGroups) {
|
||||
sb.append(" <group name=\"" + group + "\"/>\n");
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("<delta>\n <delete>\n");
|
||||
for (String group : myDeletedGroups) {
|
||||
sb.append(" <group name=\"" + group + "\"/>\n");
|
||||
}
|
||||
|
||||
Map<String, ZLGroup> values = myDeletedValues.getGroups();
|
||||
for (String group : values.keySet()) {
|
||||
sb.append(" <group name=\"" + group + "\">\n");
|
||||
for (ZLOptionValue option : values.get(group).getValues()) {
|
||||
sb.append(" <option name=\"" + option.getName() + "\"/>\n");
|
||||
}
|
||||
sb.append(" </group>\n");
|
||||
}
|
||||
sb.append(" </delete>\n");
|
||||
|
||||
values = mySetValues.getGroups();
|
||||
for (String group : values.keySet()) {
|
||||
sb.append(" <group name=\"" + group + "\">\n");
|
||||
for (ZLOptionValue option : values.get(group).getValues()) {
|
||||
sb.append(" <option name=\"" + option.getName() + "\" ");
|
||||
sb.append("value=\"" + option.getValue() + "\" ");
|
||||
sb.append("category=\"" + option.getCategory() + "\">\n");
|
||||
}
|
||||
sb.append(" </group>\n");
|
||||
}
|
||||
sb.append("</delta>");
|
||||
return sb.toString();
|
||||
}
|
||||
Map<String, ZLGroup> values = myDeletedValues.getGroups();
|
||||
for (String group : values.keySet()) {
|
||||
sb.append(" <group name=\"" + group + "\">\n");
|
||||
for (ZLOptionValue option : values.get(group).getValues()) {
|
||||
sb.append(" <option name=\"" + option.getName() + "\"/>\n");
|
||||
}
|
||||
sb.append(" </group>\n");
|
||||
}
|
||||
sb.append(" </delete>\n");
|
||||
|
||||
values = mySetValues.getGroups();
|
||||
for (String group : values.keySet()) {
|
||||
sb.append(" <group name=\"" + group + "\">\n");
|
||||
for (ZLOptionValue option : values.get(group).getValues()) {
|
||||
sb.append(" <option name=\"" + option.getName() + "\" ");
|
||||
sb.append("value=\"" + option.getValue() + "\" ");
|
||||
sb.append("category=\"" + option.getCategory() + "\">\n");
|
||||
}
|
||||
sb.append(" </group>\n");
|
||||
}
|
||||
sb.append("</delta>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public final class ZLGroup {
|
|||
return Collections.unmodifiableCollection(myData.values());
|
||||
}
|
||||
|
||||
protected ZLOptionValue getOption(String name) {
|
||||
return myData.get(name);
|
||||
}
|
||||
|
||||
protected ZLOptionValue getOption(String name) {
|
||||
return myData.get(name);
|
||||
}
|
||||
|
||||
public String getValue(String name){
|
||||
ZLOptionValue temp = myData.get(name);
|
||||
if (temp != null){
|
||||
|
|
|
@ -6,15 +6,15 @@ public class ZLOptionValue {
|
|||
private String myName = "";
|
||||
|
||||
public ZLOptionValue(String name, String value, String category) {
|
||||
if (value != null) {
|
||||
myValue = value.intern();
|
||||
}
|
||||
if (category != null) {
|
||||
myCategory = category.intern();
|
||||
}
|
||||
if (name != null) {
|
||||
myName = name.intern();
|
||||
}
|
||||
if (value != null) {
|
||||
myValue = value.intern();
|
||||
}
|
||||
if (category != null) {
|
||||
myCategory = category.intern();
|
||||
}
|
||||
if (name != null) {
|
||||
myName = name.intern();
|
||||
}
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
|
@ -34,10 +34,10 @@ public class ZLOptionValue {
|
|||
public String getCategory() {
|
||||
return myCategory;
|
||||
}
|
||||
|
||||
public void setCategory(String cat) {
|
||||
myCategory = cat;
|
||||
}
|
||||
|
||||
public void setCategory(String cat) {
|
||||
myCategory = cat;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return " <option name=\"" + myName
|
||||
|
|
|
@ -42,16 +42,16 @@ import java.util.*;
|
|||
}
|
||||
}
|
||||
|
||||
public void setCategory(String group, String name, String cat) {
|
||||
ZLGroup gr = myData.get(group);
|
||||
if (gr != null){
|
||||
ZLOptionValue option = gr.getOption(name);
|
||||
if (option != null) {
|
||||
option.setCategory(cat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCategory(String group, String name, String cat) {
|
||||
ZLGroup gr = myData.get(group);
|
||||
if (gr != null){
|
||||
ZLOptionValue option = gr.getOption(name);
|
||||
if (option != null) {
|
||||
option.setCategory(cat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setValue(String group, String name, String value, String category) {
|
||||
if (myData.get(group) != null){
|
||||
myData.get(group).setValue(name, value, category);
|
||||
|
@ -63,10 +63,10 @@ import java.util.*;
|
|||
}
|
||||
|
||||
public void unsetValue(String group, String name) {
|
||||
ZLGroup gr = myData.get(group);
|
||||
if (gr != null) {
|
||||
gr.unsetValue(name);
|
||||
}
|
||||
ZLGroup gr = myData.get(group);
|
||||
if (gr != null) {
|
||||
gr.unsetValue(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -162,8 +162,7 @@ import org.zlibrary.core.options.config.*;
|
|||
*
|
||||
* Ïğî÷èòàòü äàííûå èç ôàéëà XML
|
||||
*
|
||||
* @param file -
|
||||
* ôàéë XML
|
||||
* @param file ôàéë XML
|
||||
*/
|
||||
public void readFile(File file) {
|
||||
try {
|
||||
|
|
|
@ -38,8 +38,8 @@ import org.zlibrary.core.options.config.*;
|
|||
|
||||
public void writeDelta() {
|
||||
//TODO ДОПИСАТЬ, ИСПОЛЬЗУЯ СТРОЕНИЕ ФАЙЛА ДЕЛЬТЫ ИЗ СИШНОГО КОДА
|
||||
this.writeConfigFile("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
+ myConfig.getDelta(), myDestinationDirectory + "/delta.xml");
|
||||
this.writeConfigFile("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
+ myConfig.getDelta(), myDestinationDirectory + "/delta.xml");
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
|
|
@ -2,5 +2,5 @@ package org.zlibrary.core.options.config.writer;
|
|||
|
||||
public interface ZLWriter {
|
||||
public void write();
|
||||
public void writeDelta();
|
||||
public void writeDelta();
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ public class Main {
|
|||
ZLConfigInstance.getInstance().unsetValue("MYGROUP",
|
||||
"lengthChangeable");*/
|
||||
|
||||
String output = "test/org/test/zlibrary/options/example/output/";
|
||||
//ZLConfigWriterFactory.createConfigWriter(output).writeDelta();
|
||||
String output = "test/org/test/zlibrary/options/example/output/";
|
||||
//ZLConfigWriterFactory.createConfigWriter(output).writeDelta();
|
||||
ZLConfigWriterFactory.createConfigWriter(output).write();
|
||||
//ZLConfigWriterFactory.createConfigWriter(output + "cleared-").writeDelta();
|
||||
//ZLConfigWriterFactory.createConfigWriter(output + "cleared-").writeDelta();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue