public class Rating extends java.lang.Object
ETrafficLightColor
assigned to a file. The
rating can be stored in the file or externally. To protect the stored color,
it is protected by a hash sum over the file's content, i.e. if the file
changes this will be detected and result in a RED rating. There are some
exclusions when calculating the check sum to make it more stable with respect
to a versioning system or encoding problems.
While the typical application is to files (and their content), the actual implementation has no notion of a file and works on arbitrary strings.
A note on compatibility: Over time there were different versions of the rating algorithm.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
RATING_TAG
The rating tag used.
|
Constructor and Description |
---|
Rating(java.util.List<java.lang.String> lines)
Constructor.
|
Rating(java.util.List<java.lang.String> lines,
ETrafficLightColor forcedRating)
Constructor.
|
Rating(java.lang.String content)
Constructor.
|
Rating(java.lang.String content,
ETrafficLightColor forcedRating)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
constructRatingTag(ETrafficLightColor color,
java.lang.String hash)
Returns the rating tag starting with "@ConQAT.Rating" and containing
the color and hash values.
|
java.lang.String |
getExpectedHashString()
Returns the expected hash code as a string.
|
ETrafficLightColor |
getRating()
Returns the actual rating determined based on the stored value and a
comparison of hash codes.
|
ETrafficLightColor |
getStoredRating()
Returns the rating stored in the file (which may be null if no old rating
was found).
|
static java.lang.String |
updateRating(java.lang.String content,
ETrafficLightColor newColor)
Updates the first found rating tag of a given string with the new color
and returns the new content.
|
public static final java.lang.String RATING_TAG
public Rating(java.lang.String content)
public Rating(java.lang.String content, ETrafficLightColor forcedRating)
forcedRating
- if this is non-null, the rating of the file is overwritten by
this color. This is useful to calculate the expected hash
value for a given (new) color.public Rating(java.util.List<java.lang.String> lines)
public Rating(java.util.List<java.lang.String> lines, ETrafficLightColor forcedRating)
forcedRating
- if this is non-null, the rating of the file is overwritten by
this color. This is useful to calculate the expected hash
value for a given (new) color.public ETrafficLightColor getStoredRating()
public ETrafficLightColor getRating()
public java.lang.String getExpectedHashString()
public static java.lang.String updateRating(java.lang.String content, ETrafficLightColor newColor)
public static java.lang.String constructRatingTag(ETrafficLightColor color, java.lang.String hash)