All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ingenico.connect.gateway.sdk.java.logging.Obfuscator Maven / Gradle / Ivy

Go to download

SDK to communicate with the Ingenico ePayments platform using the Ingenico Connect Server API

There is a newer version: 6.47.0
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy