
br.com.moip.helpers.PayloadFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-java Show documentation
Show all versions of sdk-java Show documentation
Java SDK for Moip APIs integration
The newest version!
package br.com.moip.helpers;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class PayloadFactory {
/**
* This method was created to simplify the construction of request payloads. However, the use of this method
* shouldn't be compulsory and you can also use plain old Maps.
*
* @param entries
* {@code Map.Entry} the entries that will describe the request payload.
*
* @return {@code Map}
*/
@SafeVarargs
public static Map payloadFactory(Map.Entry... entries) {
Map map = new HashMap<>();
for (Map.Entry entry : entries)
map.put(entry.getKey(), entry.getValue());
return Collections.unmodifiableMap(map);
}
/**
* This is a auxiliary method used to load the {@code Map} returned from {@code payloadFactory}. The usage
* is similar to {@code Map} interaction, but its simplify the dynamic usage of {@code payloadFactory}.
*
* @param key
* {@code String} the attribute key.
*
* @param value
* {@code Object} the attribute value.
*
* @return {@code Map.Entry}
*/
public static Map.Entry value(String key, Object value) {
return new AbstractMap.SimpleImmutableEntry<>(key, value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy