/** * Returns the Result for the given string. * <p> * The {@code name} is converted internally to upper case with the {@linkplain Locale#ENGLISH ENGLISH} locale to * avoid problems on the Turkish locale. Do not use with Turkish enum values. * </p> * * @param enumType The Class of the enum. * @param name The enum name, case-insensitive. If null, returns {@code defaultValue}. * @param <T> The type of the enum. * @return an enum value or null if {@code name} is null. */ public static <T extends Enum<T>> T valueOf(final Class<T> enumType, final String name) { return valueOf(enumType, name, null); }
/** * Formats the Structured data as described in <a href="https://tools.ietf.org/html/rfc5424">RFC 5424</a>. * * @param format The format identifier. * @return The formatted String. */ public String asString(final String format) { try { return format(EnglishEnums.valueOf(MapFormat.class, format), new StringBuilder()).toString(); } catch (final IllegalArgumentException ex) { return asString(); } }
/** * Formats the structured data as described in RFC 5424. * * @param format The format identifier. Ignored in this implementation. * @return The formatted String. */ @Override public String asString(final String format) { try { return asString(EnglishEnums.valueOf(Format.class, format), null); } catch (final IllegalArgumentException ex) { return asString(); } }
protected Builder newSyslogAppenderBuilder(final String protocol, final String format, final boolean newLine) { // @formatter:off return SyslogAppender.newSyslogAppenderBuilder() .withPort(PORTNUM) .withProtocol(EnglishEnums.valueOf(Protocol.class, protocol)) .withReconnectDelayMillis(-1) .withName("TestApp") .withIgnoreExceptions(false) .setId("Audit") .setEnterpriseNumber(18060) .setMdcId("RequestContext") .setNewLine(newLine) .setAppName("TestApp") .setMsgId("Test") .setFormat(format); // @formatter:on } }
@Override public E convert(final String s) { return EnglishEnums.valueOf(clazz, s); } }
/** * Returns the Result for the given string. * * @param name The Result enum name, case-insensitive. If null, returns, defaultResult * @param defaultResult the Result to return if name is null * @return a Result enum value or null if name is null */ public static Result toResult(final String name, final Result defaultResult) { return EnglishEnums.valueOf(Result.class, name, defaultResult); } }
/** * Returns the Facility for the given string. * * @param name The Facility enum name, case-insensitive. If null, returns, defaultFacility * @param defaultFacility the Facility to return if name is null * @return a Facility enum value or null if name is null */ public static Facility toFacility(final String name, final Facility defaultFacility) { return EnglishEnums.valueOf(Facility.class, name, defaultFacility); }
/** * Returns the Result for the given string. * <p> * The {@code name} is converted internally to upper case with the {@linkplain Locale#ENGLISH ENGLISH} locale to * avoid problems on the Turkish locale. Do not use with Turkish enum values. * </p> * * @param enumType The Class of the enum. * @param name The enum name, case-insensitive. If null, returns {@code defaultValue}. * @param <T> The type of the enum. * @return an enum value or null if {@code name} is null. */ public static <T extends Enum<T>> T valueOf(final Class<T> enumType, final String name) { return valueOf(enumType, name, null); }
/** * Formats the Structured data as described in <a href="https://tools.ietf.org/html/rfc5424">RFC 5424</a>. * * @param format The format identifier. * @return The formatted String. */ public String asString(final String format) { try { return format(EnglishEnums.valueOf(MapFormat.class, format), new StringBuilder()).toString(); } catch (final IllegalArgumentException ex) { return asString(); } }
/** * Formats the structured data as described in RFC 5424. * * @param format The format identifier. Ignored in this implementation. * @return The formatted String. */ @Override public String asString(final String format) { try { return asString(EnglishEnums.valueOf(Format.class, format), null); } catch (final IllegalArgumentException ex) { return asString(); } }
/** * Creates an EncodingPatternConverter using a pattern string and an optional escape format. * * @param config the current Configuration * @param options first option is the nested pattern format; second option is the escape format (optional) * @return instance of pattern converter. */ public static EncodingPatternConverter newInstance(final Configuration config, final String[] options) { if (options.length > 2 || options.length == 0) { LOGGER.error("Incorrect number of options on escape. Expected 1 or 2, but received {}", options.length); return null; } if (options[0] == null) { LOGGER.error("No pattern supplied on escape"); return null; } final EscapeFormat escapeFormat = options.length < 2 ? EscapeFormat.HTML : EnglishEnums.valueOf(EscapeFormat.class, options[1], EscapeFormat.HTML); final PatternParser parser = PatternLayout.createPatternParser(config); final List<PatternFormatter> formatters = parser.parse(options[0]); return new EncodingPatternConverter(formatters, escapeFormat); }
/** * Creates an ANSI escape sequence from the given {@linkplain AnsiEscape} names. * * @param names * {@linkplain AnsiEscape} names. * @return An ANSI escape sequence. */ public static String createSequence(final String... names) { if (names == null) { return getDefaultStyle(); } final StringBuilder sb = new StringBuilder(AnsiEscape.CSI.getCode()); boolean first = true; for (final String name : names) { try { final AnsiEscape escape = EnglishEnums.valueOf(AnsiEscape.class, name.trim()); if (!first) { sb.append(AnsiEscape.SEPARATOR.getCode()); } first = false; sb.append(escape.getCode()); } catch (final Exception ex) { // Ignore the error. } } sb.append(AnsiEscape.SUFFIX.getCode()); return sb.toString(); }
.withHost(host) .withPort(port) .withProtocol(EnglishEnums.valueOf(Protocol.class, protocolStr)) .withSslConfiguration(sslConfiguration) .withConnectTimeoutMillis(connectTimeoutMillis)