Example usage for java.lang Character Character

List of usage examples for java.lang Character Character

Introduction

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

Prototype

@Deprecated(since = "9")
public Character(char value) 

Source Link

Document

Constructs a newly allocated Character object that represents the specified char value.

Usage

From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java

/** Gets default value.
 * @return default value.//from   www .  java  2 s .c  om
 */
public Object getDefaultValue() {
    if (defaultValue != null)
        return this.defaultValue;
    Class cls = getType();
    if (primitiveWrapperClass != null) {
        if (cls.equals(Boolean.TYPE))
            return new Boolean(false);
        else if (cls.equals(Byte.TYPE))
            return new Byte((byte) 0);
        else if (cls.equals(Character.TYPE))
            return new Character((char) 0);
        else if (cls.equals(Double.TYPE))
            return new Double((double) 0);
        else if (cls.equals(Float.TYPE))
            return new Float((float) 0);
        else if (cls.equals(Integer.TYPE))
            return new Integer((int) 0);
        else if (cls.equals(Long.TYPE))
            return new Long((long) 0);
        else if (cls.equals(Short.TYPE))
            return new Short((short) 0);
        else
            return null;
    } else
        return null;
}

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

/**
 * Finds end of URL.//from w  w  w .j  a  va 2  s .co  m
 * @param entireToken input String (URL)
 * @return position of last char of URL, returns -1 when entire String is URL
 */
private static int findEndOfUrl(String entireToken) {
    int space = entireToken.indexOf(' ');
    int line = entireToken.indexOf("<br/>");
    int tag = entireToken.indexOf("&lt;");
    int end = -1;

    // end characters
    Set<Character> endChars = new HashSet<Character>();
    endChars.add(new Character('.'));
    endChars.add(new Character(','));

    if (space == -1 || (space > line && line != -1)) {
        end = line;
    } else {
        end = space;
    }

    if (end == -1 || (end > tag && tag != -1)) {
        end = tag;
    }

    // dot before the end
    if (end > 0 && (endChars.contains(new Character(entireToken.charAt(end - 1))))) {
        end--;
    }
    // dot at the end
    else if (endChars.contains(new Character(entireToken.charAt(entireToken.length() - 1)))) {
        end = entireToken.length() - 1;
    }

    return end;
}

From source file:com.tc.object.ApplicatorDNAEncodingTest.java

public void testBasic() throws Exception {
    final TCByteBufferOutputStream output = new TCByteBufferOutputStream();

    final List<Object> data = new ArrayList<Object>();
    data.add(new ObjectID(1));
    data.add("one");
    data.add(new Boolean(true));
    data.add("two");
    data.add(new Byte((byte) 42));
    data.add("three");
    data.add(new Character('\t'));
    data.add("four");
    data.add(new Double(Math.PI));
    data.add("five");
    data.add(new Float(Math.E));
    data.add("six");
    data.add(new Integer(Integer.MAX_VALUE));
    data.add("seven");
    data.add(new Long(System.currentTimeMillis() % 17));
    data.add("eight");
    data.add(new Short((short) -1));

    final DNAEncoding encoding = getApplicatorEncoding();
    for (Object d : data) {
        encoding.encode(d, output);/*from  w  w w.j a v a  2 s  .c o  m*/
    }

    final TCByteBufferInputStream input = new TCByteBufferInputStream(output.toArray());
    for (Object orig : data) {
        final Object decoded = encoding.decode(input);

        assertEquals(orig, decoded);
    }

    assertEquals(0, input.available());
}

From source file:org.dragonet.net.translator.Translator_v0_11.java

public void processCrafting(WindowSetSlotPacket packet) {
    if (!(this.getSession().getPlayer() instanceof Player)) {
        return;//  ww w  . jav a2 s .c  om
    }
    int realSlot = 0;
    if (packet.slot < 27) {
        realSlot = packet.slot + 9;
    } else if (packet.slot >= 27) {
        realSlot = packet.slot - 27;
    }
    ItemStack item = this.getSession().getPlayer().getInventory().getItem(realSlot);
    if (item == null) {
        item = new ItemStack(Material.AIR);
    } else if (item.getAmount() <= 0) {
        this.getSession().getPlayer().getInventory().setItem(realSlot, null);
        return;
    }
    System.out.println(
            "FROM " + item.toString() + "to (ITEM=" + packet.item.id + ",CNT=" + packet.item.count + ")");
    if (packet.item.count < 0) {
        this.getSession().sendInventory();
        return;
    }
    if (item.getTypeId() == 0 && packet.item.id == 0) {
        this.getSession().sendInventory();
        return; //No changes
    }
    if (item.getTypeId() == packet.item.id && item.getAmount() == packet.item.count
            && item.getDurability() == packet.item.meta) {
        this.getSession().sendInventory();
        return; //No changes
    }
    if ((item.getTypeId() != 0 && packet.item.id == 0)
            || (item.getTypeId() != 0 && (item.getTypeId() != packet.item.id))
            || (item.getAmount() > (packet.item.count & 0xFF))) {
        this.getSession().sendInventory();
        return; //Decreasing item, ignore
    }
    int amount = packet.item.count - (item.getTypeId() == 0 ? 0 : item.getAmount());
    ItemStack result = new ItemStack(packet.item.id, amount, packet.item.meta);
    List<Recipe> recipes = this.getSession().getServer().getCraftingManager().getRecipesFor(result);
    if (recipes.size() <= 0) {
        return;
    }
    //System.out.println("CRAFTING FOR: " + result.toString() + ", recipes count: " + recipes.size());
    if (packet.windowID == PEWindowConstantID.PLAYER_INVENTORY && recipes.size() > 4) {
        //Can not craft more than 4 recipes in a player inventory
        this.getSession().sendInventory();
        return;
    }
    ItemList items = new ItemList(this.getSession().getPlayer().getInventory());
    //List all ways to craft
    for (Recipe recipe : recipes) {
        if (recipe instanceof ShapedRecipe) {
            ShapedRecipe shaped = (ShapedRecipe) recipe;
            boolean faild = false;
            for (String itemChar : shaped.getShape()) {
                ItemStack ingredient = shaped.getIngredientMap().get(new Character(itemChar.charAt(0)));
                if (ingredient == null) {
                    continue;
                }
                if (!items.tryToRemove(ingredient)) {
                    faild = true;
                    break;
                }
            }
            if (!faild) {
                //Apply changes
                for (String itemChar : shaped.getShape()) {
                    ItemStack ingredient = shaped.getIngredientMap().get(new Character(itemChar.charAt(0)));
                    if (ingredient == null) {
                        continue;
                    }
                    this.getSession().getPlayer().getInventory().remove(ingredient);
                }
                //System.out.println("CRAFT SUCCESS! ");
            } else {
                continue;
            }
            this.getSession().getPlayer().getInventory().addItem(result);
            this.getSession().sendInventory();
            return;
        }
    }
    //System.out.println("FAILD TO CRAFT! ");
    this.getSession().sendInventory();
}

From source file:jp.terasoluna.fw.validation.FieldChecksTest01.java

/**
 * testExtractValue07()/*ww  w . j  a  v  a 2s  .  co  m*/
 * <br><br>
 * 
 * ()
 * <br>
 * F
 * <br><br>
 * () bean:new Character('@')<br>
 *         
 * <br>
 * () String:"@"<br>
 *         
 * <br>
 * ?bean?Character???bean????????
 * <br>
 * 
 * @throws Exception ?????
 */
@Test
public void testExtractValue07() throws Exception {
    // 
    // 
    assertEquals("@", new FieldChecks().extractValue(new Character('@'), field));
}

From source file:com.sfs.jbtimporter.JBTProcessor.java

/**
 * Gets the special character map./*from  ww  w. j a v  a  2 s  .c  om*/
 *
 * @return the special character map
 */
private final Map<Character, String> initialiseSpecialCharacterMap() {

    final Map<Character, String> map = new HashMap<Character, String>();

    map.put(new Character('\u0100'), "&#256;");
    map.put(new Character('\u0101'), "&#257;");
    map.put(new Character('\u0102'), "&#258;");
    map.put(new Character('\u0103'), "&#259;");
    map.put(new Character('\u0104'), "&#260;");
    map.put(new Character('\u0105'), "&#261;");
    map.put(new Character('\u0106'), "&#262;");
    map.put(new Character('\u0107'), "&#263;");
    map.put(new Character('\u0108'), "&#264;");
    map.put(new Character('\u0108'), "&#265;");
    map.put(new Character('\u010C'), "&#268;");
    map.put(new Character('\u010D'), "&#269;");
    map.put(new Character('\u010E'), "&#270;");
    map.put(new Character('\u010F'), "&#271;");
    map.put(new Character('\u0110'), "&#272;");
    map.put(new Character('\u0111'), "&#273;");
    map.put(new Character('\u0112'), "&#274;");
    map.put(new Character('\u0113'), "&#275;");
    map.put(new Character('\u0118'), "&#280;");
    map.put(new Character('\u0119'), "&#281;");
    map.put(new Character('\u011A'), "&#282;");
    map.put(new Character('\u011B'), "&#283;");
    map.put(new Character('\u011C'), "&#284;");
    map.put(new Character('\u011D'), "&#285;");
    map.put(new Character('\u011E'), "&#286;");
    map.put(new Character('\u011F'), "&#287;");
    map.put(new Character('\u0122'), "&#290;");
    map.put(new Character('\u0123'), "&#291;");
    map.put(new Character('\u0124'), "&#292;");
    map.put(new Character('\u0125'), "&#293;");
    map.put(new Character('\u012A'), "&#298;");
    map.put(new Character('\u012B'), "&#299;");
    map.put(new Character('\u0130'), "&#304;");
    map.put(new Character('\u0131'), "&#305;");
    map.put(new Character('\u0134'), "&#308;");
    map.put(new Character('\u0135'), "&#309;");
    map.put(new Character('\u0136'), "&#310;");
    map.put(new Character('\u0137'), "&#311;");
    map.put(new Character('\u0139'), "&#313;");
    map.put(new Character('\u013A'), "&#314;");
    map.put(new Character('\u013B'), "&#315;");
    map.put(new Character('\u013C'), "&#316;");
    map.put(new Character('\u013D'), "&#317;");
    map.put(new Character('\u013E'), "&#318;");
    map.put(new Character('\u0141'), "&#321;");
    map.put(new Character('\u0142'), "&#322;");
    map.put(new Character('\u0143'), "&#323;");
    map.put(new Character('\u0144'), "&#324;");
    map.put(new Character('\u0145'), "&#325;");
    map.put(new Character('\u0146'), "&#326;");
    map.put(new Character('\u0147'), "&#327;");
    map.put(new Character('\u0148'), "&#328;");
    map.put(new Character('\u0150'), "&#336;");
    map.put(new Character('\u0151'), "&#337;");
    map.put(new Character('\u0154'), "&#340;");
    map.put(new Character('\u0155'), "&#341;");
    map.put(new Character('\u0156'), "&#342;");
    map.put(new Character('\u0157'), "&#343;");
    map.put(new Character('\u0158'), "&#344;");
    map.put(new Character('\u0159'), "&#345;");
    map.put(new Character('\u015A'), "&#346;");
    map.put(new Character('\u015B'), "&#347;");
    map.put(new Character('\u015C'), "&#348;");
    map.put(new Character('\u015D'), "&#349;");
    map.put(new Character('\u015E'), "&#350;");
    map.put(new Character('\u015F'), "&#351;");
    map.put(new Character('\u0160'), "&#352;");
    map.put(new Character('\u0161'), "&#353;");
    map.put(new Character('\u0162'), "&#354;");
    map.put(new Character('\u0163'), "&#355;");
    map.put(new Character('\u0164'), "&#356;");
    map.put(new Character('\u0165'), "&#357;");
    map.put(new Character('\u016A'), "&#362;");
    map.put(new Character('\u016B'), "&#363;");
    map.put(new Character('\u016C'), "&#364;");
    map.put(new Character('\u016D'), "&#365;");
    map.put(new Character('\u016E'), "&#366;");
    map.put(new Character('\u016F'), "&#367;");
    map.put(new Character('\u0170'), "&#368;");
    map.put(new Character('\u0171'), "&#369;");
    map.put(new Character('\u0178'), "&#376;");
    map.put(new Character('\u0179'), "&#377;");
    map.put(new Character('\u017A'), "&#378;");
    map.put(new Character('\u017B'), "&#379;");
    map.put(new Character('\u017C'), "&#380;");
    map.put(new Character('\u017D'), "&#381;");
    map.put(new Character('\u017E'), "&#382;");
    map.put(new Character('\u2116'), "&#8470;");
    map.put(new Character('\u00C1'), "&Aacute;");
    map.put(new Character('\u00E1'), "&aacute;");
    map.put(new Character('\u00C2'), "&Acirc;");
    map.put(new Character('\u00E2'), "&acirc;");
    map.put(new Character('\u00C6'), "&AElig;");
    map.put(new Character('\u00E6'), "&aelig;");
    map.put(new Character('\u00E0'), "&agrave;");
    map.put(new Character('\u00C0'), "&Agrave;");
    map.put(new Character('\u00C5'), "&Aring;");
    map.put(new Character('\u00E5'), "&aring;");
    map.put(new Character('\u00C3'), "&Atilde;");
    map.put(new Character('\u00E3'), "&atilde;");
    map.put(new Character('\u00C4'), "&Auml;");
    map.put(new Character('\u00E4'), "&auml;");
    map.put(new Character('\u2022'), "&bull;");
    map.put(new Character('\u00C7'), "&Ccedil;");
    map.put(new Character('\u00E7'), "&ccedil;");
    map.put(new Character('\u00A9'), "&copy;");
    map.put(new Character('\u2020'), "&dagger;");
    map.put(new Character('\u00B0'), "&deg;");
    map.put(new Character('\u00C9'), "&Eacute;");
    map.put(new Character('\u00E9'), "&eacute;");
    map.put(new Character('\u00CA'), "&Ecirc;");
    map.put(new Character('\u00EA'), "&ecirc;");
    map.put(new Character('\u00C8'), "&Egrave;");
    map.put(new Character('\u00E8'), "&egrave;");
    map.put(new Character('\u00D0'), "&ETH;");
    map.put(new Character('\u00F0'), "&eth;");
    map.put(new Character('\u00CB'), "&Euml;");
    map.put(new Character('\u00EB'), "&euml;");
    map.put(new Character('\u20AC'), "&euro;");
    map.put(new Character('\u00CD'), "&Iacute;");
    map.put(new Character('\u00ED'), "&iacute;");
    map.put(new Character('\u00CE'), "&Icirc;");
    map.put(new Character('\u00EE'), "&icirc;");
    map.put(new Character('\u00A1'), "&iexcl;");
    map.put(new Character('\u00CC'), "&Igrave;");
    map.put(new Character('\u00EC'), "&igrave;");
    map.put(new Character('\u00BF'), "&iquest;");
    map.put(new Character('\u00CF'), "&Iuml;");
    map.put(new Character('\u00EF'), "&iuml;");
    map.put(new Character('\u00AB'), "&laquo;");
    map.put(new Character('\u2014'), "&mdash;");
    map.put(new Character('\u00B5'), "&micro;");
    map.put(new Character('\u00B7'), "&middot;");
    map.put(new Character('\u2013'), "&ndash;");
    map.put(new Character('\u00D1'), "&Ntilde;");
    map.put(new Character('\u00F1'), "&ntilde;");
    map.put(new Character('\u00D3'), "&Oacute;");
    map.put(new Character('\u00F3'), "&oacute;");
    map.put(new Character('\u00D4'), "&Ocirc;");
    map.put(new Character('\u00F4'), "&ocirc;");
    map.put(new Character('\u0152'), "&OElig;");
    map.put(new Character('\u0153'), "&oelig;");
    map.put(new Character('\u00D2'), "&Ograve;");
    map.put(new Character('\u00F2'), "&ograve;");
    map.put(new Character('\u00AA'), "&ordf;");
    map.put(new Character('\u00BA'), "&ordm;");
    map.put(new Character('\u00D8'), "&Oslash;");
    map.put(new Character('\u00F8'), "&oslash;");
    map.put(new Character('\u00D5'), "&Otilde;");
    map.put(new Character('\u00F5'), "&otilde;");
    map.put(new Character('\u00D6'), "&Ouml;");
    map.put(new Character('\u00F6'), "&ouml;");
    map.put(new Character('\u00A3'), "&pound;");
    map.put(new Character('\u00BB'), "&raquo;");
    map.put(new Character('\u00AE'), "&reg;");
    map.put(new Character('\u00DF'), "&szlig;");
    map.put(new Character('\u00DE'), "&THORN;");
    map.put(new Character('\u00FE'), "&thorn;");
    map.put(new Character('\u00DA'), "&Uacute;");
    map.put(new Character('\u00FA'), "&uacute;");
    map.put(new Character('\u00DB'), "&Ucirc;");
    map.put(new Character('\u00FB'), "&ucirc;");
    map.put(new Character('\u00D9'), "&Ugrave;");
    map.put(new Character('\u00F9'), "&ugrave;");
    map.put(new Character('\u00F6'), "&uml;");
    map.put(new Character('\u00DC'), "&Uuml;");
    map.put(new Character('\u00FC'), "&uuml;");
    map.put(new Character('\u00DD'), "&Yacute;");
    map.put(new Character('\u00FD'), "&yacute;");
    map.put(new Character('\u00FF'), "&yuml;");

    return map;
}

From source file:net.sf.ezmorph.bean.BeanMorpherTest.java

public void testMorph_PrimitiveBean_to_TypedBean() {
    PrimitiveBean primitiveBean = new PrimitiveBean();
    primitiveBean.setPclass(Object.class);
    primitiveBean.setPstring("MORPH");
    morpherRegistry.registerMorpher(new BeanMorpher(TypedBean.class, morpherRegistry));
    TypedBean typedBean = (TypedBean) morpherRegistry.morph(TypedBean.class, primitiveBean);
    assertNotNull(typedBean);/*from  ww w  .  ja v  a2s .c o m*/
    assertEquals(Boolean.FALSE, typedBean.getPboolean());
    assertEquals(Byte.valueOf("0"), typedBean.getPbyte());
    assertEquals(Short.valueOf("0"), typedBean.getPshort());
    assertEquals(Integer.valueOf("0"), typedBean.getPint());
    assertEquals(Long.valueOf("0"), typedBean.getPlong());
    assertEquals(Float.valueOf("0"), typedBean.getPfloat());
    assertEquals(Double.valueOf("0"), typedBean.getPdouble());
    assertEquals(new Character('\0'), typedBean.getPchar());
    assertEquals(null, typedBean.getParray());
    assertEquals(null, typedBean.getPlist());
    assertEquals(null, typedBean.getPbean());
    assertEquals(null, typedBean.getPmap());
    assertEquals("MORPH", typedBean.getPstring());
    assertEquals(Object.class, typedBean.getPclass());
}

From source file:edu.cornell.mannlib.vedit.util.Stemmer.java

public static String StemString(String inputStr, int maxLength) {
    String outputStr = "";

    int previousCh = 0;
    char[] w = new char[maxLength];
    char[] inputArray = inputStr.toCharArray();
    Stemmer s = new Stemmer();
    int inputArrayIndex = 0, stemmerInputBufferIndex = 0, ch = 0;
    for (inputArrayIndex = 0; inputArrayIndex < inputArray.length; inputArrayIndex++) {
        ch = inputArray[inputArrayIndex];
        if (Character.isLetter((char) ch)) {
            stemmerInputBufferIndex = 0; // start collecting letters for a new word
            while (inputArrayIndex < inputArray.length) { // keep reading until hit character other than a letter
                ch = Character.toLowerCase((char) ch);
                w[stemmerInputBufferIndex] = (char) ch;
                if (stemmerInputBufferIndex < maxLength - 1) {
                    stemmerInputBufferIndex++;
                }/*from  w w  w .  j  a v  a  2s . co m*/
                if (inputArrayIndex < inputArray.length - 1) {
                    previousCh = ch;
                    ch = inputArray[++inputArrayIndex];
                    if (!Character.isLetter((char) ch)) { // parse the word in preparation for starting a new one
                        for (int c = 0; c < stemmerInputBufferIndex; c++) { // copy to stemmer internal buffer
                            s.add(w[c]);
                        }
                        s.stem();
                        {
                            String u;
                            u = s.toString();
                            outputStr += u;
                            if (ch == '-') { // replace - with space
                                outputStr += " ";
                            } else if (ch == '.') {
                                if (Character.isDigit((char) previousCh)) {
                                    outputStr += ".";
                                } else {
                                    outputStr += " ";
                                    //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass
                                }
                            } else {
                                Character Ch = new Character((char) ch);
                                outputStr += Ch.toString();
                            }
                            stemmerInputBufferIndex = 0; // to avoid repeats after )
                        }
                        break;
                    }
                } else {
                    break;
                }
            }
        } else if (Character.isWhitespace((char) ch)) {
            if (!Character.isWhitespace((char) previousCh)) {
                if (previousCh != '.') {
                    Character Ch = new Character((char) ch);
                    outputStr += Ch.toString();
                }
            }
        } else if (ch == '(') { // open paren; copy all characters until close paren
            while (ch != ')') {
                if (inputArrayIndex < inputArray.length) {
                    ch = inputArray[inputArrayIndex++];
                } else {
                    log.trace("");
                    log.trace("1 short of EOS in paren at pos: " + inputArrayIndex + " of " + inputStr);
                    break;
                }
                Character Ch = new Character((char) ch);
                //outputStr += Ch.toString();
                //System.out.print( Ch.toString() );
            }
            //log.trace("");
            /* not needed -- just duplicates close paren
            if ( ch == ')') {
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
            log.trace( Ch.toString() );
            }
            */
            stemmerInputBufferIndex = 0;
        } else if (ch == ')') { // when is last character of input string
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
            log.trace(Ch.toString());
            log.trace("found close paren at position: " + inputArrayIndex + " of input term " + inputStr);
        } else if (ch == '-') { // replace - with space
            outputStr += " ";
        } else if (ch == '.') {
            if (Character.isDigit((char) previousCh)) {
                outputStr += ".";
            } else {
                outputStr += " ";
                //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass
            }
        } else {
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
        }
        previousCh = ch;
        if (ch < 0)
            break;
    }

    if (stemmerInputBufferIndex > 0) {
        for (int c = 0; c < stemmerInputBufferIndex; c++) {
            s.add(w[c]);
        }
        s.stem();

        String u;
        u = s.toString();
        outputStr += u;
    }

    return outputStr == null ? (outputStr.equals("") ? null : outputStr.trim()) : outputStr.trim();
}

From source file:org.apache.geode.management.internal.cli.util.JsonUtil.java

public static Object getPrimitiveOrWrapperValue(Class<?> klass, Object value) throws IllegalArgumentException {
    if (klass.isAssignableFrom(Byte.class) || klass.isAssignableFrom(byte.class)) {
        return value;
    } else if (klass.isAssignableFrom(Short.class) || klass.isAssignableFrom(short.class)) {
        return value;
    } else if (klass.isAssignableFrom(Integer.class) || klass.isAssignableFrom(int.class)) {
        return value;
    } else if (klass.isAssignableFrom(Long.class) || klass.isAssignableFrom(long.class)) {
        return value;
    } else if (klass.isAssignableFrom(Float.class) || klass.isAssignableFrom(float.class)) {
        return value;
    } else if (klass.isAssignableFrom(Double.class) || klass.isAssignableFrom(double.class)) {
        return value;
    } else if (klass.isAssignableFrom(Boolean.class) || klass.isAssignableFrom(boolean.class)) {
        return value;
    } else if (klass.isAssignableFrom(String.class)) {
        return String.valueOf(value);
    } else if (klass.isAssignableFrom(Character.class)) {
        // Need to take care of converting between string to char values
        if (value instanceof String) {
            String str = (String) value;
            if (str.length() == 1)
                return new Character(str.charAt(0));
            else if (str.length() > 1 || str.length() == 0) {
                throw new IllegalArgumentException(
                        "Expected Character value but found String with length " + str.length());
            }//from   w  w  w  .j  av a2 s  . c  om
        } else if (value instanceof Character) {
            return value;
        } else {
            throw new IllegalArgumentException("Expected Character value but found " + value.getClass());
        }
    } else if (klass.isAssignableFrom(char.class)) {
        // Need to take care of converting between string to char values
        if (value instanceof String) {
            String str = (String) value;
            if (str.length() == 1)
                return str.charAt(0);
            else if (str.length() > 1 || str.length() == 0) {
                throw new IllegalArgumentException(
                        "Expected Character value but found String with length " + str.length());
            }
        } else if (value instanceof Character) {
            return ((Character) value).charValue();
        } else {
            throw new IllegalArgumentException("Expected Character value but found " + value.getClass());
        }
    } else {
        return null;
    }
    return value;
}

From source file:org.jboss.dashboard.ui.taglib.formatter.Formatter.java

/**
 * Sets a parameter for the fragment. The object set as parameter value
 * must not be changed during all the execution, otherwise the result won't be
 * as expected. That is, if this object has a method that changes its content,
 * this method must not be called by the Formatter during the service() method.
 * Otherwise, all the rendering performed by the fragmentValue tag will use
 * the *last* version of the object, the one existing after the invocation of
 * service method, which is probably not expected.
 * <p>Example, of a iterating formatter:</p>
 * <code>/*from  www .  j a va2 s. co  m*/
 * StringBuffer sb = new StringBuffer();<br>
 * for( int i= 0; i<10; i++){<br>
 * sb.delete(0,sb.length())<br>
 * sb.append( i );<br>
 * setAttribute("index",sb);<br>
 * renderFragment("output");<br>
 * }<br>     *
 * </code>
 * will generate an output like :
 * 10 10 10 10 10 10 10 10 10 10
 * while the expected output is:
 * 0 1 2 3 4 5 6 7 8 9
 * <p/>
 * So, use objects and don't change them. This is usually easy to accomplish, by using
 * different instances, in the example above, replace sb.delete(0,sb.length()) with
 * sb = new StringBuffer();
 *
 * @param name  Name of the parameter.
 * @param value It's value. Must not be changed during all the execution.
 */
protected void setAttribute(String name, char value) {
    if (log.isDebugEnabled())
        log.debug("Setting of attribute " + name + " scheduled.");
    tag.addProcessingInstruction(ProcessingInstruction.getSetParameterInstruction(name, new Character(value)));
}