|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.props.PropertiesDiff
public class PropertiesDiff
An immutable diff/patch representation for well-behaved simple String-->String Properties. These diffs can be used to send just changes/deltas over the wire for well-behaved pure-String Properties.
Where all property names (ie keys) are pure 8-bit values a more compact internal (still immutable) form will be used for them.
Also individual values will be held in a more compact form where possible.
This class itself is immutable and Serializable, and designed to be efficient on the wire.
Note that comments are not retained, and the diff elements are ordered to allow efficient compression.
The diff notes elements that are removed and that are changed/added with the new/changed value in its entirety.
This does not record changes below the level of a single element, ie may not be effective for small number of large, often-changing values.
This class does not attempt to intern() keys or values unless asked to.
| Field Summary | |
|---|---|
private int |
_hash
Cached hash value; initially zero. |
private java.util.NavigableSet<java.lang.CharSequence> |
deletedNames
The logically immutable in-order set of items/names entirely removed; never null. |
static PropertiesDiff |
EMPTY_DIFF
Immutable empty diff. |
private static java.util.Properties |
EMPTY_PROPERTIES
Private empty Properties map; never changed, never null. |
private java.util.NavigableMap<java.lang.CharSequence,java.lang.CharSequence> |
newValues
The logically immutable in-order map from items/names to the new/changed values; never null. |
private static long |
serialVersionUID
Serial UID. |
int |
sizeAfter
The entry count for the output properties set as a sanity-check; guaranteed non-negative. |
int |
sizeBefore
The entry count for the input properties set as a sanity-check; guaranteed non-negative. |
static java.util.Comparator<java.lang.CharSequence> |
SORT_ORDER
Comparator that provides total ordering for sorted results; not null. |
| Constructor Summary | |
|---|---|
PropertiesDiff()
Make new empty diff instance. |
|
PropertiesDiff(int sizeBefore,
int sizeAfter,
java.util.Set<? extends java.lang.CharSequence> deleted,
java.util.Map<? extends java.lang.CharSequence,? extends java.lang.CharSequence> added)
Create diff instance. |
|
| Method Summary | |
|---|---|
private static java.util.Set<Tuple.Pair<java.lang.CharSequence,java.lang.CharSequence>> |
_computeChangeValues(java.util.Properties p)
Create "change" values from a Properties instance; never null. |
static java.util.Properties |
applyDiff(java.util.Properties p1,
PropertiesDiff diff)
Applies diff to an extant Properties instance to generate a new AEP instance; never null. |
private static java.util.NavigableSet<java.lang.CharSequence> |
convertAllToNameOrAllToString(java.util.Set<? extends java.lang.CharSequence> in)
Convert all supplied CharSequence values to Name else convert them all to String; never null. |
static PropertiesDiff |
createAsStandAloneDiff(java.util.Properties p1)
Create diff against empty Properties. |
static PropertiesDiff |
createDiff(java.util.Properties p1,
java.util.Properties p2,
boolean force,
boolean intern)
Create diff between two Properties instances; never null. |
static java.util.Properties |
createFromStandAloneDiff(PropertiesDiff pd)
Create from diff against empty Properties. |
boolean |
equals(java.lang.Object obj)
Equal iff all fields are identical. |
java.util.SortedMap<java.lang.CharSequence,java.lang.CharSequence> |
getNewValues()
Get (immutable) newValues; never null. |
int |
hashCode()
Hash code depends on all deleted/changed elements; guaranteed zero for an empty diff, non-zero otherwise. |
boolean |
isEmpty()
Returns true iff the diff is "empty", ie no deletions nor additions/changes. |
static Tuple.Pair<java.util.Properties,java.lang.Long> |
loadFromFile(java.io.File filename)
Load properties with timestamp; never null. |
private void |
readObject(java.io.ObjectInputStream ois)
Deserialise. |
protected java.lang.Object |
readResolve()
Deserialise: including discarding duplicate empty values. |
java.lang.String |
toString()
Human-readable summary of state. |
void |
validateObject()
Checks that the object is internally consistent. |
private void |
writeObject(java.io.ObjectOutputStream oos)
Write out a less-redundant form of our internal information. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.util.Comparator<java.lang.CharSequence> SORT_ORDER
private transient java.util.NavigableSet<java.lang.CharSequence> deletedNames
Keys in this set are always of a single type, eg all String or all Name.
private transient java.util.NavigableMap<java.lang.CharSequence,java.lang.CharSequence> newValues
Keys in this map are always of a single type, eg all String or all Name.
Values in this map may be of mixed type.
public final int sizeBefore
public final int sizeAfter
public static final PropertiesDiff EMPTY_DIFF
private static final java.util.Properties EMPTY_PROPERTIES
private transient int _hash
Since access is atomic, this need not be marked volatile.
Never set to zero once non-zero.
private static final long serialVersionUID
| Constructor Detail |
|---|
public PropertiesDiff()
public PropertiesDiff(int sizeBefore,
int sizeAfter,
java.util.Set<? extends java.lang.CharSequence> deleted,
java.util.Map<? extends java.lang.CharSequence,? extends java.lang.CharSequence> added)
sizeBefore - size of input Properties; non-negativesizeAfter - size of output Properties; non-negativedeleted - names present in input and not present in output; non-nulladded - new/changed name-value pairs in output; non-null| Method Detail |
|---|
private static final java.util.NavigableSet<java.lang.CharSequence> convertAllToNameOrAllToString(java.util.Set<? extends java.lang.CharSequence> in)
public java.util.SortedMap<java.lang.CharSequence,java.lang.CharSequence> getNewValues()
Values may be of a mix of (immutable) types within one result.
The comparator is SORT_ORDER and we use a SortedMap so as not to rely on hashCode() and equals(), eg we can look up with a String key in a table whose actual keys are Name.
private static java.util.Set<Tuple.Pair<java.lang.CharSequence,java.lang.CharSequence>> _computeChangeValues(java.util.Properties p)
The first element in each Pair is the (non-null) property name; the second element is the (non-null) property value.
p - non-null pure String-->String properties setpublic static PropertiesDiff createAsStandAloneDiff(java.util.Properties p1)
Forces intern()ing of the keys and values.
public static java.util.Properties createFromStandAloneDiff(PropertiesDiff pd)
throws AllExhibitPropertiesDelta.DiffException
AllExhibitPropertiesDelta.DiffException
public static PropertiesDiff createDiff(java.util.Properties p1,
java.util.Properties p2,
boolean force,
boolean intern)
throws AllExhibitPropertiesDelta.DiffException
This will refuse to create a diff if it seems that the diff is unlikely to be useful, for example:
force - if true then force a diff to be produced
even if this routine would normally refuse to do so on efficiency groundsintern - if true than force intern()ing of all String values
AllExhibitPropertiesDelta.DiffException - if no diff can be generated
or is unlikely to be worthwhile to use
(eg would be more than a fraction of the size of the second AEP)
public static java.util.Properties applyDiff(java.util.Properties p1,
PropertiesDiff diff)
throws AllExhibitPropertiesDelta.DiffException
We do very basic/quick sanity checks on the before/after sizes to catch misapplication of a diff to a clearly-inappropriate Properties set.
AllExhibitPropertiesDelta.DiffException - if the diff cannot be appliedpublic boolean isEmpty()
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
private void writeObject(java.io.ObjectOutputStream oos)
throws java.io.IOException
None of the values written are intern()ed during serialisation, at the risk of not unifying them with identical values in the object stream, to avoid inadvertently creating permanent intern() overhead for them.
java.io.IOException
private void readObject(java.io.ObjectInputStream ois)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
protected java.lang.Object readResolve()
throws java.io.ObjectStreamException
java.io.ObjectStreamException
public void validateObject()
throws java.io.InvalidObjectException
validateObject in interface java.io.ObjectInputValidationjava.io.InvalidObjectException
public static Tuple.Pair<java.util.Properties,java.lang.Long> loadFromFile(java.io.File filename)
throws java.io.IOException
java.io.IOException - in case of difficulty loading the file
java.io.FileNotFoundException - if the file is absent/unreadable
|
DHD Multimedia Gallery V1.60.69 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||