com.ingenico.connect.gateway.sdk.java.logging.Obfuscator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connect-sdk-java Show documentation
Show all versions of connect-sdk-java Show documentation
SDK to communicate with the Ingenico ePayments platform using the Ingenico Connect Server API
package com.ingenico.connect.gateway.sdk.java.logging;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
abstract class Obfuscator {
private final Map obfuscators;
Obfuscator(Map obfuscators, boolean caseInsensitive) {
this.obfuscators = copy(obfuscators, caseInsensitive);
}
private Map copy(Map obfuscators, boolean caseInsensitive) {
Map copy;
if (caseInsensitive) {
copy = new TreeMap(String.CASE_INSENSITIVE_ORDER);
copy.putAll(obfuscators);
} else {
copy = new LinkedHashMap(obfuscators);
}
return Collections.unmodifiableMap(copy);
}
String obfuscateValue(String key, String value) {
ValueObfuscator obfuscator = obfuscators.get(key);
return obfuscator != null ? obfuscator.obfuscateValue(value) : value;
}
abstract static class Builder {
private final Map obfuscators = new LinkedHashMap();
Builder() {}
Builder withAll(String key) {
obfuscators.put(key, ValueObfuscator.ALL);
return this;
}
Builder withFixedLength(String key, int fixedLength) {
obfuscators.put(key, ValueObfuscator.fixedLength(fixedLength));
return this;
}
Builder withKeepStartCount(String key, int count) {
obfuscators.put(key, ValueObfuscator.keepStartCount(count));
return this;
}
Builder withKeepEndCount(String key, int count) {
obfuscators.put(key, ValueObfuscator.keepEndCount(count));
return this;
}
Map getObfuscators() {
return obfuscators;
}
abstract Obfuscator build();
}
}