Example usage for org.apache.commons.lang3 CharUtils toChar

List of usage examples for org.apache.commons.lang3 CharUtils toChar

Introduction

In this page you can find the example usage for org.apache.commons.lang3 CharUtils toChar.

Prototype

public static char toChar(final String str) 

Source Link

Document

Converts the String to a char using the first character, throwing an exception on empty Strings.

 CharUtils.toChar("A")  = 'A' CharUtils.toChar("BA") = 'B' CharUtils.toChar(null) throws IllegalArgumentException CharUtils.toChar("")   throws IllegalArgumentException 

Usage

From source file:com.tacitknowledge.flip.aspectj.converters.CharacterConverter.java

/** {@inheritDoc } */
public Object convert(String expression, Class outputClass) {
    return CharUtils.toChar(expression);
}

From source file:io.manasobi.utils.RandomUtils.java

/**
 *   ?? ? ??? ? ?? .<br>/*  w  ww. j  av  a 2s .c  om*/
 * ASCII CODE  startChar ?? endChar? ??.<br><br>
 *
 * RandomUtils.getString(10, 'B', 'r') = FoOXjRmmMr
 *
 * @param count ? ? ?
 * @param startChar  
 * @param endChar ?? 
 * @return   ?? ? ?
 */
public static String getString(int count, String startChar, String endChar) {

    int startInt = Integer.valueOf(CharUtils.toChar(startChar));
    int endInt = Integer.valueOf(CharUtils.toChar(endChar));

    int gap = endInt - startInt;
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < count; i++) {
        int chInt;
        do {
            chInt = GENERATOR.nextInt(gap + 1) + startInt;
        } while (!Character.toString((char) chInt).matches("^[a-zA-Z]$"));
        buf.append((char) chInt);
    }
    return buf.toString();
}

From source file:ch.cyberduck.core.Local.java

public Local(final String parent, final String name, final String delimiter) throws LocalAccessDeniedException {
    this(parent.endsWith(delimiter) ? String.format("%s%s", parent, name)
            : String.format("%s%c%s", parent, CharUtils.toChar(delimiter), name));
}

From source file:ch.cyberduck.core.Local.java

public Local(final Local parent, final String name, final String delimiter) throws LocalAccessDeniedException {
    this(parent.isRoot() ? String.format("%s%s", parent.getAbsolute(), name)
            : String.format("%s%c%s", parent.getAbsolute(), CharUtils.toChar(delimiter), name));
}

From source file:com.github.ithildir.airbot.service.impl.AirNowMeasurementServiceImpl.java

private void _initReportingAreaRecord(Buffer buffer) {
    String[] values = StringUtils.split(buffer.toString(), '|');

    char dataType = CharUtils.toChar(values[5]);

    if (dataType != 'O') {
        return;//from   w  ww.  j  a  va 2  s  .c o  m
    }

    boolean primary = BooleanUtils.toBoolean(values[6]);

    if (!primary) {
        return;
    }

    String stateCode = values[8];

    if (StringUtils.isBlank(stateCode)) {
        return;
    }

    long time = _parseTime(values[1], values[2], values[3]);
    String reportingArea = values[7];
    double latitude = Double.parseDouble(values[9]);
    double longitude = Double.parseDouble(values[10]);
    String mainPollutant = _parsePollutant(values[11]);
    int aqi = Integer.parseInt(values[12]);
    String comments = values[15];

    Location coordinates = new Location(latitude, longitude, "US");

    _reportingAreaCoordinates.put(reportingArea, coordinates);

    Measurement measurement = new Measurement(reportingArea, time, aqi, mainPollutant, Collections.emptyMap(),
            comments);

    _reportingAreaMeasurements.put(reportingArea, measurement);
}

From source file:ch.cyberduck.core.Local.java

@Override
public char getDelimiter() {
    return CharUtils.toChar(PreferencesFactory.get().getProperty("local.delimiter"));
}

From source file:com.pandich.dropwizard.curator.refresh.Refresher.java

protected final Object getValue(final A element, final NodeValue nodeValue) {
    final String rawValue = nodeValue.getValue();

    final Class<?> clazz = getType(element);

    final CuratorMapper<?> mapper = this.mappers.get(clazz);
    if (mapper != null) {
        return mapper.readValueFroMString(rawValue);
    }/*from   w w w .j a v a  2s.c  o m*/

    if (isAssignable(clazz, String.class)) {
        return rawValue;
    }

    if (isAssignable(clazz, Boolean.class)) {
        return Boolean.valueOf(rawValue);
    }

    if (isAssignable(clazz, Character.class)) {
        return CharUtils.toChar(rawValue);
    }

    if (isAssignable(clazz, Byte.class)) {
        return Byte.valueOf(rawValue);
    }

    if (isAssignable(clazz, Short.class)) {
        return Short.valueOf(rawValue);
    }

    if (isAssignable(clazz, Integer.class)) {
        return Integer.valueOf(rawValue);
    }

    if (isAssignable(clazz, Long.class)) {
        return Long.valueOf(rawValue);
    }

    if (isAssignable(clazz, Float.class)) {
        return Float.valueOf(rawValue);
    }

    if (isAssignable(clazz, Double.class)) {
        return Double.valueOf(rawValue);
    }

    if (isAssignable(clazz, BigInteger.class)) {
        return new BigInteger(rawValue);
    }

    if (isAssignable(clazz, BigDecimal.class)) {
        return new BigDecimal(rawValue);
    }

    try {
        return objectMapper.readValue(rawValue, clazz);
    } catch (IOException e) {
        throw new RuntimeException("type '" + clazz.getName() + "' is not supported", e);
    }
}

From source file:io.manasobi.utils.StringUtils.java

/**
 *  char? ?  ? ?? camel case  <br><br>
 *
 * StringUtils.convertToCamelCase("anyframe-java-test", "-") = "anyframeJavaTest"
 *
 * @param targetString ? ?/*from  ww w . j  a  v  a  2s  .com*/
 * @param posChar ?? ?  ?
 * @return camel case  ? ?
 */
public static String convertToCamelCase(String targetString, String posChar) {
    StringBuilder result = new StringBuilder();
    boolean nextUpper = false;
    String allLower = targetString.toLowerCase();

    for (int i = 0; i < allLower.length(); i++) {
        char currentChar = allLower.charAt(i);
        if (currentChar == CharUtils.toChar(posChar)) {
            nextUpper = true;
        } else {
            if (nextUpper) {
                currentChar = Character.toUpperCase(currentChar);
                nextUpper = false;
            }
            result.append(currentChar);
        }
    }
    return result.toString();
}

From source file:org.blocks4j.reconf.client.constructors.SimpleConstructor.java

public Object construct(MethodData data) throws Throwable {
    Class<?> returnClass = (Class<?>) data.getReturnType();

    String trimmed = StringUtils.defaultString(StringUtils.trim(data.getValue()));
    if (!trimmed.startsWith("'") || !trimmed.endsWith("'")) {
        throw new RuntimeException(msg.format("error.invalid.string", data.getValue(), data.getMethod()));
    }/*w  w w.ja v a2 s . c om*/

    String wholeValue = StringUtils.substring(trimmed, 1, trimmed.length() - 1);

    if (String.class.equals(returnClass)) {
        return wholeValue;
    }

    if (null == data.getValue()) {
        return null;
    }

    if (Object.class.equals(returnClass)) {
        returnClass = String.class;
    }

    if (char.class.equals(data.getReturnType()) || Character.class.equals(data.getReturnType())) {
        if (StringUtils.length(wholeValue) == 1) {
            return CharUtils.toChar(wholeValue);
        }
        return CharUtils.toChar(StringUtils.replace(wholeValue, " ", ""));
    }

    if (primitiveBoxing.containsKey(returnClass)) {
        if (StringUtils.isBlank(wholeValue)) {
            return null;
        }
        Method parser = primitiveBoxing.get(returnClass).getMethod(
                "parse" + StringUtils.capitalize(returnClass.getSimpleName()), new Class<?>[] { String.class });
        return parser.invoke(primitiveBoxing.get(returnClass), new Object[] { StringUtils.trim(wholeValue) });
    }

    Method valueOf = null;
    try {
        valueOf = returnClass.getMethod("valueOf", new Class<?>[] { String.class });
    } catch (NoSuchMethodException ignored) {
    }

    if (valueOf == null) {
        try {

            valueOf = returnClass.getMethod("valueOf", new Class<?>[] { Object.class });
        } catch (NoSuchMethodException ignored) {
        }
    }

    if (null != valueOf) {
        if (StringUtils.isEmpty(wholeValue)) {
            return null;
        }
        return valueOf.invoke(data.getReturnType(), new Object[] { StringUtils.trim(wholeValue) });
    }

    Constructor<?> constructor = null;

    try {
        constructor = returnClass.getConstructor(String.class);
        constructor.setAccessible(true);

    } catch (NoSuchMethodException ignored) {
        throw new IllegalStateException(
                msg.format("error.string.constructor", returnClass.getSimpleName(), data.getMethod()));
    }

    try {
        return constructor.newInstance(wholeValue);

    } catch (Exception e) {
        if (e.getCause() != null && e.getCause() instanceof NumberFormatException) {
            return constructor.newInstance(StringUtils.trim(wholeValue));
        }
        throw e;
    }
}

From source file:org.cryptomator.frontend.webdav.mount.WindowsWebDavMounter.java

@Override
public WebDavMount mount(URI uri, Map<MountParam, Optional<String>> mountParams) throws CommandFailedException {
    final String driveLetter = mountParams.getOrDefault(MountParam.WIN_DRIVE_LETTER, Optional.empty())
            .orElse(AUTO_ASSIGN_DRIVE_LETTER);
    if (driveLetters.getOccupiedDriveLetters().contains(CharUtils.toChar(driveLetter))) {
        throw new CommandFailedException("Drive letter occupied.");
    }//from   ww w .  j  a v a 2 s. c  om

    final String hostname = mountParams.getOrDefault(MountParam.HOSTNAME, Optional.empty()).orElse(LOCALHOST);
    try {
        final URI adjustedUri = new URI(uri.getScheme(), uri.getUserInfo(), hostname, uri.getPort(),
                uri.getPath(), uri.getQuery(), uri.getFragment());
        CommandResult mountResult = mount(adjustedUri, driveLetter);
        return new WindowsWebDavMount(
                AUTO_ASSIGN_DRIVE_LETTER.equals(driveLetter) ? getDriveLetter(mountResult.getStdOut())
                        : driveLetter);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Invalid host: " + hostname);
    }
}