Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ public static TSEncodingBuilder getConverter(TSEncoding type) {
}
}

protected boolean isKeyContainedInMap(Map<String, String> map, String key) {
if(map == null || key == null) {
return false;
}
for(String keyInMap : map.keySet()) {
if(key.equalsIgnoreCase(keyInMap)) {
return true;
}
}
return false;
}

/**
* return a series's encoder with different types and parameters according to its measurement id
* and data type.
Expand Down Expand Up @@ -149,15 +161,18 @@ public Encoder getEncoder(TSDataType type) {
@Override
public void initFromProps(Map<String, String> props) {
// set max error from initialized map or default value if not set
if (props == null || !props.containsKey(Encoder.MAX_POINT_NUMBER)) {
if (!isKeyContainedInMap(props, Encoder.MAX_POINT_NUMBER)) {
maxPointNumber = TSFileConfig.floatPrecision;
} else {
maxPointNumber = Integer.valueOf(props.get(Encoder.MAX_POINT_NUMBER));
if (maxPointNumber < 0) {
maxPointNumber = TSFileConfig.floatPrecision;
LOGGER
.warn("cannot set max point number to negative value, replaced with default value:{}",
maxPointNumber);
for(Map.Entry<String, String> entry : props.entrySet()) {
if(Encoder.MAX_POINT_NUMBER.equalsIgnoreCase(entry.getKey())) {
maxPointNumber = Integer.valueOf(entry.getValue());
if (maxPointNumber < 0) {
maxPointNumber = TSFileConfig.floatPrecision;
LOGGER.warn("cannot set max point number to negative value, replaced with default value:{}",
maxPointNumber);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the else block is just enough and the if block is redundant.
You may set maxPointNumber = TSFileConfig.floatPrecision first and then go through the loop for(Map.Entry<String, String> entry : props.entrySet()) .

}
}
}
Expand Down Expand Up @@ -197,15 +212,18 @@ public Encoder getEncoder(TSDataType type) {
*/
public void initFromProps(Map<String, String> props) {
// set max error from initialized map or default value if not set
if (props == null || !props.containsKey(Encoder.MAX_POINT_NUMBER)) {
if (!isKeyContainedInMap(props, Encoder.MAX_POINT_NUMBER)) {
maxPointNumber = TSFileConfig.floatPrecision;
} else {
maxPointNumber = Integer.valueOf(props.get(Encoder.MAX_POINT_NUMBER));
if (maxPointNumber < 0) {
maxPointNumber = TSFileConfig.floatPrecision;
LOGGER
.warn("cannot set max point number to negative value, replaced with default value:{}",
maxPointNumber);
for(Map.Entry<String, String> entry : props.entrySet()) {
if(Encoder.MAX_POINT_NUMBER.equalsIgnoreCase(entry.getKey())) {
maxPointNumber = Integer.valueOf(entry.getValue());
if (maxPointNumber < 0) {
maxPointNumber = TSFileConfig.floatPrecision;
LOGGER.warn("cannot set max point number to negative value, replaced with default value:{}",
maxPointNumber);
}
}
}
}
}
Expand Down