Package Torello.Java.ReadOnly
Class ReadOnlyProperties
- java.lang.Object
-
- Torello.Java.ReadOnly.ReadOnlyHashtable<java.lang.Object,java.lang.Object>
-
- Torello.Java.ReadOnly.ReadOnlyProperties
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,ReadOnlyDictionary<java.lang.Object,java.lang.Object>,ReadOnlyMap<java.lang.Object,java.lang.Object>
public class ReadOnlyProperties extends ReadOnlyHashtable<java.lang.Object,java.lang.Object>
This class was originally copied fromGitHub's Open-JDKAccount. It has been heavily modified as all method bodies have been removed; although few changes were applied to the file's Javadoc Commenting. Method and parameter names & types have not been modified whatsoever - although several methods have been eliminated.
This file contains quite a bit of Wrapper-Code which has been placed around the code from the original Open JDK-21 Source-File of the same (or, rather, highly similar) Class-Name. The original JDK Source-File may be viewed on theJDK-21 GitHubpublic (and, coincidentally, Read-Only) Source-Release archive for Java Packagejava.util.*
The Original'.java'Source-File's Header-Copyright Information is included here:File Copyright. Within that Copyright Notice, it is suggested that a copy of theGNU Public License V2also be included alongside.Immutable Wrapper forjava.util.Properties, found in the "Java Collections Framework".
Immutable Wrapper Class:
This data class contains all of the methods that the standard Java class 'Properties' contains - except those which would directly or indirectly modify / mutate the internal data-structure.
In order to guarantee that the contents and values of thisPropertiesremain constant and unchanged, this class retains an internalProperties, and assigns it the Java modifier'private'to prevent any outside, unwanted modification. This class' own methods are all trivial, single-line wrappers that invoke the originaljava.utilmethods, but leave out any & all wrappers for methods that have the ability to modify, update, remove or insert values into the internal and privateProperties.
Finally, this class offers a Read Only Guarantee, which is enforced by preventing any instantiation of this class from occuring that would allow outside references of its internal, privatePropertiesfield
ImmutableinterfaceInheritance-Tree:
This class implements a variant of the JDK'sjava.util.*Interface-Stack, all of which have been slightly modified (and renamed to add the prefix'ReadOnly'to their names). This decision was necessary because many of the support functions inside Java Collection Framework classes have utility / helper methods that retrieve & generate Sub-Maps and Sub-Sets that are linked to the originalCollection's, Set'sandMap'sfrom whence they were produced.
These Sub-Map / Sub-Set retrieval methods all sing the same refrain - changes to the returnedMap/Setwill be reflected into'this'instance, and vice-versa.
TheseSub-Map'sandSub-Set'swould easily (even though 'accidentally') provide a dangerous back-door means for modifying and updating a Collection that is claiming to be Read-Only & Immutable.
As a result, the decision was made to also port all of thejava.util.*interfaces, such asSet, Map, List & Collection, into the Read-Only Collections Framework by renaming them toReadOnlySet, ReadOnlyMap, & ReadOnlyCollection- and of course to remove / eliminate all Mutator-Methods from those interfaces. This extra step further guarantees the provision that this Data-Class is, truly, Read-Only and un-modifiable.
Self-Referential ReadOnlyProperties's
Though likely uncommon in most typical software projects, it is possible for aPropertiesto actually contain a reference to itself. However, in the translation from a standardPropertiesto aReadOnlyProperties, there is actually no direct and realizable way to preserve any self-referential pointers inside theReadOnlyPropertieswhich is being constructed.
Java's Generic Type-System, generally, makes such references nearly (but not completely) impossible. Unless you have assignedjava.lang.Objectto the Data-Class' Generic-Type, there is likely no common Ancestor-Type that would inherit both aReadOnlyProperties, and the other objects in your data-set.
As a result, if you happen to pass an instance of data that contains references or pointers to itself, those pointers will not be updated to reference the Read-Only variant of your Data-Structure when that Data-Structure is created. TheReadOnlyPropertiesthat you get back will simply contain pointers to the original Data-Structure you passed to the constructor of this class!- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/Java/ReadOnly/ReadOnlyProperties.java
- Open New Browser-Tab: Torello/Java/ReadOnly/ReadOnlyProperties.java
File Size: 29,253 Bytes Line Count: 692 '\n' Characters Found
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface Torello.Java.ReadOnly.ReadOnlyMap
ReadOnlyMap.Entry<K,V>
-
-
Field Summary
Fields Modifier and Type Field protected static longserialVersionUID
-
Constructor Summary
Construct an Instance using a Runnable / Tuple2 Combination Constructor ReadOnlyProperties(
Tuple2<Object,Object> refHolder,
Runnable computeNextEntry,
Integer sizeIfKnown
)Map or Properties Source: Build Instance Constructor ReadOnlyProperties(Map<A,B> map, BiFunction<A,B,Ret2<String,String>> mapTranslator)ReadOnlyProperties(Properties properties)Stream or Reader Source: Build an Instance Constructor ReadOnlyProperties(
InputStream inStream,
Integer sizeIfKnown
)ReadOnlyProperties(
Reader reader,
Integer sizeIfKnown
)ReadOnlyProperties(
Integer sizeIfKnown,
InputStream in
)
-
Method Summary
Get a Property (a Hashtable Value) Modifier and Type Method Objectget(Object key)ObjectgetOrDefault(Object key, Object defaultValue)StringgetProperty(String key)StringgetProperty(String key, String defaultValue)Retrieve all Properties Keys Modifier and Type Method Enumeration<Object>keys()ReadOnlySet<Object>keySet()Enumeration<?>propertyNames()ReadOnlySet<String>stringPropertyNames()Retrieve all Properties Values Modifier and Type Method Enumeration<Object>elements()ReadOnlyCollection<Object>values()Check this Properties' Contents Modifier and Type Method booleancontains(Object value)booleancontainsKey(Object key)booleancontainsValue(Object value)booleanisEmpty()intsize()Write this Properties Table to an Output Stream or Writer Modifier and Type Method voidlist(PrintStream out)voidlist(PrintWriter out)voidstore(OutputStream out, String comments)voidstore(Writer writer, String comments)voidstoreToXML(OutputStream os, String comment)voidstoreToXML(OutputStream os, String comment, String encoding)voidstoreToXML(OutputStream os, String comment, java.nio.charset.Charset charset)Functions for Both the Key and the Value Modifier and Type Method ReadOnlySet<ReadOnlyMap.Entry<Object,
Object>>entrySet()voidforEach(BiConsumer<? super Object,? super Object> action)Convert 'this' to a Standard 'java.util' Collections-Framework Type Modifier and Type Method Map<Object,Object>cloneToMap()PropertiescloneToProperties()Map<Object,Object>wrapToImmutableMap()Retrieve a Singleton Empty-Instance Modifier and Type Method static ReadOnlyPropertiesemptyROP()Methods: class java.lang.Object Modifier and Type Method booleanequals(Object o)inthashCode()StringtoString()-
Methods inherited from class Torello.Java.ReadOnly.ReadOnlyHashtable
cloneToHashtable, cloneToHashtableOLD, emptyROHT
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface Torello.Java.ReadOnly.ReadOnlyMap
containsKeyAND, containsKeyAND, containsKeyNAND, containsKeyNAND, containsKeyOR, containsKeyOR, containsKeyXOR, containsKeyXOR, containsValueAND, containsValueAND, containsValueNAND, containsValueNAND, containsValueOR, containsValueOR, containsValueXOR, containsValueXOR, copyIntoMap
-
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable. Using theSerializableImplementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
protected static final long serialVersionUID = 1;
-
-
Constructor Detail
-
ReadOnlyProperties
public ReadOnlyProperties(java.util.Properties properties)
Clones parameter'properties'(and saves it) in order to guarantee that'this'instance is Read-Only and furthermore shielded from outside modification.- Parameters:
properties- ThePropertiesto be cloned and saved into this instance internal and private'properties'field.- Code:
- Exact Constructor Body:
// This is a little bizarre, but necessary. Properties extends Hashtable super(friendClassBadge); this.fromBuilderOrProperties = false; // TO-DO: FIX-ME, CLONE IS NOT ACCEPTABLE IN READ-ONLY !!! IT IS A BACK-DOOR !!! this.properties = (Properties) properties.clone();
-
ReadOnlyProperties
public ReadOnlyProperties (java.util.Map<A,B> map, java.util.function.BiFunction<A,B,Ret2<java.lang.String,java.lang.String>> mapTranslator)
If only a small amount of processing needs to be done on the contents of some Java Map, and using an entire Builder-Class seems disproportionately complex - this constructor can convert any JavaMapinto aReadOnlyProperties, using a simple'mapTranslator'.- Type Parameters:
A- The Key-Type of the User-ProvidedMap.B- The Value-Type of the User-ProvidedMap.- Parameters:
map- Any JavaMap.mapTranslator- A function for mapping the iterated elements of Map-Types'A'and'B', into the actualProperties'sKey and Value Type'String'.
If this parameter is passed null, this method will throw aNullPointerException.- Throws:
java.lang.NullPointerException- if either parameter'i'or parameter'mapTranslator'is passed null.- Code:
- Exact Constructor Body:
super(friendClassBadge); Objects.requireNonNull(mapTranslator, "You have passed null to parameter 'mapTranslator'"); fromBuilderOrProperties = false; Properties properties = new Properties(map.size()); for (Map.Entry<A, B> entry : map.entrySet()) { Ret2<String, String> ret2 = mapTranslator.apply(entry.getKey(), entry.getValue()); properties.put(ret2.a, ret2.b); } // Empty Optimization (throw away, completely, the reference, use static-constant) this.properties = (properties.size() == 0) ? EMPTY_PROPERTIES : properties;
-
ReadOnlyProperties
public ReadOnlyProperties(java.io.InputStream inStream, java.lang.Integer sizeIfKnown) throws java.io.IOException
Reads a property list (key and element pairs) from the input byte stream. The input stream is in a simple line-oriented format as specified inload(Reader)and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section3.3of The Java Language Specification.
The specified stream remains open after this method returns.
This Detail-Comment was copied from class:java.util.Properties, JDK 21
Method: Properties.load(InputStream.inStream)- Parameters:
inStream- the input stream.sizeIfKnown- If the number of elements to be inserted is known, this value / size may be provided, here, to parameter'sizeIfKnown'. This allows the internalPropertiesinstance to be adequately sized & initialized at the beginning of this constructor, alleviating the need / overhead of resizing, again, during this class' construction.
It is not mandatory that the value provided be accurate, as ought be seen in the code below, this value is solely used for the'initialCapacity'argument to thePropertiesconstructor. When it is more accurate, the Data-Structure operates more efficiently.- Throws:
java.io.IOException- if an error occurred when reading from the input stream.java.lang.IllegalArgumentException- if the input stream contains a malformed Unicode escape sequence.java.lang.NullPointerException- ifinStreamis null.- Code:
- Exact Constructor Body:
super(friendClassBadge); this.fromBuilderOrProperties = false; this.properties = (sizeIfKnown != null) ? new Properties(sizeIfKnown) : new Properties(); this.properties.load(inStream);
-
ReadOnlyProperties
public ReadOnlyProperties(java.io.Reader reader, java.lang.Integer sizeIfKnown) throws java.io.IOException
Reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.
Properties are processed in terms of lines. There are two kinds of lines, natural lines and logical lines. A natural line is defined as a line of characters that is terminated either by a set of line terminator characters ('\n'or'\r'or'\r\n') or by the end of the stream. A natural line may be either a blank line, a comment line, or hold all or some of a key-element pair. A logical line holds all the data of a key-element pair, which may be spread out across several adjacent natural lines by escaping the line terminator sequence with a backslash character'\'. Note that a comment line cannot be extended in this manner; every natural line that is a comment must have its own comment indicator, as described below. Lines are read from input until the end of the stream is reached.
A natural line that contains only white space characters is considered blank and is ignored. A comment line has an ASCII'#'or'!'as its first non-whitespace character; comment lines are also ignored and do not encode key-element information. In addition to line terminators, this format considers the characters space (' ','\u005Cu0020'), tab ('\t','\u005Cu0009'), and form feed ('\f','\u005Cu000C') to be white space.
If a logical line is spread across several natural lines, the backslash escaping the line terminator sequence, the line terminator sequence, and any white space at the start of the following line have no effect on the key or element values. The remainder of the discussion of key and element parsing (when loading) will assume all the characters constituting the key and element appear on a single natural line after line continuation characters have been removed. Note that it is not sufficient to only examine the character preceding a line terminator sequence to decide if the line terminator is escaped; there must be an odd number of contiguous backslashes for the line terminator to be escaped. Since the input is processed from left to right, a non-zero even number of 2n contiguous backslashes before a line terminator (or elsewhere) encodes n backslashes after escape processing.
The key contains all of the characters in the line starting with the first non-whitespace character and up to, but not including, the first unescaped'=',':', or white space character other than a line terminator. All of these key termination characters may be included in the key by escaping them with a preceding backslash character; for example,
\:\=
would be the two-character key":=". Line terminator characters can be included using'\r'and'\n'escape sequences. Any white space after the key is skipped; if the first non-whitespace character after the key is'='or':', then it is ignored and any white space characters after it are also skipped. All remaining characters on the line become part of the associated element string; if there are no remaining characters, the element is the empty string"". Once the raw character sequences constituting the key and element are identified, escape processing is performed as described above.
As an example, each of the following three lines specifies the key"Truth"and the associated element value"Beauty":Truth = BeautyTruth: BeautyTruth :Beuty
As another example, the following three lines specify a single property:fruits apple, banana, pear, \ cantaloupe, watermelon, \ kiwi, mango
The key is"fruits"and the associated element is:"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"
Note that a space appears before each'\'so that a space will appear after each comma in the final result; the'\', line terminator, and leading white space on the continuation line are merely discarded and are not replaced by one or more other characters.
As a third example, the line:cheeses
specifies that the key is"cheeses"and the associated element is the empty string"".
Characters in keys and elements can be represented in escape sequences similar to those used for character and string literals (see The Java Language Specification section 3.3 and 3.10.6 The differences from the character escape sequences and Unicode escapes used for characters and strings are:- Octal escapes are not recognized.
- The character sequence
'\b'does not represent a backspace character. - The method does not treat a backslash character,
'\', before a non-valid escape character as an error; the backslash is silently dropped. For example, in a JavaStringthe sequence"\z"would cause a compile time error. In contrast, this method silently drops the backslash. Therefore, this method treats the two character sequence"\b"as equivalent to the single character'b'. - Escapes are not necessary for single and double quotes; however, by the rule above, single and double quote characters preceded by a backslash still yield single and double quote characters, respectively.
- Only a single
'u'character is allowed in a Unicode escape sequence.
The specified stream remains open after this method returns.
This Detail-Comment was copied from class:java.util.Properties, JDK 21
Method: Properties.load(InputStream.inStream)- Parameters:
reader- the input character stream.sizeIfKnown- If the number of elements to be inserted is known, this value / size may be provided, here, to parameter'sizeIfKnown'. This allows the internalPropertiesinstance to be adequately sized & initialized at the beginning of this constructor, alleviating the need / overhead of resizing, again, during this class' construction.
It is not mandatory that the value provided be accurate, as ought be seen in the code below, this value is solely used for the'initialCapacity'argument to thePropertiesconstructor. When it is more accurate, the Data-Structure operates more efficiently.- Throws:
java.io.IOException- if an error occurred when reading from the input stream.java.lang.IllegalArgumentException- if a malformed Unicode escape appears in the input.java.lang.NullPointerException- ifreaderis null.- Code:
- Exact Constructor Body:
super(friendClassBadge); this.fromBuilderOrProperties = false; this.properties = (sizeIfKnown != null) ? new Properties(sizeIfKnown) : new Properties(); this.properties.load(reader);
-
ReadOnlyProperties
public ReadOnlyProperties(java.lang.Integer sizeIfKnown, java.io.InputStream in) throws java.io.IOException, java.io.UnsupportedEncodingException, java.util.InvalidPropertiesFormatException
Loads all of the properties represented by the XML document on the specified input stream into this properties table.
The XML document must have the following DOCTYPE declaration:
HTML Elements:
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
Furthermore, the document must satisfy the properties DTD described above.
An implementation is required to read XML documents that use the "UTF-8" or "UTF-16" encoding. An implementation may support additional encodings.
The specified stream is closed after this method returns.
This Detail-Comment was copied from class:java.util.Properties, JDK 21
Method: Properties.load(InputStream.inStream)- Parameters:
sizeIfKnown- If the number of elements to be inserted is known, this value / size may be provided, here, to parameter'sizeIfKnown'. This allows the internalPropertiesinstance to be adequately sized & initialized at the beginning of this constructor, alleviating the need / overhead of resizing, again, during this class' construction.
It is not mandatory that the value provided be accurate, as ought be seen in the code below, this value is solely used for the'initialCapacity'argument to thePropertiesconstructor. When it is more accurate, the Data-Structure operates more efficiently.in- the input stream from which to read the XML document.- Throws:
java.io.IOException- if reading from the specified input stream results in anIOException.java.io.UnsupportedEncodingException- if the document's encoding declaration can be read and it specifies an encoding that is not supportedjava.util.InvalidPropertiesFormatException- Data on input stream does not constitute a valid XML document with the mandated document type.java.lang.NullPointerException- ifinis null.- See Also:
storeToXML(OutputStream, String, String), Character Encoding in Entities- Code:
- Exact Constructor Body:
super(friendClassBadge); this.fromBuilderOrProperties = false; this.properties = (sizeIfKnown != null) ? new Properties(sizeIfKnown) : new Properties(); this.properties.loadFromXML(in);
-
ReadOnlyProperties
public ReadOnlyProperties (Tuple2<java.lang.Object,java.lang.Object> refHolder, java.lang.Runnable computeNextEntry, java.lang.Integer sizeIfKnown)
Builds aPropertiesinstance using the'refHolder'&'computeNextEntry'combination.- Parameters:
refHolder- Any instance ofTuple2may be passed to this parameter. This reference may not be null, or aNullPointerExceptionwill throw immediately.
This parameter must be used to populate thisReadOnlyPropertiesinstance.
The'computeNextEntry'instance provided to this method, when invoked, should place each Key-Value Pair that it computes into the two fields of this'refHolder'. After invoking the'computeNextEntry'consumer, the contents of thisTuple2are inserted into thisReadOnlyMapinstance.
Please review the Source-Code in the window below. It, hopefully, elucidates how this method retrieves the data to be placed into thisReadOnlyPropertiesusing this'refHolder'.computeNextEntry- ThisRunnableinstance will be called to compute the Key-Value Pairs that are to be inserted into thisReadOnlyPropertiesinstance. The Lambda-Expression or Method provided to thisRunnablemust place each Key-Value Pair into the'refHolder'instance.
After each insertion that is performed, the logic will check if the Key and Value ofTuple2instance have been passed null. When both the Key and the Value are null, this Constructor will cease inserting data into this instance internalProperties, and exit.
NOTE: It is acceptabe for thisRunnableto return multiple values for a single Key. If redundant Keys are placed into the'refHolder', the old value assigned to the key will be over-written by the latest value. If both a key and a value placed into'refHolder'are duplicates, both will be reinserted a second time, which doesn't have any effect on the internally storedProperties.
Again, for a detailed understanding of how to use this parameter, it is best just to look at the imported Constructor-Body below!sizeIfKnown- If the number of elements to be inserted is known, this value / size may be provided, here, to parameter'sizeIfKnown'. This allows the internalPropertiesinstance to be adequately sized & initialized at the beginning of this constructor, alleviating the need / overhead of resizing, again, during this class' construction.
It is not mandatory that the value provided be accurate, as ought be seen in the code below, this value is solely used for the'initialCapacity'argument to thePropertiesconstructor. When it is more accurate, the Data-Structure operates more efficiently.- Code:
- Exact Constructor Body:
super(friendClassBadge); Objects.requireNonNull(refHolder, ROHelpers.NULL_MSG + "'refHolder'"); Objects.requireNonNull(computeNextEntry, ROHelpers.NULL_MSG + "'computeNextEntry'"); fromBuilderOrProperties = false; Properties properties = new Properties(((sizeIfKnown == null) ? 16 : sizeIfKnown)); do { computeNextEntry.run(); if ((refHolder.a == null) && (refHolder.b == null)) break; properties.put(refHolder.a, refHolder.b); } while (true); // Empty Optimization (throw away, completely, the reference, use static-constant) this.properties = (properties.size() == 0) ? EMPTY_PROPERTIES : properties;
-
-
Method Detail
-
emptyROP
public static ReadOnlyProperties emptyROP()
Returns an empty singleton instance of this class.
NOTE: The instance that is returned is astatic, finalconstant which is constructed during the loading of this class by the Class-Loader. It is fully Thread-Safe, unless it is going to be used as an Object-Monitor to help lock a Synchronized Code-Block!- Code:
- Exact Method Body:
return EMPTY_READONLY_PROPERTIES;
-
store
public void store(java.io.Writer writer, java.lang.String comments) throws java.io.IOException
Writes this property list (key and element pairs) from this instance' internalPropertiestable to the output character stream (in a format suitable for using theProperties.load(Reader)method.
Properties from the defaults table of thisPropertiestable (if any) are not written out by this method.
If the comments argument is not null, then an ASCII'#'character, the comments string, and a line separator are first written to the output stream. Thus, thecommentscan serve as an identifying comment. Any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a line feed ('\r\n') in comments is replaced by aSystem.lineSeparator()and if the next character in comments is not character'#'or character'!'then an ASCII'#'is written out after that line separator.
If the System-Propertyjava.properties.dateis set on the command line and is non-empty (as determined byString.isEmpty(), a comment line is written as follows. First, a'#'character is written, followed by the contents of the property, followed by a line separator. Any line terminator characters in the value of the system property are treated the same way as noted above for the comments argument. If the system property is not set or is empty, a comment line is written as follows. First, a'#'character is written, followed by the current date and time formatted as if by theDate.toString()method, followed by a line separator.
Then every entry in thisPropertiestable is written out, one per line. For each entry the key string is written, then an ASCII'=', then the associated element string. For the key, all space characters are written with a preceding'\'character. For the element, leading space characters, but not embedded or trailing space characters, are written with a preceding'\'character. The key and element characters'#','!','=', and':'are written with a preceding backslash to ensure that they are properly loaded.
After the entries have been written, the output stream is flushed. The output stream remains open after this method returns.
The keys and elements are written in the natural sort order of the keys in theentrySet()unlessentrySet()is overridden by a subclass to return a different value thansuper.entrySet().- Parameters:
writer- an output character stream writer.comments- a description of the property list.- Throws:
java.io.IOException- if writing this property list to the specified output stream throws anIOException.java.lang.ClassCastException- if thisPropertiesobject contains any keys or values that are notStrings.java.lang.NullPointerException- ifwriteris null.- Code:
- Exact Method Body:
this.properties.store(writer, comments);
-
store
public void store(java.io.OutputStream out, java.lang.String comments) throws java.io.IOException
Writes this property list (key and element pairs) from this instance' internalPropertiestable to the output character stream in a format suitable for using theProperties.load(InputStream)method.
Properties from the defaults table of thisPropertiestable (if any) are not written out by this method.
This method outputs the comments, properties keys and values in the same format as specified instore(Writer)with the following differences:- The stream is written using the ISO 8859-1 character encoding.
- Characters not in Latin-1 in the comments are written as
'\u005Cu'xxxx for their appropriate unicode hexadecimal value xxxx. - Characters less than
\u005Cu0020and characters greater than'\u005Cu007E'in property keys or values are written as'\u005Cu'xxxx for the appropriate hexadecimal value xxxx.
After the entries have been written, the output stream is flushed. The output stream remains open after this method returns.- Parameters:
out- an output stream.comments- a description of the property list.- Throws:
java.io.IOException- if writing this property list to the specified output stream throws anIOException.java.lang.ClassCastException- if thisPropertiesobject contains any keys or values that are notStrings.java.lang.NullPointerException- ifoutis null.- Code:
- Exact Method Body:
this.properties.store(out, comments);
-
storeToXML
public void storeToXML(java.io.OutputStream os, java.lang.String comment) throws java.io.IOException
Emits an XML document representing all of the properties contained in this table.
An invocation of this method of the formprops.storeToXML(os, comment)behaves in exactly the same way as the invocationprops.storeToXML(os, comment, "UTF-8");.- Parameters:
os- the output stream on which to emit the XML document.comment- a description of the property list, ornullif no comment is desired.- Throws:
java.io.IOException- if writing to the specified output stream results in anIOException.java.lang.NullPointerException- ifosis null.java.lang.ClassCastException- if thisPropertiesobject contains any keys or values that are notStrings.- Code:
- Exact Method Body:
this.properties.storeToXML(os, comment);
-
storeToXML
public void storeToXML(java.io.OutputStream os, java.lang.String comment, java.lang.String encoding) throws java.io.IOException
Emits an XML document representing all of the properties contained in this table, using the specified encoding.
The XML document will have the following DOCTYPE declaration:
HTML Elements:
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">;
If the specified comment isnullthen no comment will be stored in the document.
An implementation is required to support writing of XML documents that use the "UTF-8" or "UTF-16" encoding. An implementation may support additional encodings.
The specified stream remains open after this method returns.
This method behaves the same asstoreToXML(OutputStream, String, Charset)except that it will look up the charset using the given encoding name.- Parameters:
os- the output stream on which to emit the XML document.comment- a description of the property list, ornullif no comment is desired.encoding- the name of a supported character encoding- Throws:
java.io.IOException- if writing to the specified output stream results in anIOException.java.io.UnsupportedEncodingException- if the encoding is not supported by the implementation.java.lang.NullPointerException- ifosisnull, or ifencodingisnull.java.lang.ClassCastException- if thisPropertiesobject contains any keys or values that are notStrings.- See Also:
- Character Encoding in Entities
- Code:
- Exact Method Body:
this.properties.storeToXML(os, comment, encoding);
-
storeToXML
public void storeToXML(java.io.OutputStream os, java.lang.String comment, java.nio.charset.Charset charset) throws java.io.IOException
Emits an XML document representing all of the properties contained in this table, using the specified encoding.
The XML document will have the following DOCTYPE declaration:
HTML Elements:
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
If the specified comment isnullthen no comment will be stored in the document.
An implementation is required to support writing of XML documents that use the "UTF-8" or "UTF-16" encoding. An implementation may support additional encodings.
Unmappable characters for the specified charset will be encoded as numeric character references.
The specified stream remains open after this method returns.- Parameters:
os- the output stream on which to emit the XML document.comment- a description of the property list, ornullif no comment is desired.charset- the charset- Throws:
java.io.IOException- if writing to the specified output stream results in anIOException.java.lang.NullPointerException- ifosorcharsetisnull.java.lang.ClassCastException- if thisPropertiesobject contains any keys or values that are notStrings.- See Also:
- Character Encoding in Entities
- Code:
- Exact Method Body:
this.properties.storeToXML(os, comment, charset);
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returnsnullif the property is not found.- Parameters:
key- the property key.- Returns:
- the value in this property list with the specified key value.
- Code:
- Exact Method Body:
return this.properties.getProperty(key);
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.- Parameters:
key- the hashtable key.defaultValue- a default value.- Returns:
- the value in this property list with the specified key value.
- Code:
- Exact Method Body:
return this.properties.getProperty(key, defaultValue);
-
propertyNames
public java.util.Enumeration<?> propertyNames()
Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.- Returns:
- an enumeration of all the keys in this property list, including the keys in the default property list.
- Throws:
java.lang.ClassCastException- if any key in this property list is not aString.- See Also:
stringPropertyNames()- Code:
- Exact Method Body:
return this.properties.propertyNames();
-
stringPropertyNames
public ReadOnlySet<java.lang.String> stringPropertyNames()
Returns an unmodifiable set of keys from this property list where the key and its corresponding value are strings, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list. Properties whose key or value is not of typeStringare omitted.
The returned set is not backed by thisPropertiesobject. Changes to thisPropertiesobject are not reflected in the returned set.- Returns:
- an unmodifiable set of keys in this property list where the key and its corresponding value are strings, including the keys in the default property list.
- Code:
- Exact Method Body:
return new JavaHTMLReadOnlySet<>(this.properties.stringPropertyNames());
-
list
public void list(java.io.PrintStream out)
Prints this property list out to the specified output stream. This method is useful for debugging.- Parameters:
out- an output stream.- Throws:
java.lang.ClassCastException- if any key in this property list is not aString.- Code:
- Exact Method Body:
this.properties.list(out);
-
list
public void list(java.io.PrintWriter out)
Prints this property list out to the specified output stream. This method is useful for debugging.- Parameters:
out- an output stream.- Throws:
java.lang.ClassCastException- if any key in this property list is not aString.- Code:
- Exact Method Body:
this.properties.list(out);
-
size
public int size()
Description copied from class:ReadOnlyHashtableReturns the number of keys in thisHashtable.- Specified by:
sizein interfaceReadOnlyDictionary<java.lang.Object,java.lang.Object>- Specified by:
sizein interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
sizein classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- the number of keys in this
Hashtable. - Code:
- Exact Method Body:
return this.properties.size();
-
isEmpty
public boolean isEmpty()
Description copied from class:ReadOnlyHashtableTests if thisHashtablemaps no keys to values.- Specified by:
isEmptyin interfaceReadOnlyDictionary<java.lang.Object,java.lang.Object>- Specified by:
isEmptyin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
isEmptyin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
TRUEif thisHashtablemaps no keys to values;FALSEotherwise.- Code:
- Exact Method Body:
return this.properties.isEmpty();
-
keys
public java.util.Enumeration<java.lang.Object> keys()
Description copied from class:ReadOnlyHashtableReturns an enumeration of the keys in thisHashtable. Use the Enumeration methods on the returned object to fetch the keys sequentially.- Specified by:
keysin interfaceReadOnlyDictionary<java.lang.Object,java.lang.Object>- Overrides:
keysin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- an enumeration of the keys in this
Hashtable. - See Also:
ReadOnlyHashtable.elements(),ReadOnlyHashtable.keySet(),ReadOnlyMap- Code:
- Exact Method Body:
return this.properties.keys();
-
elements
public java.util.Enumeration<java.lang.Object> elements()
Description copied from class:ReadOnlyHashtableReturns an enumeration of the values in thisHashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.- Specified by:
elementsin interfaceReadOnlyDictionary<java.lang.Object,java.lang.Object>- Overrides:
elementsin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- an enumeration of the values in this
Hashtable. - See Also:
ReadOnlyHashtable.keys(),ReadOnlyHashtable.values(),ReadOnlyMap- Code:
- Exact Method Body:
return this.properties.elements();
-
contains
public boolean contains(java.lang.Object value)
Description copied from class:ReadOnlyHashtableTests if some key maps into the specified value in thisHashtable. This operation is more expensive than thecontainsKeymethod.
Note that this method is identical in functionality tocontainsValue, (which is part of theReadOnlyMapinterface.- Overrides:
containsin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Parameters:
value- a value to search for- Returns:
TRUEif and only if some key maps to thevalueargument in thisHashtableas determined by theequalsmethod;falseotherwise.- Code:
- Exact Method Body:
return this.properties.contains(value);
-
containsValue
public boolean containsValue(java.lang.Object value)
Description copied from class:ReadOnlyHashtableReturnsTRUEif thisHashtablemaps one or more keys to this value.
Note that this method is identical in functionality toReadOnlyHashtable.contains(java.lang.Object).- Specified by:
containsValuein interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
containsValuein classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Parameters:
value- value whose presence in thisHashtableis to be tested- Returns:
TRUEif this map maps one or more keys to the specified value- Code:
- Exact Method Body:
return this.properties.containsValue(value);
-
containsKey
public boolean containsKey(java.lang.Object key)
Description copied from class:ReadOnlyHashtableTests if the specified object is a key in thisHashtable.- Specified by:
containsKeyin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
containsKeyin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Parameters:
key- possible key- Returns:
TRUEif and only if the specified object is a key in thisHashtable, as determined by theequalsmethod;falseotherwise.- See Also:
ReadOnlyHashtable.contains(Object)- Code:
- Exact Method Body:
return this.properties.containsKey(key);
-
get
public java.lang.Object get(java.lang.Object key)
Description copied from class:ReadOnlyHashtableReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.
More formally, if this map contains a mapping from a keykto a valuevsuch that(key.equals(k)), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)- Specified by:
getin interfaceReadOnlyDictionary<java.lang.Object,java.lang.Object>- Specified by:
getin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
getin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key - Code:
- Exact Method Body:
return this.properties.get(key);
-
keySet
public ReadOnlySet<java.lang.Object> keySet()
Description copied from class:ReadOnlyHashtableReturns aReadOnlySetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.- Specified by:
keySetin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
keySetin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- a set view of the keys contained in this map
- Code:
- Exact Method Body:
return new JavaHTMLReadOnlySet<>( fromBuilderOrProperties ? ((ROPropertiesBuilder) this.properties)._keySet(friendClassBadge) : this.properties.keySet() );
-
values
public ReadOnlyCollection<java.lang.Object> values()
Description copied from class:ReadOnlyHashtableReturns aReadOnlyCollectionview of the values contained in this map.- Specified by:
valuesin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
valuesin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- a collection view of the values contained in this map
- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyCollection<>( fromBuilderOrProperties ? ((ROPropertiesBuilder) this.properties)._values(friendClassBadge) : this.properties.values() );
-
entrySet
public ReadOnlySet<ReadOnlyMap.Entry<java.lang.Object,java.lang.Object>> entrySet ()
Description copied from class:ReadOnlyHashtableReturns aReadOnlySetview of the mappings contained in this map.- Specified by:
entrySetin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
entrySetin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- a set view of the mappings contained in this map
- Code:
- Exact Method Body:
return ROHelperEntrySet.toReadOnlyEntrySet( fromBuilderOrProperties ? ((ROPropertiesBuilder) this.properties)._entrySet(friendClassBadge) : this.properties.entrySet() );
-
getOrDefault
public java.lang.Object getOrDefault(java.lang.Object key, java.lang.Object defaultValue)
Description copied from interface:ReadOnlyMapReturns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.- Specified by:
getOrDefaultin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
getOrDefaultin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Parameters:
key- the key whose associated value is to be returneddefaultValue- the default mapping of the key- Returns:
- the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key - Code:
- Exact Method Body:
return this.properties.getOrDefault(key, defaultValue);
-
forEach
public void forEach (java.util.function.BiConsumer<? super java.lang.Object,? super java.lang.Object> action)
Description copied from interface:ReadOnlyMapPerforms the given action for each entry in this map until all entries have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of entry set iteration (if an iteration order is specified.) Exceptions thrown by the action are relayed to the caller.
The default implementation is equivalent to, for thismap:
for (ReadOnlyMap.Entry<K, V> entry : map.entrySet()) action.accept(entry.getKey(), entry.getValue());
The default implementation makes no guarantees about synchronization or atomicity properties of this method. Any implementation providing atomicity guarantees must override this method and document its concurrency properties.- Specified by:
forEachin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
forEachin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Parameters:
action- The action to be performed for each entry- Code:
- Exact Method Body:
this.properties.forEach(action);
-
cloneToProperties
public java.util.Properties cloneToProperties()
Clone's'this'instance internalPropertiesfield, and returns it. This method generates a Read / Write Cloned Version of'this'instance' internalReadOnlyProperties. The instance that's returned by this method is a clone, and this decision preserves the immutable (Read-Only) protection offered by this class.
Standard JDK Properties
The returned object is a Standard JDKPropertiesdata-structure (the one from packagejava.util). It is mutable, but again because it is a clone of'this'instance's internalProperties, it is not actually 'linked' to the internalProperties
This does mean that changes to the returnedPropertiesinstance will not be reflected to the'this' ReadOnlyProperties. They are, in fact, two independent and unlinked copies of the internal data.- Returns:
- An independent, mutable copy of
'this'instance' internalPropertiesdata-structure. - Code:
- Exact Method Body:
return fromBuilderOrProperties ? new Properties(this.properties) : (Properties) this.properties.clone();
-
cloneToMap
public java.util.Map<java.lang.Object,java.lang.Object> cloneToMap()
Converts this ReadOnlyProperties to a java.util.PropertiesSame: Identical to the method cloneToProperties().Returns: Has Return-Type Map<E>, instead.Implements: Parent-Class ReadOnlyMap.cloneToMap()- Specified by:
cloneToMapin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
cloneToMapin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- For the sub-class
ReadOnlyHashMap, this will return a cloned instance of the internaljava.util.HashMap.
- For the sub-class
ReadOnlyTreeMap, this will return a cloned instance of the internaljava.util.TreeMap.
- For the sub-class
ReadOnlyHashtable, this will return a cloned instance of the internaljava.util.Hashtable.
- For the sub-class
ReadOnlyProperties, this will return a cloned instance of the internaljava.util.Properties.
- For the sub-class
- Code:
- Exact Method Body:
return cloneToProperties();
-
wrapToImmutableMap
public java.util.Map<java.lang.Object,java.lang.Object> wrapToImmutableMap ()
Description copied from interface:ReadOnlyMapInvokesjava.util.Collections.unmodifiableMapon the internalMap
Standard JDKMap:
There may be situations where the TypeReadOnlyMapis simply not usable with an API that can't be adapted to accept Type's from the Java-HTMLReadOnlyPackage. If such a case arises, this method can be used to generate an immutable instance of a JDK-Standardjava.utilType, which does not inherit fromTorello.Java.ReadOnly
Classjava.util.Collectionsoffers a method that wraps a type into an Unmodifiable-Wrapper that implements the standardjava.util.Map, but throws an exception if any attempts are made to invoke Mutator-Methods.
Unmodifiable-Collections throw Exceptions instead:
The returnedjava.util.Mapinstance will hopefully provide an acceptable substitute whenReadOnlyType's cannot match an API's requirements. Java's Immutable-Wrappers work on a different principle - these classes retain any / all Mutator-Methods amongst their Type-Members, but instead throw anUnsupportedOperationExceptionif any of those methods are invoked!
Also, if a Java Collections FrameworkUnmodifiable-Class has any Member-Methods that return a "View" into the underlying Data-Structure, the Sub-Lists and Sub-Maps returned by those methods are also, subsequently, wrapped in anUnmodifiable-Wrapper. These returned instances will also throw anUnsupportedOperationExceptionif any of those methods are invoked!
This does provide a shield or layer of protection against modification to guarantee the "Immutability-Contract" offered by these classes, all-the-while returning to native Java API Collection Types, rather thanTorello.Java.ReadOnlyTypes, which may not always be compatible with a given API or Interface requirement!
Remember, many of the Data-Classes insidejava.utilhave methods whose documentation state very clearly that "any changes made the this [View] will be pushed back into the original type."- Specified by:
wrapToImmutableMapin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
wrapToImmutableMapin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- A
Setwhich adheres to the JDK interfacejava.util.Set, but throws anUnsupportedOperationExceptionif a user attempts to invoke a Mutator-Method on the returned instance. - Code:
- Exact Method Body:
return Collections.unmodifiableMap(this.properties);
-
toString
public java.lang.String toString()
Returns aStringrepresentation of thisProperties. TheStringrepresentation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters", "(comma and space). Elements are converted toString'sas byString.valueOf(Object).- Overrides:
toStringin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- a
Stringrepresentation of thisProperties - Code:
- Exact Method Body:
return this.properties.toString();
-
equals
public boolean equals(java.lang.Object o)
Compares the specified Object with this List for equality, as per the definition in the classjava.util.Properties.- Specified by:
equalsin interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
equalsin classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Parameters:
o- object to be compared for equality with thisProperties- Returns:
TRUEif the specified Object is equal to this map- Code:
- Exact Method Body:
if (this == o) return true; if (! (o instanceof ReadOnlyProperties)) return false; return this.properties.equals(((ReadOnlyProperties) o).properties);
-
hashCode
public int hashCode()
Description copied from class:ReadOnlyHashtableReturns the hash code value for this Map as per the definition in the classjava.util.Hashtable.- Specified by:
hashCodein interfaceReadOnlyMap<java.lang.Object,java.lang.Object>- Overrides:
hashCodein classReadOnlyHashtable<java.lang.Object,java.lang.Object>- Returns:
- the hash code value for this map
- See Also:
ReadOnlyMap.Entry.hashCode(),ReadOnlyMap.equals(Object)- Code:
- Exact Method Body:
return this.properties.hashCode();
-
-