mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
начинаю добавлять дельту к конфигу.
пока не она не конфликтует с чтением =))) осталось только сделать запись дельты, и перед большой записью в файл надо еще не забыть написать applyDelta git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@213 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
3e15f26d82
commit
98e05a51a0
10 changed files with 185 additions and 62 deletions
|
@ -1,6 +1,6 @@
|
|||
package org.zlibrary.core.options;
|
||||
|
||||
import org.zlibrary.core.options.config.ZLConfig;
|
||||
import org.zlibrary.core.options.config.ZLSimpleConfig;
|
||||
import org.zlibrary.core.options.config.ZLConfigInstance;
|
||||
|
||||
public abstract class ZLOption {
|
||||
|
@ -8,7 +8,7 @@ public abstract class ZLOption {
|
|||
public static final String CONFIG_CATEGORY = "options";
|
||||
public static final String STATE_CATEGORY = "state";
|
||||
|
||||
protected ZLConfig myConfig = ZLConfigInstance.getInstance();
|
||||
protected ZLSimpleConfig myConfig = ZLConfigInstance.getInstance();
|
||||
protected String myCategory;
|
||||
protected String myGroup;
|
||||
protected String myOptionName;
|
||||
|
|
|
@ -1,69 +1,65 @@
|
|||
package org.zlibrary.core.options.config;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* êëàññ Êîíôèã. ýòî ñâîåîáðàçíàÿ ñòðóêòóðà îïöèé.
|
||||
* îñíîâíîå ïîëå myData ñîäåðæèò ñïèñîê ãðóïï, êîòîðûì
|
||||
* â êà÷åñòâå êëþ÷åé ñîïîñòàâëÿþòñÿ èõ èìåíà.
|
||||
* @author Àäìèíèñòðàòîð
|
||||
*
|
||||
*/
|
||||
/*package*/ class ZLConfigImpl implements ZLConfig {
|
||||
// public abstract void unsetValue(String group, String name);
|
||||
private final ZLSimpleConfigImpl myMainConfig;
|
||||
private final ZLDeltaConfig myDeltaConfig;
|
||||
|
||||
// public abstract boolean isAutoSavingSupported() const = 0;
|
||||
// public abstract void startAutoSave(int seconds) = 0;
|
||||
private Map<String, ZLGroup> myData;
|
||||
|
||||
public ZLConfigImpl (){
|
||||
myData = new LinkedHashMap<String, ZLGroup>();
|
||||
}
|
||||
|
||||
public Map<String, ZLGroup> getGroups(){
|
||||
return Collections.unmodifiableMap(myData);
|
||||
}
|
||||
|
||||
public ZLConfigImpl (Map<String, ZLGroup> map){
|
||||
myData = map;
|
||||
}
|
||||
|
||||
public void removeGroup(String group){
|
||||
if (myData.get(group) != null){
|
||||
myData.remove(group);
|
||||
}
|
||||
public ZLConfigImpl() {
|
||||
myMainConfig = new ZLSimpleConfigImpl();
|
||||
myDeltaConfig = new ZLDeltaConfig();
|
||||
}
|
||||
|
||||
public String getValue(String group, String name, String defaultValue){
|
||||
if (myData.get(group) != null){
|
||||
return myData.get(group).getValue(name, defaultValue);
|
||||
} else{
|
||||
return defaultValue;
|
||||
}
|
||||
public Map<String, ZLGroup> getGroups() {
|
||||
return myMainConfig.getGroups();
|
||||
}
|
||||
|
||||
public void setValue(String group, String name, String value, String category){
|
||||
if (myData.get(group) != null){
|
||||
myData.get(group).setValue(name, value, category);
|
||||
|
||||
public String getValue(String group, String name, String defaultValue) {
|
||||
String value = myDeltaConfig.getValue(group, name, defaultValue);
|
||||
if (value == null) {
|
||||
return myMainConfig.getValue(group, name, defaultValue);
|
||||
} else {
|
||||
ZLGroup newGroup = new ZLGroup();
|
||||
newGroup.setValue(name, value, category);
|
||||
myData.put(group, newGroup);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public void unsetValue(String group, String name){
|
||||
myData.get(group).unsetValue(name);
|
||||
|
||||
public void removeGroup(String name) {
|
||||
myDeltaConfig.removeGroup(name);
|
||||
}
|
||||
|
||||
public void setValue(String group, String name, String value, String category) {
|
||||
myDeltaConfig.setValue(group, name, value, category);
|
||||
}
|
||||
|
||||
public void unsetValue(String group, String name) {
|
||||
myDeltaConfig.unsetValue(group, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* ìåòîä âûâîäà â ñòðîêó
|
||||
*/
|
||||
public String toString(){
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String categoryName : myData.keySet()){
|
||||
sb.append("" + categoryName + "\n\n" + myData.get(categoryName) + "\n");
|
||||
public void clearDelta() {
|
||||
myDeltaConfig.clear();
|
||||
}
|
||||
|
||||
public void applyDelta() {
|
||||
for (String deletedGroup : myDeltaConfig.getDeletedGroups()) {
|
||||
myMainConfig.removeGroup(deletedGroup);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
Map<String, String> deletedValues = myDeltaConfig.getDeletedValues();
|
||||
for (String group : deletedValues.keySet()) {
|
||||
myMainConfig.unsetValue(group, deletedValues.get(group));
|
||||
}
|
||||
|
||||
ZLSimpleConfigImpl setValues = myDeltaConfig.getSetValues();
|
||||
Map<String, ZLGroup> groups = setValues.getGroups();
|
||||
for (String group : groups.keySet()) {
|
||||
for (ZLOptionValue value : groups.get(group).getValues()) {
|
||||
myMainConfig.setValue(group, value.getName(),
|
||||
value.getValue(), value.getCategory());
|
||||
}
|
||||
}
|
||||
myDeltaConfig.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.zlibrary.core.options.config;
|
|||
|
||||
public class ZLConfigInstance {
|
||||
|
||||
private static final ZLConfigImpl myConfig = new ZLConfigImpl();
|
||||
private static final ZLConfig myConfig = new ZLConfigImpl();
|
||||
|
||||
public static ZLConfig getInstance(){
|
||||
return myConfig;
|
||||
|
|
49
src/org/zlibrary/core/options/config/ZLDeltaConfig.java
Normal file
49
src/org/zlibrary/core/options/config/ZLDeltaConfig.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
package org.zlibrary.core.options.config;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/*package*/ final class ZLDeltaConfig {
|
||||
|
||||
private Map<String, String> myDeletedValues = new HashMap<String, String>();
|
||||
private Set<String> myDeletedGroups = new HashSet<String>();
|
||||
private ZLSimpleConfigImpl mySetValues = new ZLSimpleConfigImpl();
|
||||
|
||||
public ZLDeltaConfig() {
|
||||
}
|
||||
|
||||
public Set<String> getDeletedGroups() {
|
||||
return Collections.unmodifiableSet(myDeletedGroups);
|
||||
}
|
||||
|
||||
public Map<String, String> getDeletedValues() {
|
||||
return Collections.unmodifiableMap(myDeletedValues);
|
||||
}
|
||||
|
||||
public ZLSimpleConfigImpl getSetValues() {
|
||||
return mySetValues;
|
||||
}
|
||||
|
||||
public String getValue(String group, String name, String defaultValue) {
|
||||
return mySetValues.getValue(group, name, defaultValue);
|
||||
}
|
||||
|
||||
public void setValue(String group, String name, String value, String category) {
|
||||
mySetValues.setValue(group, name, value, category);
|
||||
}
|
||||
|
||||
public void unsetValue(String group, String name) {
|
||||
myDeletedValues.put(group, name);
|
||||
mySetValues.unsetValue(group, name);
|
||||
}
|
||||
|
||||
public void removeGroup(String group) {
|
||||
myDeletedGroups.add(group);
|
||||
mySetValues.removeGroup(group);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
myDeletedValues.clear();
|
||||
myDeletedGroups.clear();
|
||||
mySetValues.clear();
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package org.zlibrary.core.options.config;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
public class ZLGroup {
|
||||
public final class ZLGroup {
|
||||
private Map<String, ZLOptionValue> myData;
|
||||
|
||||
public ZLGroup (){
|
||||
|
@ -13,12 +13,12 @@ public class ZLGroup {
|
|||
return Collections.unmodifiableCollection(myData.values());
|
||||
}
|
||||
|
||||
public String getValue(String name, String defaultValue){
|
||||
public String getValue(String name){
|
||||
ZLOptionValue temp = myData.get(name);
|
||||
if (temp != null){
|
||||
return temp.getValue();
|
||||
} else {
|
||||
return defaultValue;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,10 @@ public class ZLOptionValue {
|
|||
return myValue;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return myCategory;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.zlibrary.core.options.config;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ZLConfig {
|
||||
public interface ZLSimpleConfig {
|
||||
|
||||
public void removeGroup(String name);
|
||||
|
69
src/org/zlibrary/core/options/config/ZLSimpleConfigImpl.java
Normal file
69
src/org/zlibrary/core/options/config/ZLSimpleConfigImpl.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package org.zlibrary.core.options.config;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* êëàññ Êîíôèã. ýòî ñâîåîáðàçíàÿ ñòðóêòóðà îïöèé.
|
||||
* îñíîâíîå ïîëå myData ñîäåðæèò ñïèñîê ãðóïï, êîòîðûì
|
||||
* â êà÷åñòâå êëþ÷åé ñîïîñòàâëÿþòñÿ èõ èìåíà.
|
||||
* @author Àäìèíèñòðàòîð
|
||||
*
|
||||
*/
|
||||
/*package*/ class ZLSimpleConfigImpl implements ZLSimpleConfig {
|
||||
// public abstract void unsetValue(String group, String name);
|
||||
|
||||
// public abstract boolean isAutoSavingSupported() const = 0;
|
||||
// public abstract void startAutoSave(int seconds) = 0;
|
||||
private Map<String, ZLGroup> myData;
|
||||
|
||||
public ZLSimpleConfigImpl() {
|
||||
myData = new LinkedHashMap<String, ZLGroup>();
|
||||
}
|
||||
|
||||
protected void clear() {
|
||||
myData.clear();
|
||||
}
|
||||
|
||||
public Map<String, ZLGroup> getGroups() {
|
||||
return Collections.unmodifiableMap(myData);
|
||||
}
|
||||
|
||||
public void removeGroup(String group) {
|
||||
if (myData.get(group) != null){
|
||||
myData.remove(group);
|
||||
}
|
||||
}
|
||||
|
||||
public String getValue(String group, String name, String defaultValue) {
|
||||
if (myData.get(group) != null){
|
||||
return myData.get(group).getValue(name);
|
||||
} else{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setValue(String group, String name, String value, String category) {
|
||||
if (myData.get(group) != null){
|
||||
myData.get(group).setValue(name, value, category);
|
||||
} else {
|
||||
ZLGroup newGroup = new ZLGroup();
|
||||
newGroup.setValue(name, value, category);
|
||||
myData.put(group, newGroup);
|
||||
}
|
||||
}
|
||||
|
||||
public void unsetValue(String group, String name) {
|
||||
myData.get(group).unsetValue(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* ìåòîä âûâîäà â ñòðîêó
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String categoryName : myData.keySet()){
|
||||
sb.append("" + categoryName + "\n\n" + myData.get(categoryName) + "\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ import org.zlibrary.core.options.config.*;
|
|||
}
|
||||
|
||||
public void endDocument() {
|
||||
myConfig.applyDelta();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.zlibrary.core.options.config.*;
|
|||
|
||||
/*package*/ class ZLConfigWriter implements ZLWriter {
|
||||
|
||||
private ZLConfig myConfig = ZLConfigInstance.getInstance();
|
||||
private ZLSimpleConfig myConfig = ZLConfigInstance.getInstance();
|
||||
private File myDestinationDirectory;
|
||||
|
||||
public ZLConfigWriter(String path){
|
||||
|
@ -34,6 +34,10 @@ import org.zlibrary.core.options.config.*;
|
|||
}
|
||||
}
|
||||
|
||||
public void writeDelta() {
|
||||
//TODO ДОПИСАТЬ, ИСПОЛЬЗУЯ СТРОЕНИЕ ФАЙЛА ДЕЛЬТЫ ИЗ СИШНОГО КОДА
|
||||
}
|
||||
|
||||
public void write() {
|
||||
Map<String, ZLGroup> data = myConfig.getGroups();
|
||||
// êëþ÷ - èìÿ êàòåãîðèè, çíà÷åíèå - ñîäåðæèìîå ñîîòâåòñòâóþùåãî ôàéëà
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue