forked from I2P_Developers/i2p.i2p
Includes mods to use org.json.simple package. See licenses/LICENSE-Apache2.0.txt Includes jBCrypt: Copyright (c) 2006 Damien Miller <djm@mindrot.org> See licenses/LICENSE-jBCrypt.txt Includes jsonrpc2 libs: See licenses/LICENSE-Apache2.0.txt http://software.dzhuvinov.com/json-rpc-2.0-server.html Jars from maven central: jsonrpc2-base-1.38.1-sources.jar 22-Oct-2017 jsonrpc2-server-1.11-sources.jar 16-Mar-2015
81 lines
1.9 KiB
Java
81 lines
1.9 KiB
Java
package com.thetransactioncompany.jsonrpc2.util;
|
|
|
|
|
|
/**
|
|
* The base abstract class for the JSON-RPC 2.0 parameter retrievers.
|
|
*
|
|
* @author Vladimir Dzhuvinov
|
|
*/
|
|
public abstract class ParamsRetriever {
|
|
|
|
|
|
/**
|
|
* Returns the parameter count.
|
|
*
|
|
* @return The parameters count.
|
|
*/
|
|
public abstract int size();
|
|
|
|
|
|
/**
|
|
* Matches a string against an array of acceptable values.
|
|
*
|
|
* @param input The string to match.
|
|
* @param enumStrings The acceptable string values. Must not be
|
|
* {@code null}.
|
|
* @param ignoreCase {@code true} for a case insensitive match.
|
|
*
|
|
* @return The matching string value, {@code null} if no match was
|
|
* found.
|
|
*/
|
|
protected static String getEnumStringMatch(final String input,
|
|
final String[] enumStrings,
|
|
final boolean ignoreCase) {
|
|
|
|
for (final String en: enumStrings) {
|
|
|
|
if (ignoreCase) {
|
|
if (en.equalsIgnoreCase(input))
|
|
return en;
|
|
}
|
|
else {
|
|
if (en.equals(input))
|
|
return en;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
/**
|
|
* Matches a string against an enumeration of acceptable values.
|
|
*
|
|
* @param input The string to match.
|
|
* @param enumClass The enumeration class specifying the acceptable
|
|
* string values. Must not be {@code null}.
|
|
* @param ignoreCase {@code true} for a case insensitive match.
|
|
*
|
|
* @return The matching enumeration constant, {@code null} if no match
|
|
* was found.
|
|
*/
|
|
protected static <T extends Enum<T>> T getEnumStringMatch(final String input,
|
|
final Class<T> enumClass,
|
|
final boolean ignoreCase) {
|
|
|
|
for (T en: enumClass.getEnumConstants()) {
|
|
|
|
if (ignoreCase) {
|
|
if (en.toString().equalsIgnoreCase(input))
|
|
return en;
|
|
}
|
|
else {
|
|
if (en.toString().equals(input))
|
|
return en;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|