Separate the sync layer from its clients. #112

This commit is contained in:
akwizgran
2015-12-21 14:36:24 +00:00
parent f5f572139a
commit 5355951466
117 changed files with 3160 additions and 3465 deletions

View File

@@ -1,46 +1,90 @@
package org.briarproject.api.data;
import org.briarproject.api.FormatException;
import java.util.HashMap;
// This class is not thread-safe
public class BdfDictionary extends HashMap<String, Object> {
public Boolean getBoolean(String key) throws FormatException {
Object o = get(key);
if (o instanceof Boolean) return (Boolean) o;
throw new FormatException();
}
public Boolean getBoolean(String key, Boolean defaultValue) {
Object o = get(key);
if (o instanceof Boolean) return (Boolean) o;
return defaultValue;
}
public Long getInteger(String key) throws FormatException {
Object o = get(key);
if (o instanceof Long) return (Long) o;
throw new FormatException();
}
public Long getInteger(String key, Long defaultValue) {
Object o = get(key);
if (o instanceof Long) return (Long) o;
return defaultValue;
}
public Double getFloat(String key) throws FormatException {
Object o = get(key);
if (o instanceof Double) return (Double) o;
throw new FormatException();
}
public Double getFloat(String key, Double defaultValue) {
Object o = get(key);
if (o instanceof Double) return (Double) o;
return defaultValue;
}
public String getString(String key) throws FormatException {
Object o = get(key);
if (o instanceof String) return (String) o;
throw new FormatException();
}
public String getString(String key, String defaultValue) {
Object o = get(key);
if (o instanceof String) return (String) o;
return defaultValue;
}
public byte[] getRaw(String key) throws FormatException {
Object o = get(key);
if (o instanceof byte[]) return (byte[]) o;
throw new FormatException();
}
public byte[] getRaw(String key, byte[] defaultValue) {
Object o = get(key);
if (o instanceof byte[]) return (byte[]) o;
return defaultValue;
}
public BdfList getList(String key) throws FormatException {
Object o = get(key);
if (o instanceof BdfList) return (BdfList) o;
throw new FormatException();
}
public BdfList getList(String key, BdfList defaultValue) {
Object o = get(key);
if (o instanceof BdfList) return (BdfList) o;
return defaultValue;
}
public BdfDictionary getDictionary(String key) throws FormatException {
Object o = get(key);
if (o instanceof BdfDictionary) return (BdfDictionary) o;
throw new FormatException();
}
public BdfDictionary getDictionary(String key, BdfDictionary defaultValue) {
Object o = get(key);
if (o instanceof BdfDictionary) return (BdfDictionary) o;

View File

@@ -1,46 +1,90 @@
package org.briarproject.api.data;
import org.briarproject.api.FormatException;
import java.util.ArrayList;
// This class is not thread-safe
public class BdfList extends ArrayList<Object> {
public Boolean getBoolean(int index) throws FormatException {
Object o = get(index);
if (o instanceof Boolean) return (Boolean) o;
throw new FormatException();
}
public Boolean getBoolean(int index, Boolean defaultValue) {
Object o = get(index);
if (o instanceof Boolean) return (Boolean) o;
return defaultValue;
}
public Long getInteger(int index) throws FormatException {
Object o = get(index);
if (o instanceof Long) return (Long) o;
throw new FormatException();
}
public Long getInteger(int index, Long defaultValue) {
Object o = get(index);
if (o instanceof Long) return (Long) o;
return defaultValue;
}
public Double getFloat(int index) throws FormatException {
Object o = get(index);
if (o instanceof Double) return (Double) o;
throw new FormatException();
}
public Double getFloat(int index, Double defaultValue) {
Object o = get(index);
if (o instanceof Double) return (Double) o;
return defaultValue;
}
public String getString(int index) throws FormatException {
Object o = get(index);
if (o instanceof String) return (String) o;
throw new FormatException();
}
public String getString(int index, String defaultValue) {
Object o = get(index);
if (o instanceof String) return (String) o;
return defaultValue;
}
public byte[] getRaw(int index) throws FormatException {
Object o = get(index);
if (o instanceof byte[]) return (byte[]) o;
throw new FormatException();
}
public byte[] getRaw(int index, byte[] defaultValue) {
Object o = get(index);
if (o instanceof byte[]) return (byte[]) o;
return defaultValue;
}
public BdfList getList(int index) throws FormatException {
Object o = get(index);
if (o instanceof BdfList) return (BdfList) o;
throw new FormatException();
}
public BdfList getList(int index, BdfList defaultValue) {
Object o = get(index);
if (o instanceof BdfList) return (BdfList) o;
return defaultValue;
}
public BdfDictionary getDictionary(int index) throws FormatException {
Object o = get(index);
if (o instanceof BdfDictionary) return (BdfDictionary) o;
throw new FormatException();
}
public BdfDictionary getDictionary(int index, BdfDictionary defaultValue) {
Object o = get(index);
if (o instanceof BdfDictionary) return (BdfDictionary) o;

View File

@@ -7,9 +7,6 @@ public interface BdfReader {
boolean eof() throws IOException;
void close() throws IOException;
void addConsumer(Consumer c);
void removeConsumer(Consumer c);
boolean hasNull() throws IOException;
void readNull() throws IOException;
void skipNull() throws IOException;

View File

@@ -1,12 +0,0 @@
package org.briarproject.api.data;
import org.briarproject.api.UniqueId;
public interface DataConstants {
int LIST_START_LENGTH = 1;
int LIST_END_LENGTH = 1;
int UNIQUE_ID_LENGTH = 2 + UniqueId.LENGTH;
}