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:com.marand.thinkmed.medications.business.impl.TherapyDisplayProvider.java

public String getFormattedDecimalValue(final String decimalValue, final Locale locale, final boolean bold) {
    if (decimalValue == null || locale == null) {
        return "";
    }/*  w  w  w .  jav a 2 s .c  o m*/
    final DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
    final Character decimalSeparator = dfs.getDecimalSeparator();
    final String splitDelimiter = decimalSeparator.equals(new Character('.')) ? "\\." : ",";

    String formattedValue = decimalValue;
    final Pattern p = Pattern.compile("\\d+" + splitDelimiter + "\\d+"); // or ("[0-9]+" + splitDelimiter + "[0-9]+") ?
    final Matcher m = p.matcher(formattedValue);
    while (m.find()) {
        final String[] decimalNumbers = m.group().split(splitDelimiter);
        if (decimalNumbers.length == 2) {
            formattedValue = formattedValue.replaceAll(m.group(),
                    decimalNumbers[0] + splitDelimiter + createSpannedValue(decimalNumbers[1],
                            "TextDataSmallerDecimal" + (bold ? " bold" : ""), false));
        }
    }
    return formattedValue;
}

From source file:net.sf.taverna.t2.activities.apiconsumer.ApiConsumerActivity.java

/**
 * Returns an array of objects representing the arguments of the method to be invoked.
 *
 * @return/* www . jav a2s  .  com*/
 * @throws Exception
 */
private Object[] argumentObjects(Map<String, T2Reference> data, AsynchronousActivityCallback callback)
        throws Exception {

    ReferenceService referenceService = callback.getContext().getReferenceService();

    // Argument objects
    String className = json.get("className").textValue();
    String methodName = json.get("methodName").textValue();
    JsonNode parameterNames = json.get("parameterNames");
    JsonNode parameterTypes = json.get("parameterTypes");
    JsonNode parameterDimensions = json.get("parameterDimensions");
    Object[] inputObjects = new Object[parameterTypes.size()];
    for (int i = 0; i < inputObjects.length; i++) {
        // Get the argument object from the reference service
        String parameterName = parameterNames.get(i).textValue();
        String parameterType = parameterTypes.get(i).textValue();
        int parameterDimension = parameterDimensions.get(i).intValue();
        Object argument = null;

        if (canRegisterAsString(parameterType)) {
            // Parameter was registered as a String with the Reference Service -
            // try to get it as String or list (of lists of ...) Strings and parse it internally
            try {
                argument = referenceService.renderIdentifier(data.get(parameterName), String.class,
                        callback.getContext());
            } catch (ReferenceServiceException rse) {
                throw new Exception("API Consumer " + className + "." + methodName + " error: "
                        + "Could not fetch the input argument " + parameterName + " of type " + parameterType
                        + " from the Reference Service.");
            }

            if (argument == null) {
                throw new Exception(
                        "API Consumer " + className + "." + methodName + " error: " + "Required input argument "
                                + parameterName + " of type " + parameterType + " not found.");
            }

            if (parameterType == "char") {
                // char
                if (parameterDimension == 0) {
                    inputObjects[i] = new Character(((String) argument).charAt(0));
                }
                //char[]
                else if (parameterDimension == 1) {
                    inputObjects[i] = ((String) argument).toCharArray();
                } else // char[][] is returned as a list of Strings, char[][][] is returned as a list of lists of Strings etc.
                {
                    // Convert the list (of lists of ...) Strings to char[][]...[]
                    inputObjects[i] = createInputObject(argument, "char[]", parameterDimension - 1);
                }
            } else {
                inputObjects[i] = createInputObject(argument, parameterType, parameterDimension);
            }
        } else if (parameterType == "byte") {
            // Parameter was registered as byte, byte[], byte[][], etc.
            try {
                argument = referenceService.renderIdentifier(data.get(parameterName), byte[].class,
                        callback.getContext());

            } catch (ReferenceServiceException rse) {
                throw new Exception("API Consumer " + className + "." + methodName + " error: "
                        + "Could not fetch the input argument " + parameterName + " of type " + parameterType
                        + " from the Reference Service.");
            }

            if (argument == null) {
                throw new Exception(
                        "API Consumer " + className + "." + methodName + " error: " + "Required input argument "
                                + parameterName + " of type " + parameterType + " not found.");
            }

            if (parameterDimension == 0) {
                inputObjects[i] = new Byte(((byte[]) argument)[0]);
            } else if (parameterDimension == 1) {
                inputObjects[i] = (byte[]) argument;
            } else // byte[][] is returned as a list of byte[]s, byte[][][] is returned as a list of lists of byte[]s, etc.
            {
                // Convert the list (of lists of ...) byte[] to byte[][]...[]
                inputObjects[i] = createInputObject(argument, "byte[]", parameterDimension - 1);
            }
        } else {
            // Parameter was regestered with Reference Service as object inside an VMObjectReference wrapper
            try {
                // Get the reference set for the VMObjectReference
                ReferenceSet vmObjectReferenceSet = (ReferenceSet) referenceService
                        .resolveIdentifier(data.get(parameterName), null, callback.getContext());
                // The set should contain only one external reference, i.e. VMObjectReference
                Set<ExternalReferenceSPI> externalReferences = vmObjectReferenceSet.getExternalReferences();
                for (ExternalReferenceSPI externalReference : externalReferences) {
                    if (externalReference instanceof VMObjectReference) {
                        argument = (VMObjectReference) externalReference;
                        break;
                    }
                }
            } catch (ReferenceServiceException rse) {
                throw new Exception("API Consumer " + className + "." + methodName + " error: "
                        + "Could not fetch the input argument " + parameterName + " of type " + parameterType
                        + " from the Reference Service.");
            }

            if (argument == null) {
                throw new Exception(
                        "API Consumer " + className + "." + methodName + " error: " + "Required input argument "
                                + parameterName + " of type " + parameterType + " not found.");
            }
            // Get the actual object from the wrapper
            inputObjects[i] = ((VMObjectReference) argument).getObject();
        }
    }
    return inputObjects;
}

From source file:org.lockss.test.LockssTestCase.java

public static void assertNotEquals(String message, char expected, char actual) {
    assertNotEquals(message, new Character(expected), new Character(actual));
}

From source file:net.sf.json.TestJSONArray.java

public void testToArray_Character() {
    String[] expected = { "A", "B" };
    Character[] chars = new Character[] { new Character('A'), new Character('B') };
    JSONArray jsonArray = JSONArray.fromObject(chars);
    Object actual = JSONArray.toArray(jsonArray);
    Assertions.assertEquals(expected, actual);
}

From source file:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java

/**
 * Consume an XML message and update the specified Character instance.
 * <br>/*from w  w w .j  ava2 s. com*/
 * @param object the instance that is to be updated with the XML message data.
 * @param cellElement the XML element that contains the data
 * @return the updated instance.
 * @exception JDOMException if there is an error consuming the message.
 */
private Object consumeMsg(Character object, Element cellElement) throws JDOMException {

    // -----------------------
    // Process the element ...
    // -----------------------
    Character result;
    try {
        if (cellElement.getTextTrim().length() == 0) {
            return null;
        }
        result = new Character(cellElement.getTextTrim().charAt(0));
    } catch (NumberFormatException e) {
        throw new JDOMException("Unable to parse the value for " + cellElement.getName() + //$NON-NLS-1$
                " element: " + cellElement.getTextTrim(), e); //$NON-NLS-1$
    }
    return result;
}

From source file:it.classhidra.core.controller.bean.java

public void set(String name, char value) {
    Object primArgument = getPrimitiveArgument(name, String.valueOf(value));
    try {//from  ww w  .j ava2 s. c o  m
        if (primArgument != null)
            setCampoValueWithPoint(name, primArgument);
        else
            setCampoValueWithPoint(name, new Character(value));
    } catch (Exception e) {
    }
}

From source file:org.energy_home.jemma.ah.internal.configurator.Configuratore.java

private void test() throws Exception {
    ServiceReference sr = bc.getServiceReference(ConfigurationAdmin.class.getName());
    ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) bc.getService(sr);

    // Array//from  ww w  . j a v  a2s  .  c o m
    Hashtable testArrayConf = new Hashtable();
    testArrayConf.put("int", new int[] { 1, 2 });
    testArrayConf.put("String", new String[] { "1", "2" });
    testArrayConf.put("Integer", new Integer[] { new Integer(1), new Integer(2) });
    testArrayConf.put("Boolean", new Boolean[] { new Boolean(true), new Boolean(false) });
    testArrayConf.put("Double", new Double[] { new Double(1), new Double(2) });
    testArrayConf.put("Short", new Short[] { new Short((short) 1), new Short((short) 2) });
    testArrayConf.put("Long", new Long[] { new Long(1), new Long(2) });
    testArrayConf.put("Float", new Float[] { new Float(1), new Float(2) });
    testArrayConf.put("Character", new Character[] { new Character('a'), new Character('b') });

    Configuration c = configurationAdmin.getConfiguration("testArray");
    c.update(testArrayConf);
}

From source file:org.dragonet.net.translator.protocols.v0_10_0.Translator_v0_10_0.java

private void processCrafting(WindowSetSlotPacket packet) {
    if (!(this.getSession().getPlayer() instanceof Player)) {
        return;/*from  w w  w .j  ava 2  s . c o  m*/
    }
    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:net.sf.json.TestJSONObject.java

public void testToBean_emptyBean() {
    EmptyBean bean = new EmptyBean();

    JSONObject json = JSONObject.fromObject(bean);
    JSONObject expected = new JSONObject();
    expected.element("arrayp", new JSONArray());
    expected.element("listp", new JSONArray());
    expected.element("bytep", new Integer(0));
    expected.element("shortp", new Integer(0));
    expected.element("intp", new Integer(0));
    expected.element("longp", new Integer(0));
    expected.element("floatp", new Integer(0));
    expected.element("doublep", new Double(0));
    expected.element("charp", "");
    expected.element("stringp", "");

    Assertions.assertEquals(expected, json);

    EmptyBean bean2 = (EmptyBean) JSONObject.toBean(json, EmptyBean.class);

    ArrayAssertions.assertEquals(new Object[0], bean2.getArrayp());
    Assertions.assertEquals(new ArrayList(), bean2.getListp());
    Assertions.assertEquals(new Byte((byte) 0), bean2.getBytep());
    Assertions.assertEquals(new Short((short) 0), bean2.getShortp());
    Assertions.assertEquals(new Integer(0), bean2.getIntp());
    Assertions.assertEquals(new Long(0), bean2.getLongp());
    Assertions.assertEquals(new Float(0), bean2.getFloatp());
    Assertions.assertEquals(new Double(0), bean2.getDoublep());
    Assertions.assertEquals(new Character('\0'), bean2.getCharp());
    Assertions.assertEquals("", bean2.getStringp());
}

From source file:it.classhidra.core.controller.bean.java

public char getChar(String name) {
    char result = ' ';
    Object objectResult = get(name);
    if (objectResult == null)
        return result;
    if (objectResult instanceof Character)
        return ((Character) objectResult).charValue();
    try {//w w w  . j ava2s  .c o m
        return new Character(objectResult.toString().trim().charAt(0)).charValue();
    } catch (Exception e) {
    }
    return result;
}