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:org.pdfsam.console.business.pdf.handlers.SplitCmdExecutor.java

/**
 * Execute the split of a pdf document when split type is S_SIZE
 * /*from  w  ww.  jav a 2 s .  co  m*/
 * @param inputCommand
 * @throws Exception
 */
private void executeSizeSplit(SplitParsedCommand inputCommand) throws Exception {
    pdfReader = PdfUtility.readerFor(inputCommand.getInputFile());
    pdfReader.removeUnusedObjects();
    pdfReader.consolidateNamedDestinations();
    int n = pdfReader.getNumberOfPages();
    BookmarksProcessor bookmarkProcessor = new BookmarksProcessor(SimpleBookmark.getBookmark(pdfReader), n);
    int fileNum = 0;
    LOG.info("Found " + n + " pages in input pdf document.");
    int currentPage;
    Document currentDocument = new Document(pdfReader.getPageSizeWithRotation(1));
    PdfImportedPage importedPage;
    File tmpFile = null;
    File outFile = null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int startPage = 0;
    int relativeCurrentPage = 0;
    for (currentPage = 1; currentPage <= n; currentPage++) {
        relativeCurrentPage++;
        // time to open a new document?
        if (relativeCurrentPage == 1) {
            LOG.debug("Creating a new document.");
            startPage = currentPage;
            fileNum++;
            tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
            FileNameRequest request = new FileNameRequest(currentPage, fileNum, null);
            outFile = new File(inputCommand.getOutputFile(), prefixParser.generateFileName(request));
            currentDocument = new Document(pdfReader.getPageSizeWithRotation(currentPage));
            baos = new ByteArrayOutputStream();
            pdfWriter = new PdfSmartCopy(currentDocument, baos);
            // set creator
            currentDocument.addCreator(ConsoleServicesFacade.CREATOR);

            setCompressionSettingOnWriter(inputCommand, pdfWriter);
            setPdfVersionSettingOnWriter(inputCommand, pdfWriter, Character.valueOf(pdfReader.getPdfVersion()));

            currentDocument.open();
        }

        importedPage = pdfWriter.getImportedPage(pdfReader, currentPage);
        pdfWriter.addPage(importedPage);
        // if it's time to close the document
        if ((currentPage == n) || ((relativeCurrentPage > 1) && ((baos.size() / relativeCurrentPage)
                * (1 + relativeCurrentPage) > inputCommand.getSplitSize().longValue()))) {
            LOG.debug("Current stream size: " + baos.size() + " bytes.");
            // manage bookmarks
            List bookmarks = bookmarkProcessor.processBookmarks(startPage, currentPage);
            if (bookmarks != null) {
                pdfWriter.setOutlines(bookmarks);
            }
            relativeCurrentPage = 0;
            currentDocument.close();
            FileOutputStream fos = new FileOutputStream(tmpFile);
            baos.writeTo(fos);
            fos.close();
            baos.close();
            LOG.info("Temporary document " + tmpFile.getName() + " done.");
            FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
            LOG.debug("File " + outFile.getCanonicalPath() + " created.");
        }
        setPercentageOfWorkDone((currentPage * WorkDoneDataModel.MAX_PERGENTAGE) / n);
    }
    pdfReader.close();
    LOG.info("Split " + inputCommand.getSplitType() + " done.");
}

From source file:com.vmware.bdd.cli.commands.CommandsUtils.java

private static String readEnter(String msg, PromptType promptType) throws Exception {
    String enter = "";
    ConsoleReader reader = getConsoleReader();
    reader.setPrompt(msg);/* w ww. j  a  va2  s  .  c om*/
    if (promptType == PromptType.USER_NAME) {
        enter = reader.readLine();
    } else if (promptType == PromptType.PASSWORD) {
        enter = reader.readLine(Character.valueOf('*'));
    }
    return enter;
}

From source file:com.dell.asm.asmcore.asmmanager.db.DeviceGroupDAO.java

/**
 * Helper method for adding filter criteria
 * //  w ww.jav  a 2s  .  co m
 * @param criteria
 *            - the filter criteria
 * @param filterInfos
 *            - list for filter specifications. filter info are added in the order in the list
 *            
 * @return List<FilterParamParser.FilterInfo>
 *                             - list of added filters
 * 
 * @throws IllegalArgumentException
 */
@SuppressWarnings("unchecked")
private List<FilterParamParser.FilterInfo> addFilterCriteria(Criteria criteria,
        List<FilterParamParser.FilterInfo> filterInfos, Class persistentClass) {

    LinkedList<FilterParamParser.FilterInfo> notFound = new LinkedList<>();

    for (FilterParamParser.FilterInfo filterInfo : filterInfos) {
        String columnName = filterInfo.getColumnName();
        List<?> values = filterInfo.getColumnValue();

        //
        // Cast strings to the property type by scanning the persistent class
        //
        Class<?> typeClass = null;
        // try non-boolean-type naming.
        try {
            typeClass = persistentClass.getMethod("get" + StringUtils.capitalize(columnName)).getReturnType();
        } catch (NoSuchMethodException e) {
            logger.info("cannot find a method for " + columnName + " in " + persistentClass.toString());

        }
        // try boolean-type naming.
        if (typeClass == null) {
            try {
                typeClass = persistentClass.getMethod("is" + StringUtils.capitalize(columnName))
                        .getReturnType();
            } catch (NoSuchMethodException e) {
                logger.info("cannot find a method for " + columnName + " in " + persistentClass.toString());
            }
        }
        // property not found. skip.
        if (typeClass == null) {
            notFound.add(filterInfo);
            continue;
        }
        if (!typeClass.isAssignableFrom(String.class)) {

            // byte/short/int/long
            if (typeClass == byte.class || typeClass == short.class || typeClass == int.class
                    || typeClass == long.class) {
                LinkedList<Long> castedValues = new LinkedList<>();
                for (String stringValue : filterInfo.getColumnValue()) {
                    castedValues.add(Long.valueOf(stringValue));
                }
                // Set casted values
                values = castedValues;

                // float/double
            } else if (typeClass == float.class || typeClass == double.class) {
                LinkedList<Double> castedValues = new LinkedList<>();
                for (String stringValue : filterInfo.getColumnValue()) {
                    castedValues.add(Double.valueOf(stringValue));
                }
                // Set casted values
                values = castedValues;
                // boolean
            } else if (typeClass == boolean.class) {
                LinkedList<Boolean> castedValues = new LinkedList<>();
                for (String stringValue : filterInfo.getColumnValue()) {
                    castedValues.add(Boolean.valueOf(stringValue));
                }
                // Set casted values
                values = castedValues;
                // char
            } else if (typeClass == char.class) {
                LinkedList<Character> castedValues = new LinkedList<>();
                for (String stringValue : filterInfo.getColumnValue()) {
                    castedValues.add(Character.valueOf(stringValue.charAt(0)));
                }
                // Set casted values
                values = castedValues;
            }
        }

        //
        // Translate filters to Hibernate Criteria
        //
        if (values.size() > 1) {
            if (FilterParamParser.FilterOperator.EQUAL.equals(filterInfo.getFilterOperator())) {
                criteria.add(Restrictions.in(columnName, values));
            } else {
                throw new IllegalArgumentException(
                        "filter operation '" + filterInfo.getFilterOperator() + "' is not recognized.");
            }
        } else if (values.size() == 1) {
            if (FilterParamParser.FilterOperator.EQUAL.equals(filterInfo.getFilterOperator())) {
                criteria.add(Restrictions.eq(columnName, values.get(0)));
            } else if (FilterParamParser.FilterOperator.CONTAIN.equals(filterInfo.getFilterOperator())) {

                // Escape '_', '%', and '\' for Hibernate.
                String escapedString = values.get(0).toString();
                escapedString = escapedString.replace("\\", "\\\\").replace("_", "\\_").replace("%", "\\%");

                criteria.add(Restrictions.like(columnName, escapedString, MatchMode.ANYWHERE));
            } else {
                throw new IllegalArgumentException(
                        "filter operation '" + filterInfo.getFilterOperator() + "' is not recognized.");
            }
        }
    }

    return notFound;
}

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

private Object getInstance(String type, String value) {
    if ((type == null) || ((type != null) && (type.equals("String")))) {
        return value;
    } else if (type.equals("Integer")) {
        return Integer.valueOf(value);
    } else if (type.equals("Boolean")) {
        return Boolean.valueOf(value);
    } else if (type.equals("Double")) {
        return Double.valueOf(value);
    } else if (type.equals("Short")) {
        return Short.valueOf(value);
    } else if (type.equals("Long")) {
        return Long.valueOf(value);
    } else if (type.equals("Float")) {
        return Float.valueOf(value);
    } else if (type.equals("Character")) {
        return Character.valueOf(value.charAt(0));
    } else if (type.equals("int")) {
        return Integer.parseInt(value);
    } else if (type.equals("short")) {
        return Short.parseShort(value);
    } else if (type.equals("boolean")) {
        return Boolean.parseBoolean(value);
    } else if (type.equals("double")) {
        return Double.parseDouble(value);
    } else if (type.equals("long")) {
        return Long.parseLong(value);
    } else if (type.equals("float")) {
        return Float.parseFloat(value);
    } else if (type.equals("char")) {
        return value.charAt(0);
    }//from   ww  w. j a v a  2  s  .  co m

    return value;
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java

/**
 * Gets the char value.// w ww . j a v  a  2s  .c  o m
 * 
 * @param node
 *          the node
 * @return the char value
 * @throws NotANumberException
 *           the not a number exception
 */
public static char getCharValue(final AbstractInsnNode node) throws NotANumberException {
    if (node == null) {
        throw new NotANumberException();
    }
    final Number numberValue = getNumberValue(node);
    if (numberValue == null) {
        throw new NotANumberException();
    }
    final int charValue = numberValue.intValue();
    return Character.valueOf((char) charValue);
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Invoke the given setter on the given object.
 *//* w w w .  j  av  a  2s.c o  m*/
public static void set(Object target, Method setter, char value) {
    set(target, setter, Character.valueOf(value));
}

From source file:com.duy.pascal.ui.view.console.ConsoleView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.isSystem()) {
        return super.onKeyDown(keyCode, event);
    }/*ww w. j  a v a 2  s  . c  o m*/
    mKeyBuffer.push((char) event.getUnicodeChar()); //scan code

    if (keyCode == KeyEvent.KEYCODE_DEL) {
        putString(THE_DELETE_COMMAND);
        return true;
    }
    String c = event.getCharacters();
    if (c == null) {
        c = Character.valueOf((char) event.getUnicodeChar()).toString();
    }
    putString(c);
    return true;
}

From source file:com.intuit.tank.tools.debugger.ActionProducer.java

/**
 * /*from   w  ww  .  j a v  a  2 s  .  co  m*/
 * @return
 */
public Action getQuitAction() {
    Action ret = actionMap.get(ACTION_QUIT);
    if (ret == null) {
        ret = new AbstractAction(ACTION_QUIT) {
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                debuggerFrame.quit();

            }
        };
        ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(Character.valueOf('Q'), menuActionMods));
        ret.putValue(Action.MNEMONIC_KEY, new Integer('Q'));
        actionMap.put(ACTION_QUIT, ret);
    }
    return ret;
}