Example usage for java.lang Character toString

List of usage examples for java.lang Character toString

Introduction

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

Prototype

public static String toString(int codePoint) 

Source Link

Document

Returns a String object representing the specified character (Unicode code point).

Usage

From source file:com.ettrema.zsync.Upload.java

/**
 * Helper method that reads the String preceding the first colon or newline in the InputStream.
 * /* w w  w  .j a v a  2s  . com*/
 * @param in The InputStream to read from
 * @param maxsearch The maximum number of bytes allowed in the key
 * @return The CHARSET encoded String that was read
 * @throws ParseException If a colon, newline, or end of input is not reached within maxsearch reads
 * @throws IOException
 */
private static String readKey(InputStream in, int maxsearch) throws ParseException, IOException {

    byte NEWLINE = Character.toString(LF).getBytes(CHARSET)[0];
    byte COLON = ":".getBytes(CHARSET)[0];
    byte[] delimiters = { NEWLINE, COLON };

    return readToken(in, delimiters, maxsearch);
}

From source file:com.allmycode.flags.MyActivity.java

boolean isHexDigit(char ch) {
    Log.i(CLASSNAME, "testing " + Character.toString(ch));
    switch (ch) {
    case 'A':
        return true;
    case 'B':
        return true;
    case 'C':
        return true;
    case 'D':
        return true;
    case 'E':
        return true;
    default://w w w . j a va 2s  . c  o  m
        return Character.isDigit(ch);
    }
}

From source file:com.github.pockethub.android.ui.repo.RepositoryListFragment.java

private void updateHeaders(final List<Repository> repos) {
    HeaderFooterListAdapter<?> rootAdapter = getListAdapter();
    if (rootAdapter == null) {
        return;/*from   w  w  w. j  a va  2 s .  c  om*/
    }

    DefaultRepositoryListAdapter adapter = (DefaultRepositoryListAdapter) rootAdapter.getWrappedAdapter();
    adapter.clearHeaders();

    if (repos.isEmpty()) {
        return;
    }

    // Add recent header if at least one recent repository
    Repository first = repos.get(0);
    if (recentRepos.contains(first)) {
        adapter.registerHeader(first, getString(R.string.recently_viewed));
    }

    // Advance past all recent repositories
    int index;
    Repository current = null;
    for (index = 0; index < repos.size(); index++) {
        Repository repository = repos.get(index);
        if (recentRepos.contains(repository.id())) {
            current = repository;
        } else {
            break;
        }
    }

    if (index >= repos.size()) {
        return;
    }

    if (current != null) {
        adapter.registerNoSeparator(current);
    }

    // Register header for first character
    current = repos.get(index);
    char start = Character.toLowerCase(current.name().charAt(0));
    adapter.registerHeader(current, Character.toString(start).toUpperCase(US));

    char previousHeader = start;
    for (index = index + 1; index < repos.size(); index++) {
        current = repos.get(index);
        char repoStart = Character.toLowerCase(current.name().charAt(0));
        if (repoStart <= start) {
            continue;
        }

        // Don't include separator for the last element of the previous
        // character
        if (previousHeader != repoStart) {
            adapter.registerNoSeparator(repos.get(index - 1));
        }

        adapter.registerHeader(current, Character.toString(repoStart).toUpperCase(US));
        previousHeader = repoStart;
        start = repoStart++;
    }

    // Don't include separator for last element
    adapter.registerNoSeparator(repos.get(repos.size() - 1));
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.por.PORFileReader.java

@Override
public TabularDataIngest read(BufferedInputStream stream, File additionalData) throws IOException {
    dbgLog.fine("PORFileReader: read() start");

    if (additionalData != null) {
        //throw new IOException ("this plugin does not support external raw data files");
        dbgLog.fine("Using extended variable labels from file " + additionalData.getName());

        extendedLabels = createLabelMap(additionalData);
    }//from w ww .  j  a va  2 s .com

    File tempPORfile = decodeHeader(stream);
    BufferedReader bfReader = null;

    try {
        bfReader = new BufferedReader(
                new InputStreamReader(new FileInputStream(tempPORfile.getAbsolutePath()), "US-ASCII"));
        if (bfReader == null) {
            dbgLog.fine("bfReader is null");
            throw new IOException("bufferedReader is null");
        }

        decodeSec2(bfReader);

        while (true) {

            char[] header = new char[LENGTH_SECTION_HEADER]; // 1 byte
            bfReader.read(header);
            String headerId = Character.toString(header[0]);

            dbgLog.fine("////////////////////// headerId=" + headerId + "//////////////////////");

            if (headerId.equals("Z")) {
                throw new IOException("reading failure: wrong headerId(Z) here");
            }

            if (headerId.equals("F")) {
                // missing value
                if ((missingValueTable != null) && (missingValueTable.size() > 0)) {
                    processMissingValueData();
                }
            }

            if (headerId.equals("8") && isCurrentVariableString) {
                headerId = "8S";
            }

            decode(headerId, bfReader);

            // for last iteration
            if (headerId.equals("F")) {
                // finished the last block (F == data) 
                // without reaching the end of this file.
                break;
            }
        }

    } finally {
        try {
            if (bfReader != null) {
                bfReader.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        if (tempPORfile.exists()) {
            tempPORfile.delete();
        }
    }

    dbgLog.fine("done parsing headers and decoding;");

    List<DataVariable> variableList = new ArrayList<>();

    for (int indx = 0; indx < variableTypelList.size(); indx++) {

        DataVariable dv = new DataVariable();
        String varName = variableNameList.get(indx);
        dv.setName(varName);
        String varLabel = variableLabelMap.get(varName);
        if (varLabel != null && varLabel.length() > 255) {
            varLabel = varLabel.substring(0, 255);
        }
        // TODO: do we still need to enforce the 255 byte limit on 
        // labels? is that enough to store whatever they have 
        // in their POR files at ODUM?
        // -- L.A. 4.0, beta11
        if (extendedLabels != null && extendedLabels.get(varName) != null) {
            dv.setLabel(extendedLabels.get(varName));
        } else {
            dv.setLabel(varLabel);
        }

        dv.setInvalidRanges(new ArrayList<>());
        dv.setSummaryStatistics(new ArrayList<>());
        dv.setUnf("UNF:6:");
        dv.setCategories(new ArrayList<>());
        dv.setFileOrder(indx);
        dv.setDataTable(dataTable);

        variableList.add(dv);

        int simpleType = 0;
        if (variableTypelList.get(indx) != null) {
            simpleType = variableTypelList.get(indx);
        }

        if (simpleType <= 0) {
            // We need to make one last type adjustment:
            // Dates and Times will be stored as character values in the 
            // dataverse tab files; even though they are not typed as 
            // strings at this point:
            // TODO: 
            // Make sure the date/time format is properly preserved!
            // (see the setFormatCategory below... but double-check!)
            // -- L.A. 4.0 alpha
            String variableFormatType = variableFormatTypeList[indx];

            if (variableFormatType != null) {
                if (variableFormatType.equals("time") || variableFormatType.equals("date")) {
                    simpleType = 1;

                    String formatCategory = formatCategoryTable.get(varName);

                    if (formatCategory != null) {
                        if (dateFormatList[indx] != null) {
                            dbgLog.fine("setting format category to " + formatCategory);
                            variableList.get(indx).setFormatCategory(formatCategory);
                            dbgLog.fine("setting formatschemaname to " + dateFormatList[indx]);
                            variableList.get(indx).setFormat(dateFormatList[indx]);
                        }
                    }
                } else if (variableFormatType.equals("other")) {
                    dbgLog.fine("Variable of format type \"other\"; type adjustment may be needed");
                    dbgLog.fine("SPSS print format: " + printFormatTable.get(variableList.get(indx).getName()));

                    if (printFormatTable.get(variableList.get(indx).getName()).equals("WKDAY")
                            || printFormatTable.get(variableList.get(indx).getName()).equals("MONTH")) {
                        // week day or month; 
                        // These are not treated as time/date values (meaning, we 
                        // don't define time/date formats for them; there's likely 
                        // no valid ISO time/date format for just a month or a day 
                        // of week). However, the
                        // values will be stored in the TAB files as strings, 
                        // and not as numerics - as they were stored in the 
                        // SAV file. So we need to adjust the type here.
                        // -- L.A. 

                        simpleType = 1;
                    }
                }
            }

        }

        dbgLog.fine("Finished creating variable " + indx + ", " + varName);

        // OK, we can now assign the types: 

        if (simpleType > 0) {
            // String: 
            variableList.get(indx).setTypeCharacter();
            variableList.get(indx).setIntervalDiscrete();
        } else {
            // Numeric: 
            variableList.get(indx).setTypeNumeric();
            // discrete or continuous?
            // "decimal variables" become dataverse data variables of interval type "continuous":

            if (decimalVariableSet.contains(indx)) {
                variableList.get(indx).setIntervalContinuous();
            } else {
                variableList.get(indx).setIntervalDiscrete();
            }

        }
        dbgLog.fine("Finished configuring variable type information.");
    }

    dbgLog.fine("done configuring variables;");

    /* 
     * From the original (3.6) code: 
    //smd.setVariableTypeMinimal(ArrayUtils.toPrimitive(variableTypelList.toArray(new Integer[variableTypelList.size()])));
    smd.setVariableFormat(printFormatList);
    smd.setVariableFormatName(printFormatNameTable);
    smd.setVariableFormatCategory(formatCategoryTable);
    smd.setValueLabelMappingTable(valueVariableMappingTable);
     * TODO: 
     * double-check that it's all being taken care of by the new plugin!
     * (for variable format and formatName, consult the SAV plugin)
     */

    dataTable.setDataVariables(variableList);

    // Assign value labels: 

    assignValueLabels(valueLabelTable);

    ingesteddata.setDataTable(dataTable);

    dbgLog.info("PORFileReader: read() end");
    return ingesteddata;
}

From source file:org.camera.service.CAMERARESTService.java

/**
 * This method returns the appender that will be added to this
 * actors display name. It gets the appender from the actors name
 * that is taken care by kepler when multiple instances of the actor
 * are added on the canvas.//from   w w w.  j av  a  2s .co m
 *  
 *     */
private String getAppender() {
    String actorName = getName();
    char c1 = actorName.charAt(actorName.length() - 1);
    System.out.println("Character 1: " + Character.toString(c1));
    char c2 = actorName.charAt(actorName.length() - 2);
    System.out.println("Character 2: " + Character.toString(c2));
    boolean check2 = false;
    boolean check1 = false;
    StringBuilder tmp = new StringBuilder("");
    if (c2 > 47 && c2 < 58) {
        check2 = true;
    }
    if (c1 > 47 && c1 < 58) {
        check1 = true;
    }
    if (check1 && check2) {
        return tmp.append(c2).append(c1).toString();
    } else if (check1) {
        return tmp.append(c1).toString();
    }
    return "";
}

From source file:com.money.manager.ex.fragment.AllDataFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    //if (item.getGroupId() == getContextMenuGroupId())
    // take a info of the selected menu, and cursor at position
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    // check if cursor is valid
    if (cursor != null) {
        switch (item.getItemId()) {
        case R.id.menu_delete:
            showDialogDeleteCheckingAccount(
                    new int[] { cursor.getInt(cursor.getColumnIndex(QueryAllData.ID)) });
            return true;
        case R.id.menu_none:
        case R.id.menu_reconciled:
        case R.id.menu_follow_up:
        case R.id.menu_duplicate:
        case R.id.menu_void:
            String status = Character.toString(item.getAlphabeticShortcut());
            if (setStatusCheckingAccount(cursor.getInt(cursor.getColumnIndex(QueryAllData.ID)), status)) {
                startLoaderData();//from  ww  w  .j  a  v  a  2 s .  c  om
                return true;
            }
        }
    }
    return false;
}

From source file:org.acmsl.commons.utils.ConversionUtils.java

/**
 * Converts given String to char.//from  w  w w  .  j  a  v  a2 s .c  o m
 * @param value the value to convert.
 * @return the converted value.
 */
public char toChar(@Nullable final String value) {
    char result = (char) -1;

    @Nullable
    final Character t_Result = toCharIfNotNull(value);

    if (t_Result != null) {
        result = t_Result.charValue();
    }

    if ((value == null) || (!value.equals(Character.toString(result)))) {
        result = (char) -1;
    }

    return result;
}

From source file:com.xmlcalabash.util.JSONtoXML.java

private static void serializeMarkLogic(TreeWriter tree, Object json, String name) {
    String localName = "item";
    if (name != null) {
        if ("".equals(name)) {
            localName = "_";
        } else {/*from ww w  .ja va2s.  co m*/
            localName = "";
            for (int pos = 0; pos < name.length(); pos++) {
                int ch = name.charAt(pos);
                if ('_' != ch && ((pos == 0 && XMLCharacterData.isNCNameStart10(ch))
                        || (pos > 0 && XMLCharacterData.isNCName10(ch)))) {
                    localName += Character.toString((char) ch);
                } else {
                    localName += String.format("_%04x", ch);
                }
            }
        }
    }

    QName elemName = new QName("j", MLJS_NS, localName);
    tree.addStartElement(elemName);

    if (json instanceof JSONObject) {
        tree.addAttribute(_type, "object");
        tree.startContent();
        buildMarkLogicPairs(tree, (JSONObject) json);
    } else if (json instanceof JSONArray) {
        tree.addAttribute(_type, "array");
        tree.startContent();
        buildMarkLogicArray(tree, (JSONArray) json);
    } else if (json instanceof Integer || json instanceof Double || json instanceof Long) {
        tree.addAttribute(_type, "number");
        tree.startContent();
        tree.addText(json.toString());
    } else if (json instanceof String) {
        tree.addAttribute(_type, "string");
        tree.startContent();
        tree.addText(json.toString());
    } else if (json instanceof Boolean) {
        tree.addAttribute(_type, "boolean");
        tree.startContent();
        tree.addText(json.toString());
    } else if (json == JSONObject.NULL) {
        tree.addAttribute(_type, "null");
        tree.startContent();
    } else {
        throw new XProcException("Unexpected type in JSON conversion.");
    }

    tree.addEndElement();
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.por.PORFileReader.java

/**
 * Read the given SPSS POR-format file via a <code>BufferedInputStream</code>
 * object.  This method calls an appropriate method associated with the given 
 * field header by reflection.//from   w ww .j a  v  a2 s  . com
 * 
 * @param stream a <code>BufferedInputStream</code>.
 * @return an <code>SDIOData</code> object
 * @throws java.io.IOException if an reading error occurs.
 */
@Override
public SDIOData read(BufferedInputStream stream, File dataFile) throws IOException {

    if (dataFile != null) {
        throw new IOException("this plugin does not support external raw data files");
    }

    File tempPORfile = decodeHeader(stream);
    BufferedReader bfReader = null;

    try {
        bfReader = new BufferedReader(
                new InputStreamReader(new FileInputStream(tempPORfile.getAbsolutePath()), "US-ASCII"));
        if (bfReader == null) {
            dbgLog.fine("bfReader is null");
            throw new IOException("bufferedReader is null");
        }

        decodeSec2(bfReader);

        while (true) {

            char[] header = new char[LENGTH_SECTION_HEADER]; // 1 byte
            bfReader.read(header);
            String headerId = Character.toString(header[0]);

            dbgLog.fine("////////////////////// headerId=" + headerId + "//////////////////////");

            if (headerId.equals("Z")) {
                throw new IOException("reading failure: wrong headerId(Z) here");
            }

            if (headerId.equals("F")) {
                // missing value
                if ((missingValueTable != null) && (missingValueTable.size() > 0)) {
                    processMissingValueData();
                }
            }

            if (headerId.equals("8") && isCurrentVariableString) {
                headerId = "8S";
            }

            decode(headerId, bfReader);

            // for last iteration
            if (headerId.equals("F")) {
                // finished the last block (F == data) 
                // without reaching the end of this file.
                break;
            }
        }

        // post-parsing processing
        // save metadata to smd 
        // varialbe Name

        smd.setVariableName(variableNameList.toArray(new String[variableNameList.size()]));
        smd.setVariableLabel(variableLabelMap);
        smd.setMissingValueTable(missingValueTable);
        dbgLog.finer("*************** missingValueCodeTable ***************:\n" + missingValueCodeTable);
        smd.setInvalidDataTable(invalidDataTable);
        smd.setValueLabelTable(valueLabelTable);
        /* Final correction of the "variable type list" values: 
         * The date/time values are stored as character strings by the DVN, 
         * so the type information needs to be adjusted accordingly:
         *          -- L.A., v3.6 
         */
        int[] variableTypeMinimal = ArrayUtils
                .toPrimitive(variableTypelList.toArray(new Integer[variableTypelList.size()]));

        for (int indx = 0; indx < variableTypelList.size(); indx++) {
            int simpleType = 0;
            if (variableTypelList.get(indx) != null) {
                simpleType = variableTypelList.get(indx).intValue();
            }

            if (simpleType <= 0) {
                // NOT marked as a numeric at this point;
                // but is it a date/time/etc.?
                String variableFormatType = variableFormatTypeList[indx];
                if (variableFormatType != null
                        && (variableFormatType.equals("time") || variableFormatType.equals("date"))) {
                    variableTypeMinimal[indx] = 1;
                }
            }
        }

        smd.setVariableTypeMinimal(variableTypeMinimal);

        //smd.setVariableTypeMinimal(ArrayUtils.toPrimitive(variableTypelList.toArray(new Integer[variableTypelList.size()])));
        smd.setVariableFormat(printFormatList);
        smd.setVariableFormatName(printFormatNameTable);
        smd.setVariableFormatCategory(formatCategoryTable);
        smd.setValueLabelMappingTable(valueVariableMappingTable);

    } finally {
        try {
            if (bfReader != null) {
                bfReader.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        if (tempPORfile.exists()) {
            tempPORfile.delete();
        }
    }

    dbgLog.info("***** PORFileReader: read() end *****");
    return new SDIOData(smd, porDataSection);
}

From source file:com.exploringspatial.job.AcladLoaderJob.java

private String parseUnicode(final String s) {
    String u = null;//from ww  w  .j a va  2 s.co m
    if (s != null) {
        final String unknown = Character.toString((char) 65533);
        u = s.replaceAll(unknown, "");
        // Strip ? \ / : | < > * " linefeed return
        u = u.replaceAll("[\\?\\\\/:|<>\\*\"\n\r]", "");
    }
    return u;
}