Example usage for java.lang Character toUpperCase

List of usage examples for java.lang Character toUpperCase

Introduction

In this page you can find the example usage for java.lang Character toUpperCase.

Prototype

public static int toUpperCase(int codePoint) 

Source Link

Document

Converts the character (Unicode code point) argument to uppercase using case mapping information from the UnicodeData file.

Usage

From source file:net.ae97.pokebot.extensions.scrolls.ScrollCommand.java

@Override
public void runEvent(CommandEvent event) {
    if (event.getArgs().length == 0) {
        event.respond("Usage: .scroll [name]");
        return;//from  ww w.j  a  v a  2  s  .  c o  m
    }
    try {
        URL playerURL = new URL(url.replace("{name}", StringUtils.join(event.getArgs(), "%20")));
        List<String> lines = new LinkedList<>();
        HttpURLConnection conn = (HttpURLConnection) playerURL.openConnection();
        conn.setRequestProperty("User-Agent", "PokeBot - " + PokeBot.VERSION);
        conn.connect();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
        }

        JsonParser parser = new JsonParser();
        JsonElement element = parser.parse(StringUtils.join(lines, "\n"));
        JsonObject obj = element.getAsJsonObject();

        String result = obj.get("msg").getAsString();
        if (!result.equalsIgnoreCase("success")) {
            event.respond("Scroll not found");
            return;
        }
        JsonObject dataObject = obj.get("data").getAsJsonArray().get(0).getAsJsonObject();

        StringBuilder builder = new StringBuilder();

        builder.append(dataObject.get("name").getAsString()).append(" - ");
        builder.append("Cost: ");
        if (dataObject.get("costgrowth").getAsInt() > 0) {
            builder.append(dataObject.get("costgrowth").getAsInt()).append(" Growth");
        } else if (dataObject.get("costorder").getAsInt() > 0) {
            builder.append(dataObject.get("costorder").getAsInt()).append(" Order");
        } else if (dataObject.get("costenergy").getAsInt() > 0) {
            builder.append(dataObject.get("costenergy").getAsInt()).append(" Energy");
        } else if (dataObject.get("costdecay").getAsInt() > 0) {
            builder.append(dataObject.get("costdecay").getAsInt()).append(" Decay");
        } else {
            builder.append("0");
        }
        builder.append(" - ");
        String kind = dataObject.get("kind").getAsString();
        kind = Character.toUpperCase(kind.charAt(0)) + kind.substring(1).toLowerCase();
        builder.append("Kind: ").append(kind).append(" - ");
        Rarity rarity = Rarity.get(dataObject.get("rarity").getAsInt());
        String rarityString = rarity.name().toLowerCase();
        rarityString = Character.toUpperCase(rarityString.charAt(0)) + rarityString.substring(1);
        builder.append("Rarity: ").append(rarityString);

        if (kind.equalsIgnoreCase("creature") || kind.equalsIgnoreCase("structure")) {
            builder.append(" - ");
            builder.append("Types: ").append(dataObject.get("types").getAsString()).append(" - ");
            builder.append("Attack: ").append(dataObject.get("ap").getAsInt()).append(" - ");
            builder.append("Cooldown: ").append(dataObject.get("ac").getAsInt()).append(" - ");
            builder.append("Health: ").append(dataObject.get("hp").getAsInt());
        }

        builder.append("\n");
        builder.append("Description: '").append(dataObject.get("description").getAsString()).append("' - ");
        builder.append("Flavor: '").append(dataObject.get("flavor").getAsString()).append("'");

        String[] message = builder.toString().split("\n");
        for (String msg : message) {
            event.respond("" + msg);
        }

    } catch (IOException | JsonSyntaxException | IllegalStateException ex) {
        PokeBot.getLogger().log(Level.SEVERE,
                "Error on getting scroll for Scrolls for '" + StringUtils.join(event.getArgs(), " ") + "'", ex);
        event.respond("Error on getting scroll: " + ex.getLocalizedMessage());
    }
}

From source file:com.opencsv.bean.AbstractBeanField.java

/**
 * Assigns the given object to this field of the destination bean.
 * Uses a custom setter method if available.
 *
 * @param <T>  Type of the bean//from w  w  w.  ja v a2 s  .  c o  m
 * @param bean The bean in which the field is located
 * @param obj  The data to be assigned to this field of the destination bean
 * @throws CsvDataTypeMismatchException If the data to be assigned cannot
 *                                      be converted to the type of the destination field
 */
private <T> void assignValueToField(T bean, Object obj) throws CsvDataTypeMismatchException {

    // obj == null means that the source field was empty. Then we simply
    // leave the field as it was initialized by the VM. For primitives,
    // that will be values like 0, and for objects it will be null.
    if (obj != null) {
        Class<?> fieldType = field.getType();

        // Find and use a setter method if one is available.
        String setterName = "set" + Character.toUpperCase(field.getName().charAt(0))
                + field.getName().substring(1);
        try {
            Method setterMethod = bean.getClass().getMethod(setterName, fieldType);
            try {
                setterMethod.invoke(bean, obj);
            } catch (IllegalAccessException e) {
                // Can't happen, because we've already established that the
                // method is public through the use of getMethod().
            } catch (InvocationTargetException e) {
                CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(obj, fieldType,
                        e.getLocalizedMessage());
                csve.initCause(e);
                throw csve;
            }
        } catch (NoSuchMethodException e1) {
            // Replace with a multi-catch as soon as we support Java 7
            // Otherwise set the field directly.
            writeWithoutSetter(bean, obj);
        } catch (SecurityException e1) {
            // Otherwise set the field directly.
            writeWithoutSetter(bean, obj);
        }
    }
}

From source file:com.redhat.rhn.common.util.StringUtil.java

/**
 * Convert the passed in string to a valid java method name. This basically
 * capitalizes each word and removes all word delimiters.
 * @param strIn The string to convert//  w  w w .j av  a  2 s . co m
 * @return The converted string
 */
public static String beanify(String strIn) {
    String str = strIn.trim();
    StringBuilder result = new StringBuilder(str.length());
    boolean wasWhitespace = false;

    for (int i = 0, j = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (Character.isLetterOrDigit(c)) {
            if (wasWhitespace) {
                c = Character.toUpperCase(c);
                wasWhitespace = false;
            }
            result.insert(j, c);
            j++;
            continue;
        }
        wasWhitespace = true;
    }
    return result.toString();
}

From source file:com.anrisoftware.globalpom.reflection.beans.BeanAccessImpl.java

private String getSetterName(String name) {
    StringBuilder builder = new StringBuilder();
    char nameChar = Character.toUpperCase(name.charAt(0));
    builder.append(SETTER_PREFIX);/*from   ww  w  .  ja  v  a  2s.  com*/
    builder.append(nameChar);
    builder.append(name.substring(1));
    return builder.toString();
}

From source file:com.softmotions.commons.bean.BeanUtils.java

/**
 * Gets a property from the given bean./*from  ww w.  j  a  va2  s  .  c  o m*/
 *
 * @param bean         The bean to read property from.
 * @param propertyName The name of the property to read.
 * @param lenient      If true is passed for this attribute, null will returned for
 *                     in case no matching getter method is defined, else an Exception will be throw
 *                     in this case.
 * @return The determined value.
 * @throws BeanException In case the bean access failed.
 */
public static Object getProperty(Object bean, String propertyName, boolean lenient) throws BeanException {

    try {
        // getting property object from bean using "getNnnn", where nnnn is parameter name
        Method getterMethod = null;
        try {
            // first trying form getPropertyNaae for regular value
            String getterName = "get" + Character.toUpperCase(propertyName.charAt(0))
                    + propertyName.substring(1);
            Class paramClass = bean.getClass();
            getterMethod = paramClass.getMethod(getterName, GETTER_ARG_TYPES);
        } catch (NoSuchMethodException ignored) {
            // next trying isPropertyNaae for possible boolean
            String getterName = "is" + Character.toUpperCase(propertyName.charAt(0))
                    + propertyName.substring(1);
            Class paramClass = bean.getClass();
            getterMethod = paramClass.getMethod(getterName, GETTER_ARG_TYPES);
        }
        return getterMethod.invoke(bean, GETTER_ARGS);
    } catch (NoSuchMethodError ex) {
        if (!lenient) {
            throw new BeanException("Property '" + propertyName + "' is undefined for given bean from class "
                    + bean.getClass().getName() + ".", ex);
        }
    } catch (NoSuchMethodException ignored) {
        if (!lenient) {
            throw new BeanException("Property '" + propertyName + "' is undefined for given bean from class "
                    + bean.getClass().getName() + ".");
        }
    } catch (InvocationTargetException ex) {
        throw new BeanException("Property '" + propertyName
                + "' could not be evaluated for given bean from class " + bean.getClass().getName() + ".", ex);
    } catch (IllegalAccessException ex) {
        throw new BeanException("Property '" + propertyName
                + "' could not be accessed for given bean from class " + bean.getClass().getName() + ".", ex);
    }
    return null;
}

From source file:DateTime.java

/**
 * Parses an RFC 3339 date/time value.//from  w  ww.  j  av a 2 s  .c  o m
 */
public static DateTime parseRfc3339(String str) throws NumberFormatException {
    try {
        Calendar dateTime = new GregorianCalendar(GMT);
        int year = Integer.parseInt(str.substring(0, 4));
        int month = Integer.parseInt(str.substring(5, 7)) - 1;
        int day = Integer.parseInt(str.substring(8, 10));
        int tzIndex;
        int length = str.length();
        boolean dateOnly = length <= 10 || Character.toUpperCase(str.charAt(10)) != 'T';
        if (dateOnly) {
            dateTime.set(year, month, day);
            tzIndex = 10;
        } else {
            int hourOfDay = Integer.parseInt(str.substring(11, 13));
            int minute = Integer.parseInt(str.substring(14, 16));
            int second = Integer.parseInt(str.substring(17, 19));
            dateTime.set(year, month, day, hourOfDay, minute, second);
            if (str.charAt(19) == '.') {
                int milliseconds = Integer.parseInt(str.substring(20, 23));
                dateTime.set(Calendar.MILLISECOND, milliseconds);
                tzIndex = 23;
            } else {
                tzIndex = 19;
            }
        }
        Integer tzShiftInteger = null;
        long value = dateTime.getTimeInMillis();
        if (length > tzIndex) {
            int tzShift;
            if (Character.toUpperCase(str.charAt(tzIndex)) == 'Z') {
                tzShift = 0;
            } else {
                tzShift = Integer.parseInt(str.substring(tzIndex + 1, tzIndex + 3)) * 60
                        + Integer.parseInt(str.substring(tzIndex + 4, tzIndex + 6));
                if (str.charAt(tzIndex) == '-') {
                    tzShift = -tzShift;
                }
                value -= tzShift * 60000;
            }
            tzShiftInteger = tzShift;
        }
        return new DateTime(dateOnly, value, tzShiftInteger);
    } catch (StringIndexOutOfBoundsException e) {
        throw new NumberFormatException("Invalid date/time format.");
    }
}

From source file:com.emc.ecs.sync.config.ConfigUtil.java

public static String labelize(String name) {
    StringBuilder label = new StringBuilder();
    for (char c : name.toCharArray()) {
        if (Character.isUpperCase(c) && label.length() > 0)
            label.append(' ');
        label.append(label.length() == 0 ? Character.toUpperCase(c) : c);
    }/*  w w w.  j  ava2  s.  c o  m*/
    return label.toString();
}

From source file:com.xpn.xwiki.plugin.charts.ChartingPlugin.java

public Chart generateChart(ChartParams params, XWikiContext context) throws GenerateException {
    try {/*from w  w w  . j  av a2s. co m*/
        // Obtain the corresponding data source and wrap it into a data source object
        DataSource dataSource = MainDataSourceFactory.getInstance().create(params.getMap(ChartParams.SOURCE),
                context);

        String type = params.getString(ChartParams.TYPE);

        Plot plot;
        try {
            String factoryClassName = ChartingPlugin.class.getPackage().getName() + ".plots."
                    + Character.toUpperCase(type.charAt(0)) + type.toLowerCase().substring(1) + "PlotFactory";

            Class factoryClass = Class.forName(factoryClassName);
            Method method = factoryClass.getMethod("getInstance", new Class[] {});
            PlotFactory factory = (PlotFactory) method.invoke(null, new Object[] {});

            plot = factory.create(dataSource, params);
        } catch (InvocationTargetException e) {
            throw new GenerateException(e.getTargetException());
        } catch (Throwable e) {
            throw new GenerateException(e);
        }

        ChartCustomizer.customizePlot(plot, params);

        JFreeChart jfchart = new JFreeChart(plot);

        ChartCustomizer.customizeChart(jfchart, params);

        return generatePngChart(jfchart, params, context);
    } catch (IOException ioe) {
        throw new GenerateException(ioe);
    } catch (DataSourceException dse) {
        throw new GenerateException(dse);
    }
}

From source file:de.vandermeer.asciithemes.a7.dropcaps.FigletOldBanner_6L.java

@Override
public String[] getDropCap(char letter) {
    return this.map.get(Character.toUpperCase(letter));
}

From source file:ar.com.fdvs.dj.domain.builders.ReflectiveReportBuilder.java

/**
 * Calculates a column title using camel humps to separate words.
 * @param _property the property descriptor.
 * @return the column title for the given property.
 *///  ww  w .  j  a  v a 2  s. c om
private static String getColumnTitle(final PropertyDescriptor _property) {
    final StringBuffer buffer = new StringBuffer();
    final String name = _property.getName();
    buffer.append(Character.toUpperCase(name.charAt(0)));
    for (int i = 1; i < name.length(); i++) {
        final char c = name.charAt(i);
        if (Character.isUpperCase(c)) {
            buffer.append(' ');
        }
        buffer.append(c);
    }
    return buffer.toString();
}