public class CommentedProperties extends Object
## General comment line 1 ## General comment line 2 ##!General comment line 3, is ignored and not loaded ## General comment line 4 # Property A comment line 1 A=1 # Property B comment line 1 # Property B comment line 2 B=2 ! Property C comment line 1 ! Property C comment line 2 C=3 D=4 # Property E comment line 1 ! Property E comment line 2 E=5 # Property F comment line 1 #!Property F comment line 2, is ignored and not loaded ! Property F comment line 3 F=5
Constructor and Description |
---|
CommentedProperties()
Constructor
|
CommentedProperties(Properties properties)
Constructor with preset comments, not comments is set.
|
Modifier and Type | Method and Description |
---|---|
void |
appendPropertiesComment(String comment)
Appends a comment to the properties comment with a new line a front.
Will only add the line if it is not null . |
void |
appendPropertyComment(String key,
String comment)
Appends a comment to the property comment with a new line a front.
Will only add the line if it is not null . |
Properties |
getProperties()
Gets the properties loaded.
|
List<String> |
getPropertiesComment()
Gets the general properties comments as a list og strings.
|
String |
getPropertiesCommentAsString()
Gets the general properties comments as a string Concatinated with a new line '\n'
|
int |
getPropertiesWithCommentCount()
Gets the number of properties with a comment attached.
|
List<String> |
getPropertyComment(String key)
Gets the comment for a property as a list of strings.
|
String |
getPropertyCommentAsString(String key)
Gets the comment for a property as a string Concatinated with a new line '\n'
|
Iterator<String> |
getPropertyNames()
Gets a iterator with all the property keys.
|
List<String> |
getPropertyNamesAsList()
Get a list of all property keys as a sorted unmodifiable list.
|
String |
getPropertyValue(String key)
Gets the value for a property.
|
boolean |
hasPropertiesCommment()
If there any general properties comment.
|
boolean |
hasPropertyComment(String key)
If there a comment to a given property.
|
void |
load(File file)
Loads the properties and comments from a file.
All entries are reset when loading a new file. |
void |
load(String text)
Loads the properties and comments from a string.
All entries are reset when loading a new file. |
void |
setPropertiesComment(String comment)
Set the general properties comment.
The string will be split in lines for each new line. |
void |
setProperty(String key,
String value)
Sets a property value.
|
void |
setProperty(String key,
String value,
String comment)
Sets a property value and comment.
|
void |
setPropertyComment(String key,
String comment)
Sets a property comment.
The string will be split in lines for each new line. |
int |
size()
The number of properties.
|
void |
store(Writer writer)
Writes this property list (key and element pairs) and comments in this Properties table to the output character stream in a format suitable for using the load(Reader) method.
The writer is closed when done. |
public CommentedProperties()
public CommentedProperties(Properties properties)
properties
- the properties to use.public void load(File file) throws IOException
file
- the fileIOException
- if any IO exception.File
public void load(String text) throws IOException
text
- the text containing properties and comments.IOException
- if any IO exception.public void store(Writer writer) throws IOException
writer
- the writer instance.IOException
- if any IO exception.Writer
public Iterator<String> getPropertyNames()
public List<String> getPropertyNamesAsList()
public String getPropertyValue(String key)
key
- the property key.public List<String> getPropertyComment(String key)
key
- the property key.null
is returned.public String getPropertyCommentAsString(String key)
key
- the property key.null
is returned.public List<String> getPropertiesComment()
null
is returned.public String getPropertiesCommentAsString()
null
is returned.public boolean hasPropertiesCommment()
true
if the properties comment is not null
and not empty after trim, otherwise false
.public boolean hasPropertyComment(String key)
key
- the property key.true
if the property comment is not null
and not empty after trim, otherwise false
.public void setPropertiesComment(String comment)
comment
- the comment.public void appendPropertiesComment(String comment)
null
. If there is no current properties comment the line is just set with a new line.comment
- the comment to append.public void setPropertyComment(String key, String comment)
key
- the property key.comment
- the new property comment.public void appendPropertyComment(String key, String comment)
null
. If there is no current property comment the line is just set with a new line.key
- the property key.comment
- the comment to append.public void setProperty(String key, String value)
key
- the property key.value
- the new property value.public void setProperty(String key, String value, String comment)
key
- the property key.value
- the new property value.comment
- the new property comment.public int size()
public Properties getProperties()
public int getPropertiesWithCommentCount()