Files
i2p.i2p/apps/i2pcontrol/java/com/thetransactioncompany/jsonrpc2/util/ParamsRetriever.java
zzz d4caafb592 Bundle I2PControl 0.12, as a console webapp
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
2018-11-25 13:26:43 +00:00

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;
}
}