Example usage for java.lang Character valueOf

List of usage examples for java.lang Character valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Character valueOf(char c) 

Source Link

Document

Returns a Character instance representing the specified char value.

Usage

From source file:com.itemanalysis.psychometrics.statistics.TwoWayTable.java

public long getColCount(char colValue) {
    return getColCount(Character.valueOf(colValue));
}

From source file:org.apache.directory.fortress.web.panel.SDListPanel.java

public SDListPanel(String id, final boolean isStatic) {
    super(id);/*from  w  ww. java 2  s. c o m*/
    SDSet sdSet = new SDSet();
    sdSet.setName("");
    String searchLabel;
    String opName;
    if (isStatic) {
        sdSet.setType(SDSet.SDType.STATIC);
        searchLabel = "SSD Name";
        opName = "ssdRoleSets";
    } else {
        sdSet.setType(SDSet.SDType.DYNAMIC);
        searchLabel = "DSD Name";
        opName = "dsdRoleSets";
    }
    SDListModel sdListModel = new SDListModel(sdSet, SecUtils.getSession(this));
    setDefaultModel(sdListModel);
    List<IGridColumn<DefaultTreeModel, DefaultMutableTreeNode, String>> columns = new ArrayList<>();
    columns.add(new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of(searchLabel), "userObject.name"));

    PropertyColumn description = new PropertyColumn<>(Model.of("Description"), "userObject.Description");

    description.setInitialSize(300);
    columns.add(description);

    PropertyColumn cardinality = new PropertyColumn<>(Model.of("Cardinality"), "userObject.Cardinality");
    cardinality.setInitialSize(100);
    columns.add(cardinality);

    PropertyColumn members = new PropertyColumn<>(Model.of("Members"), "userObject.members");
    members.setInitialSize(600);
    columns.add(members);

    List<SDSet> sdSets = (List<SDSet>) getDefaultModel().getObject();
    treeModel = createTreeModel(sdSets);
    grid = new TreeGrid<DefaultTreeModel, DefaultMutableTreeNode, String>("sdtreegrid", treeModel, columns) {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        public void selectItem(IModel itemModel, boolean selected) {
            node = (DefaultMutableTreeNode) itemModel.getObject();
            if (!node.isRoot()) {
                SDSet sdSet = (SDSet) node.getUserObject();
                log.debug("TreeGrid.addGrid.selectItem selected sdSet =" + sdSet.getName());
                if (super.isItemSelected(itemModel)) {
                    log.debug("TreeGrid.addGrid.selectItem item is selected");
                    super.selectItem(itemModel, false);
                } else {
                    super.selectItem(itemModel, true);
                    SelectModelEvent.send(getPage(), this, sdSet);
                }
            }
        }
    };
    //grid.setContentHeight( 50, SizeUnit.EM );
    grid.setAllowSelectMultiple(false);
    grid.setClickRowToSelect(true);
    grid.setClickRowToDeselect(false);
    grid.setSelectToEdit(false);
    // expand the root node
    grid.getTreeState().expandAll();
    this.listForm = new Form("form");
    this.listForm.add(grid);
    grid.setOutputMarkupId(true);

    radioGroup = new RadioGroup("searchOptions", new PropertyModel(this, "selectedRadioButton"));
    add(radioGroup);
    Radio nameRb = new Radio("nameRb", new Model(Character.valueOf(NAMES)));
    radioGroup.add(nameRb);
    Radio roleRb = new Radio("roleRb", new Model(Character.valueOf(ROLES)));
    radioGroup.add(roleRb);
    addRoleSearchModal(roleRb);
    radioGroup.setOutputMarkupId(true);
    radioGroup.setRenderBodyOnly(false);
    searchValFld = new TextField(GlobalIds.SEARCH_VAL, new PropertyModel<String>(this, GlobalIds.SEARCH_VAL));
    searchValFld.setOutputMarkupId(true);
    AjaxFormComponentUpdatingBehavior ajaxUpdater = new AjaxFormComponentUpdatingBehavior(GlobalIds.ONBLUR) {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            target.add(searchValFld);
        }
    };
    searchValFld.add(ajaxUpdater);
    radioGroup.add(searchValFld);
    this.listForm.add(radioGroup);
    selectedRadioButton = NAMES;
    this.listForm.add(new SecureIndicatingAjaxButton(GlobalIds.SEARCH, GlobalIds.REVIEW_MGR, opName) {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            log.debug(".search onSubmit");
            info("Searching SDSets...");
            if (!StringUtils.isNotBlank(searchVal)) {
                searchVal = "";
            }
            final SDSet srchSd = new SDSet();
            if (isStatic) {
                srchSd.setType(SDSet.SDType.STATIC);
            } else {
                srchSd.setType(SDSet.SDType.DYNAMIC);
            }
            switch (selectedRadioButton) {
            case NAMES:
                log.debug(".onSubmit NAMES RB selected");
                srchSd.setName(searchVal);
                break;
            case ROLES:
                log.debug(".onSubmit ROLES RB selected");
                srchSd.setMember(searchVal);
                break;
            }

            setDefaultModel(new SDListModel(srchSd, SecUtils.getSession(this)));
            treeModel.reload();
            rootNode.removeAllChildren();
            List<SDSet> sdSets = (List<SDSet>) getDefaultModelObject();
            if (CollectionUtils.isNotEmpty(sdSets)) {
                for (SDSet sdSet : sdSets)
                    rootNode.add(new DefaultMutableTreeNode(sdSet));
                info("Search returned " + sdSets.size() + " matching objects");
            } else {
                info("No matching objects found");
            }
            target.add(grid);
        }

        @Override
        public void onError(AjaxRequestTarget target, Form form) {
            log.warn(".search.onError");
            target.add();
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            AjaxCallListener ajaxCallListener = new AjaxCallListener() {
                /** Default serialVersionUID */
                private static final long serialVersionUID = 1L;

                @Override
                public CharSequence getFailureHandler(Component component) {
                    return GlobalIds.WINDOW_LOCATION_REPLACE_COMMANDER_HOME_HTML;
                }
            };
            attributes.getAjaxCallListeners().add(ajaxCallListener);
        }
    });
    add(this.listForm);
}

From source file:org.cloudgraph.hbase.service.HBaseDataConverter.java

/**
 * Converts the given value from bytes based on data type and cardinality
 * information for the given property. For 'many' or multi-valued properties,
 * if the SDO Java type for the property is not already String, the value is
 * first converted from a String using the SDO conversion which uses
 * java.util.Arrays formatting, resulting in an array of primitive types. For
 * non 'many' or singular properties, only the HBase Bytes utility is used.
 * //w ww  .j a  v a 2  s .  c  o m
 * @param targetProperty
 *          the property
 * @param value
 *          the bytes value
 * @return the converted object
 * @throws IllegalArgumentException
 *           if the given property is not a data type property
 */
public Object fromBytes(Property targetProperty, byte[] value) {
    Object result = null;

    if (!targetProperty.getType().isDataType())
        throw new IllegalArgumentException(
                "property " + targetProperty.toString() + " is not a datatype property");

    DataType targetDataType = DataType.valueOf(targetProperty.getType().getName());

    switch (targetDataType) {
    // Data types stored as String bytes in HBase
    case String:
    case Strings:
    case URI:
    case Month:
    case MonthDay:
    case Day:
    case Time:
    case Year:
    case YearMonth:
    case YearMonthDay:
    case Duration:
        String resultStr = Bytes.toString(value);
        result = DataConverter.INSTANCE.fromString(targetProperty, resultStr);
        break;
    case Date:
        resultStr = Bytes.toString(value);
        result = DataConverter.INSTANCE.fromString(targetProperty, resultStr);
        break;
    case DateTime:
        // NOTE: remember datetime is a String Java representation in
        // SDO 2.1
        resultStr = Bytes.toString(value);
        result = DataConverter.INSTANCE.fromString(targetProperty, resultStr);
        break;

    // Data types stored by directly converting from primitive types to
    // bytes in HBase.
    // FIXME: what to do with variable size types e.g. Decimal, BigInteger,
    // Bytes
    case Decimal:
        if (!targetProperty.isMany())
            result = Bytes.toBigDecimal(value);
        else
            result = DataConverter.INSTANCE.fromString(targetProperty, Bytes.toString(value));
        break;
    case Bytes:
        if (!targetProperty.isMany())
            result = value; // already bytes
        else
            result = value; // already bytes
        break;
    case Byte:
        if (!targetProperty.isMany()) {
            // NOTE: no toByte method as would expect as there is
            // opposite method, see below
            // e.g. Bytes.toByte(value);
            if (value != null) {
                if (value.length > 2)
                    log.warn("truncating " + String.valueOf(value.length)
                            + " length byte array for target data type 'byte'");
                result = value[0];
            }
        } else {
            result = value;
        }
        break;
    case Boolean:
        if (!targetProperty.isMany()) {
            result = Bytes.toBoolean(value);
        } else {
            int count = value.length / Bytes.SIZEOF_BOOLEAN;
            List<Boolean> list = new ArrayList<>(count);
            for (int offset = 0, idx = 0; offset < value.length; offset += Bytes.SIZEOF_BOOLEAN, idx++) {
                byte[] buf = new byte[Bytes.SIZEOF_BOOLEAN];
                System.arraycopy(value, offset, buf, 0, Bytes.SIZEOF_BOOLEAN);
                list.add(new Boolean(Bytes.toBoolean(buf)));
            }
            result = list;
        }
        break;
    case Character:
        if (!targetProperty.isMany())
            result = Character.valueOf(Bytes.toString(value).charAt(0));
        else
            result = DataConverter.INSTANCE.fromString(targetProperty, Bytes.toString(value));
        break;
    case Double:
        if (!targetProperty.isMany()) {
            result = Bytes.toDouble(value);
        } else {
            int count = value.length / Bytes.SIZEOF_DOUBLE;
            List<Double> list = new ArrayList<>(count);
            for (int offset = 0, idx = 0; offset < value.length; offset += Bytes.SIZEOF_DOUBLE, idx++) {
                list.add(new Double(Bytes.toDouble(value, offset)));
            }
            result = list;
        }
        break;
    case Float:
        if (!targetProperty.isMany()) {
            result = Bytes.toFloat(value);
        } else {
            int count = value.length / Bytes.SIZEOF_FLOAT;
            List<Float> list = new ArrayList<>(count);
            for (int offset = 0, idx = 0; offset < value.length; offset += Bytes.SIZEOF_FLOAT, idx++) {
                list.add(new Float(Bytes.toFloat(value, offset)));
            }
            result = list;
        }
        break;
    case Int:
        if (!targetProperty.isMany()) {
            result = Bytes.toInt(value);
        } else {
            int count = value.length / Bytes.SIZEOF_INT;
            List<Integer> list = new ArrayList<>(count);
            for (int offset = 0, idx = 0; offset < value.length; offset += Bytes.SIZEOF_INT, idx++) {
                list.add(new Integer(Bytes.toInt(value, offset, Bytes.SIZEOF_INT)));
            }
            result = list;
        }
        break;
    case UnsignedInt:
        if (!targetProperty.isMany()) {
            result = UnsignedInteger.fromIntBits(Ints.fromByteArray(value));
        } else {
            int count = value.length / Bytes.SIZEOF_INT;
            List<UnsignedInteger> list = new ArrayList<>(count);
            for (int offset = 0, idx = 0; offset < value.length; offset += Bytes.SIZEOF_INT, idx++) {
                byte[] bytes = new byte[Bytes.SIZEOF_INT];
                System.arraycopy(value, offset, bytes, 0, bytes.length);
                list.add(UnsignedInteger.fromIntBits(Ints.fromByteArray(bytes)));
            }
            result = list;
        }
        break;
    case Integer:
        if (!targetProperty.isMany())
            result = new BigInteger(value);
        else
            result = DataConverter.INSTANCE.fromString(targetProperty, Bytes.toString(value));
        break;
    case Long:
        if (!targetProperty.isMany()) {
            result = Bytes.toLong(value);
        } else {
            int count = value.length / Bytes.SIZEOF_LONG;
            List<Long> list = new ArrayList<>(count);
            for (int offset = 0, idx = 0; offset < value.length; offset += Bytes.SIZEOF_LONG, idx++) {
                list.add(new Long(Bytes.toLong(value, offset, Bytes.SIZEOF_LONG)));
            }
            result = list;
        }
        break;
    case UnsignedLong:
        if (!targetProperty.isMany()) {
            result = UnsignedLong.fromLongBits(Longs.fromByteArray(value));
        } else {
            int count = value.length / Bytes.SIZEOF_LONG;
            List<UnsignedLong> list = new ArrayList<>(count);
            for (int offset = 0, idx = 0; offset < value.length; offset += Bytes.SIZEOF_LONG, idx++) {
                byte[] bytes = new byte[Bytes.SIZEOF_LONG];
                System.arraycopy(value, offset, bytes, 0, bytes.length);
                list.add(UnsignedLong.fromLongBits(Ints.fromByteArray(bytes)));
            }
            result = list;
        }
        break;
    case Short:
        if (!targetProperty.isMany()) {
            result = Bytes.toShort(value);
        } else {
            int count = value.length / Bytes.SIZEOF_SHORT;
            List<Short> list = new ArrayList<>(count);
            for (int offset = 0, idx = 0; offset < value.length; offset += Bytes.SIZEOF_SHORT, idx++) {
                list.add(new Short(Bytes.toShort(value, offset, Bytes.SIZEOF_SHORT)));
            }
            result = list;
        }
        break;
    case Object:
        // FIXME: custom serialization?
    default:
        result = Bytes.toString(value);
        break;
    }

    return result;
}

From source file:org.kuali.rice.krad.data.jpa.Filter.java

/**
 * Coerces the {@code attributeValue} using the given {@code type}.
 *
 * @param type the type to use to coerce the value.
 * @param attributeName the attribute name of the field to coerce.
 * @param attributeValue the value to coerce.
 * @return the coerced value./*from   ww w  . ja v a  2  s. c o  m*/
 */
private static Object coerceValue(Class<?> type, String attributeName, String attributeValue) {
    try {
        if (Character.TYPE.equals(type) || Character.class.isAssignableFrom(type)) {
            return Character.valueOf(attributeValue.charAt(0));
        } else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) {
            return Boolean.valueOf(attributeValue);
        } else if (Short.TYPE.equals(type) || Short.class.isAssignableFrom(type)) {
            return Short.valueOf(attributeValue);
        } else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) {
            return Integer.valueOf(attributeValue);
        } else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) {
            return Long.valueOf(attributeValue);
        } else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) {
            return Double.valueOf(attributeValue);
        } else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) {
            return Float.valueOf(attributeValue);
        }
    } catch (NumberFormatException nfe) {
        LOG.error("Could not coerce the value " + attributeValue + " for the field " + attributeName, nfe);
    }

    return attributeValue;
}

From source file:org.paxle.crawler.ftp.impl.FtpUrlConnection.java

private static void formatStdDirlisting(final OutputStream into, final FTPListParseEngine fileParseEngine) {
    final Formatter writer = new Formatter(into);
    FTPFile[] files;//w  ww .  j a v a 2s.  c  om
    while (fileParseEngine.hasNext()) {
        files = fileParseEngine.getNext(16);
        for (final FTPFile file : files) {
            if (file == null)
                continue;

            // directory
            char c;
            switch (file.getType()) {
            case FTPFile.DIRECTORY_TYPE:
                c = 'd';
                break;
            case FTPFile.SYMBOLIC_LINK_TYPE:
                c = 's';
                break;
            default:
                c = '-';
                break;
            }
            writer.format("%c", Character.valueOf(c));

            // permissions
            for (final int access : FILE_ACCESS_MODES) {
                writer.format("%c%c%c",
                        Character.valueOf(file.hasPermission(access, FTPFile.READ_PERMISSION) ? 'r' : '-'),
                        Character.valueOf(file.hasPermission(access, FTPFile.WRITE_PERMISSION) ? 'w' : '-'),
                        Character.valueOf(file.hasPermission(access, FTPFile.EXECUTE_PERMISSION) ? 'x' : '-'));
            }

            // other information
            writer.format("  %2d", Integer.valueOf(file.getHardLinkCount()));
            writer.format("  %8s", file.getUser());
            writer.format("  %8s", file.getGroup());
            writer.format("  %12d", Long.valueOf(file.getSize()));
            writer.format("  %1$tY-%1$tm-%1$td %1$tH:%1$tM",
                    Long.valueOf(file.getTimestamp().getTimeInMillis()));
            writer.format("  %s", file.getName());

            writer.format("%s", System.getProperty("line.separator"));
        }
    }

    writer.flush();
}

From source file:it.unimi.dsi.util.Properties.java

public void addProperty(final Enum<?> key, final char c) {
    super.addProperty(key.name().toLowerCase(), Character.valueOf(c));
}

From source file:org.pdfsam.console.business.pdf.handlers.SplitCmdExecutor.java

/**
 * Execute the split of a pdf document when split type is S_BURST
 * //  ww w  .ja va 2  s . co  m
 * @param inputCommand
 * @throws Exception
 */
private void executeBurst(SplitParsedCommand inputCommand) throws Exception {
    int currentPage;
    Document currentDocument;
    pdfReader = PdfUtility.readerFor(inputCommand.getInputFile());
    pdfReader.removeUnusedObjects();
    pdfReader.consolidateNamedDestinations();

    // we retrieve the total number of pages
    int n = pdfReader.getNumberOfPages();
    int fileNum = 0;
    LOG.info("Found " + n + " pages in input pdf document.");
    for (currentPage = 1; currentPage <= n; currentPage++) {
        LOG.debug("Creating a new document.");
        fileNum++;
        File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
        FileNameRequest request = new FileNameRequest(currentPage, fileNum, null);
        File outFile = new File(inputCommand.getOutputFile().getCanonicalPath(),
                prefixParser.generateFileName(request));
        currentDocument = new Document(pdfReader.getPageSizeWithRotation(currentPage));

        pdfWriter = new PdfSmartCopy(currentDocument, new FileOutputStream(tmpFile));

        currentDocument.addCreator(ConsoleServicesFacade.CREATOR);
        setCompressionSettingOnWriter(inputCommand, pdfWriter);

        // set pdf version
        setPdfVersionSettingOnWriter(inputCommand, pdfWriter, Character.valueOf(pdfReader.getPdfVersion()));

        currentDocument.open();
        PdfImportedPage importedPage = pdfWriter.getImportedPage(pdfReader, currentPage);
        pdfWriter.addPage(importedPage);
        currentDocument.close();
        FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
        LOG.debug("File " + outFile.getCanonicalPath() + " created.");
        setPercentageOfWorkDone((currentPage * WorkDoneDataModel.MAX_PERGENTAGE) / n);
    }
    pdfReader.close();
    LOG.info("Burst done.");
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

@Test
public void testWhenTrieSizeLessThanGroupSize2() {
    List<String> pages = Arrays.asList(_property + "13");
    UrlTrie trie1 = new UrlTrie(_property, pages);
    UrlTriePrefixGrouper grouper = new UrlTriePrefixGrouper(trie1, 2);
    Triple<String, FilterOperator, UrlTrieNode> next = grouper.next();
    Assert.assertEquals(next.getLeft(), _property);
    Assert.assertEquals(next.getMiddle(), FilterOperator.CONTAINS);
    Assert.assertEquals(next.getRight().getValue(), Character.valueOf('/'));
    Assert.assertFalse(next.getRight().isExist());
    Assert.assertFalse(grouper.hasNext());
}

From source file:it.unimi.dsi.util.Properties.java

public void setProperty(final Enum<?> key, final char b) {
    super.setProperty(key.name().toLowerCase(), Character.valueOf(b));
}

From source file:demo.config.PropertyConverter.java

/**
 * Converts the specified value object to a {@code Character}. This method
 * converts the passed in object to a string. If the string has exactly one
 * character, this character is returned as result. Otherwise, conversion
 * fails./*  w w  w.java 2  s .co  m*/
 * 
 * @param value
 *            the value to be converted
 * @return the resulting {@code Character} object
 * @throws ConversionException
 *             if the conversion is not possible
 */
public static Character toCharacter(Object value) throws ConversionException {
    String strValue = String.valueOf(value);
    if (strValue.length() == 1) {
        return Character.valueOf(strValue.charAt(0));
    } else {
        throw new ConversionException(
                String.format("The value '%s' cannot be converted to a Character object!", strValue));
    }
}