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:ml.shifu.shifu.core.binning.EqualPopulationBinning.java

public String objToString() {
    List<String> histogramStrList = new ArrayList<String>();

    if (this.header != null) {
        LinkNode<HistogramUnit> tmp = this.header;
        while (tmp != null) {
            histogramStrList.add(tmp.data().objToString());
            tmp = tmp.next();/* w w w .  ja va 2s .c  o m*/
        }
    }

    return super.objToString() + Character.toString(FIELD_SEPARATOR) + Integer.toString(maxHistogramUnitCnt)
            + Character.toString(FIELD_SEPARATOR) + StringUtils.join(histogramStrList, SETLIST_SEPARATOR);
}

From source file:io.manasobi.utils.StringUtils.java

/**
 * camel case ? ?? underscore ? ? <br><br>
 *
 * StringUtils.convertToUnderScore("anyframeJavaTest") = "anyframe_java_test"
 *
 * @param camelCase  camel case ? ?/*  www .  j av a  2 s . co m*/
 * @return underscore  ? ?
 */
public static String convertToUnderScore(String camelCase) {
    String result = "";
    for (int i = 0; i < camelCase.length(); i++) {
        char currentChar = camelCase.charAt(i);
        // This is starting at 1 so the result does not end up with an
        // underscore at the begin of the value
        if (i > 0 && Character.isUpperCase(currentChar)) {
            result = result.concat("_");
        }
        result = result.concat(Character.toString(currentChar).toLowerCase());
    }
    return result;
}

From source file:org.exoplatform.social.core.storage.impl.SpaceStorageImpl.java

private void _applyFilter(WhereExpression whereExpression, SpaceFilter spaceFilter) {

    String spaceNameSearchCondition = spaceFilter.getSpaceNameSearchCondition();
    char firstCharacterOfName = spaceFilter.getFirstCharacterOfSpaceName();

    if (spaceNameSearchCondition != null && spaceNameSearchCondition.length() != 0) {
        if (this.isValidInput(spaceNameSearchCondition)) {

            spaceNameSearchCondition = this.processSearchCondition(spaceNameSearchCondition);

            if (spaceNameSearchCondition.contains(StorageUtils.PERCENT_STR)) {
                whereExpression.startGroup();
                whereExpression.like(SpaceEntity.name, spaceNameSearchCondition).or()
                        .like(SpaceEntity.description, spaceNameSearchCondition);
                whereExpression.endGroup();
            } else {
                whereExpression.startGroup();
                whereExpression.contains(SpaceEntity.name, spaceNameSearchCondition).or()
                        .contains(SpaceEntity.description, spaceNameSearchCondition);
                whereExpression.endGroup();
            }//from  www. j  a  va 2  s  .co m
        }
    } else if (!Character.isDigit(firstCharacterOfName)) {
        String firstCharacterOfNameString = Character.toString(firstCharacterOfName);
        String firstCharacterOfNameLowerCase = firstCharacterOfNameString.toLowerCase()
                + StorageUtils.PERCENT_STR;
        whereExpression.like(whereExpression.callFunction(QueryFunction.LOWER, SpaceEntity.name),
                firstCharacterOfNameLowerCase);
    }
}

From source file:org.apache.phoenix.schema.stats.BaseStatsCollectorIT.java

private void testCompactUpdatesStats(Integer statsUpdateFreq, String tableName) throws Exception {
    int nRows = 10;
    Connection conn = getConnection(statsUpdateFreq);
    PreparedStatement stmt;//from w w w .  j a v a2s.  c om
    conn.createStatement()
            .execute("CREATE TABLE " + tableName + "(k CHAR(1) PRIMARY KEY, v INTEGER, w INTEGER) "
                    + (!tableDDLOptions.isEmpty() ? tableDDLOptions + "," : "")
                    + ColumnFamilyDescriptorBuilder.KEEP_DELETED_CELLS + "=" + Boolean.FALSE);
    stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(?,?,?)");
    for (int i = 0; i < nRows; i++) {
        stmt.setString(1, Character.toString((char) ('a' + i)));
        stmt.setInt(2, i);
        stmt.setInt(3, i);
        stmt.executeUpdate();
    }
    conn.commit();

    TestUtil.doMajorCompaction(conn, physicalTableName);

    if (statsUpdateFreq != 0) {
        invalidateStats(conn, tableName);
    } else {
        // Confirm that when we have a non zero STATS_UPDATE_FREQ_MS_ATTRIB, after we run
        // UPDATATE STATISTICS, the new statistics are faulted in as expected.
        List<KeyRange> keyRanges = getAllSplits(conn, tableName);
        assertNotEquals(nRows + 1, keyRanges.size());
        // If we've set MIN_STATS_UPDATE_FREQ_MS_ATTRIB, an UPDATE STATISTICS will invalidate the cache
        // and forcing the new stats to be pulled over.
        int rowCount = conn.createStatement().executeUpdate("UPDATE STATISTICS " + tableName);
        assertEquals(10, rowCount);
    }
    List<KeyRange> keyRanges = getAllSplits(conn, tableName);
    assertEquals(nRows + 1, keyRanges.size());

    int nDeletedRows = conn.createStatement()
            .executeUpdate("DELETE FROM " + tableName + " WHERE V < " + nRows / 2);
    conn.commit();
    assertEquals(5, nDeletedRows);

    Scan scan = new Scan();
    scan.setRaw(true);
    PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
    try (Table htable = phxConn.getQueryServices().getTable(Bytes.toBytes(tableName))) {
        ResultScanner scanner = htable.getScanner(scan);
        Result result;
        while ((result = scanner.next()) != null) {
            System.out.println(result);
        }
    }

    TestUtil.doMajorCompaction(conn, physicalTableName);

    scan = new Scan();
    scan.setRaw(true);
    phxConn = conn.unwrap(PhoenixConnection.class);
    try (Table htable = phxConn.getQueryServices().getTable(Bytes.toBytes(tableName))) {
        ResultScanner scanner = htable.getScanner(scan);
        Result result;
        while ((result = scanner.next()) != null) {
            System.out.println(result);
        }
    }

    if (statsUpdateFreq != 0) {
        invalidateStats(conn, tableName);
    } else {
        assertEquals(nRows + 1, keyRanges.size());
        // If we've set STATS_UPDATE_FREQ_MS_ATTRIB, an UPDATE STATISTICS will invalidate the cache
        // and force us to pull over the new stats
        int rowCount = conn.createStatement().executeUpdate("UPDATE STATISTICS " + tableName);
        assertEquals(5, rowCount);
    }
    keyRanges = getAllSplits(conn, tableName);
    assertEquals(nRows / 2 + 1, keyRanges.size());
    ResultSet rs = conn.createStatement()
            .executeQuery("SELECT SUM(GUIDE_POSTS_ROW_COUNT) FROM " + "\"" + SYSTEM_CATALOG_SCHEMA + "\".\""
                    + SYSTEM_STATS_TABLE + "\"" + " WHERE PHYSICAL_NAME='" + physicalTableName + "'");
    rs.next();
    assertEquals(nRows - nDeletedRows, rs.getLong(1));
}

From source file:com.tesora.dve.sql.parser.InvokeParser.java

public static PlanningResult buildPlan(SchemaContext pc, byte[] line, Charset cs, String pstmtID)
        throws PEException {
    boolean isPrepare = (pstmtID != null);
    if (pc != null)
        SchemaContext.threadContext.set(pc);
    preparse(pc);//from  w w  w .j a  v a 2s .c  om
    ParserOptions options = ParserOptions.NONE.setDebugLog(true).setResolve().setFailEarly();
    if (isPrepare)
        options = options.setPrepare().setActualLiterals();

    PlanningResult result = null;

    String lineStr = PECharsetUtils.getString(line, cs, true);
    if (lineStr == null) {
        // bad characters - not a candidate for caching
        // if we get this for a prepared stmt, just give up for now
        if (isPrepare)
            throw new PEException("Invalid prepare request: bad characters");
        ParseResult pr = parameterizeAndParse(pc, options, line, cs);
        List<Statement> stmts = pr.getStatements();
        List<ExecutionPlan> plans = new ArrayList<ExecutionPlan>();
        ConnectionValuesMap cvm = new ConnectionValuesMap();
        for (Statement s : stmts) {
            PlanningResult epr = Statement.getExecutionPlan(pc, s, pc.getBehaviorConfiguration(), lineStr,
                    pr.getInputState());
            plans.addAll(epr.getPlans());
            cvm.take(epr.getValues());
        }
        result = new PlanningResult(plans, cvm, pr.getInputState(), lineStr);
    } else {
        lineStr = StringUtils.strip(lineStr, new String(Character.toString(Character.MIN_VALUE)));

        logParse(pc, lineStr, pstmtID);

        InputState input = buildInputState(lineStr, pc);

        if (isPrepare) {
            if (input.getCommand() == null)
                throw new PEException(
                        "Prepare stmt is too long (greater than " + input.getThreshold() + " characters)");
            result = preparePlan(pc, input, options, pstmtID);
        } else
            result = buildPlan(pc, input, options, null);
    }
    for (ExecutionPlan ep : result.getPlans())
        if (ep.isRoot()) {
            SqlStatistics.incrementCounter(((RootExecutionPlan) ep).getStatementType());
        }
    return result;
}

From source file:org.ednovo.gooru.domain.service.classplan.LearnguideServiceImpl.java

@Override
public String updateCollectionThumbnail(String gooruContentId, String fileName, String imageURL,
        Map<String, Object> formField) throws Exception {
    boolean isHasSlash = StringUtils.contains(fileName, '\\');

    if (isHasSlash) {
        fileName = StringUtils.substringAfterLast(fileName, Character.toString('\\'));
    }/*from   w w  w . j a va 2 s.c  om*/

    Learnguide collection = this.getLearnguideRepository().findByContent(gooruContentId);
    boolean buildThumbnail = false;

    if (imageURL != null && imageURL.length() > 0) {
        String resourceImageFile = collection.getOrganization().getNfsStorageArea().getInternalPath()
                + collection.getFolder() + "/" + fileName;
        String prevFileName = collection.getThumbnail();
        if (prevFileName != null && !prevFileName.equalsIgnoreCase("")) {
            File prevFile = new File(collection.getOrganization().getNfsStorageArea().getInternalPath()
                    + collection.getFolder() + "/" + prevFileName);
            if (prevFile.exists()) {
                prevFile.delete();
            }
            s3ResourceApiHandler.deleteResourceFile(collection, collection.getThumbnail());
        }
        ImageUtil.downloadAndSaveFile(imageURL, resourceImageFile);
        collection.setThumbnail(fileName);
        buildThumbnail = true;
        logger.info("Thumbnail downloader:Resource " + collection.getGooruOid()
                + " didn't have image. downloading into " + resourceImageFile);
    } else {
        File classplanDir = new File(
                collection.getOrganization().getNfsStorageArea().getInternalPath() + collection.getFolder());

        if (!classplanDir.exists()) {
            classplanDir.mkdirs();
        }

        Map<String, byte[]> files = (Map<String, byte[]>) formField.get(RequestUtil.UPLOADED_FILE_KEY);

        byte[] fileData = null;

        // expecting only one file in the request right now
        for (byte[] fileContent : files.values()) {
            fileData = fileContent;
        }
        if (fileData != null && fileData.length > 0) {

            String prevFileName = collection.getThumbnail();

            if (prevFileName != null && !prevFileName.equalsIgnoreCase("")) {
                File prevFile = new File(collection.getOrganization().getNfsStorageArea().getInternalPath()
                        + collection.getFolder() + "/" + prevFileName);
                if (prevFile.exists()) {
                    prevFile.delete();
                }
            }

            File file = new File(collection.getOrganization().getNfsStorageArea().getInternalPath()
                    + collection.getFolder() + "/" + fileName);

            OutputStream out = new FileOutputStream(file);
            out.write(fileData);
            out.close();

            collection.setThumbnail(fileName);
            buildThumbnail = true;
        }
    }

    this.getLearnguideRepository().save(collection);
    if (buildThumbnail) {
        resourceImageUtil.sendMsgToGenerateThumbnails(collection);
    }
    indexProcessor.index(collection.getGooruOid(), IndexProcessor.INDEX, COLLECTION);

    // Remove the collection from cache
    collectionUtil.deleteCollectionFromCache(gooruContentId, COLLECTION);

    return collection.getFolder() + "/" + fileName;
}

From source file:com.virtusa.akura.student.controller.StudentParentController.java

/**
 * handle request for view the parent information.
 * //from w w w.j a  va2  s  .  c  om
 * @param parentWrapper command object
 * @param model to hold model attributes.
 * @param session session
 * @param request request
 * @return view name
 * @throws AkuraAppException when exception occurs
 */
@RequestMapping(value = REQ_MAP_VALUE_ADMIN_PARENT)
public String showParentDetailAdminPanel(@ModelAttribute(PARENT_WRAPPER) ParentWrapper parentWrapper,
        ModelMap model, HttpSession session, HttpServletRequest request) throws AkuraAppException {

    Integer studentId = (Integer) session.getAttribute(STUDENT_ID);

    if (studentId != null) {

        // user requesting a relation F= father M= mother G=guardian
        String relationship = request.getParameter(SELECTED_RELATIONSHIP);

        if (relationship == null || relationship.isEmpty()) {

            // if user did not specify relation type, get available parent
            // info if any. first father then guardian or mother .
            List<StudentParent> listSP = parentService.getStudentParentListByStudentId(studentId);

            if (listSP != null && !listSP.isEmpty()) {

                for (StudentParent studentParentObj : listSP) {

                    if (studentParentObj.getRelationship() == FATHER_CHAR) {
                        parentWrapper.setRelationship(FATHER_STRING);
                        parentWrapper.setParent(studentParentObj.getParent());
                        break;

                    } else if (studentParentObj.getRelationship() == GUARDIAN_CHAR) {
                        parentWrapper.setRelationship(GUARDIAN_STRING);
                        parentWrapper.setParent(studentParentObj.getParent());

                    } else if (studentParentObj.getRelationship() == MOTHER_CHAR) {
                        parentWrapper.setRelationship(MOTHER_STRING);
                        parentWrapper.setParent(studentParentObj.getParent());
                    }
                }
            } else {// no any parent info found , empty parent object
                parentWrapper.setRelationship(FATHER_STRING);
                parentWrapper.setParent(new Parent());

            }
        } else {// user requesting parent with specific relation
            char relation = relationship.charAt(0);
            parentWrapper.setRelationship(Character.toString(relation));

            List<StudentParent> list = parentService.getParentListBy(studentId, relation);
            if (list != null && !list.isEmpty()) {
                parentWrapper.setParent(list.get(0).getParent());

            } else {// requested parent is empty;
                parentWrapper.setParent(new Parent());
            }
        }
        setDonationListToModel(studentId, model);
    }
    setupStudentRatingDetails(model, session);
    displayPhoneNumberDetails(parentWrapper.getParent(), model);
    return VIEW_PARENT;
}

From source file:edu.stanford.muse.xword.Crossword.java

public String toHTMLString(boolean printAnswers) {
    StringBuilder sb = new StringBuilder();
    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            char c = box[i][j];
            String s = "_", css_class = "empty";
            if (c == EMPTY)
                css_class = "empty";
            else if (c == STOP)
                css_class = "stop";
            else {
                s = printAnswers ? Character.toString(c) : "_";
                css_class = "letter";
            }//from w  ww .ja va 2s.  co m
            String clueNumSpan = "";
            if (clueNums[i][j] != 0)
                clueNumSpan = "<span class=\"cluenum-in-box\">" + clueNums[i][j] + "</span>";
            sb.append("<div class=\"box " + css_class + "\">" + clueNumSpan + s + "</div>");
        }
        sb.append("<div class=\"endRow\"></div>");
    }
    return sb.toString();
}

From source file:org.apache.phoenix.end2end.BasePermissionsIT.java

AccessTestAction readMultiTenantTableWithoutIndex(final String tableName, final String tenantId)
        throws SQLException {
    return new AccessTestAction() {
        @Override/*from   ww w  . jav  a2  s.com*/
        public Object run() throws Exception {
            try (Connection conn = getConnection(tenantId); Statement stmt = conn.createStatement()) {
                // Accessing all the data from the table avoids the use of index
                String readTableSQL = "SELECT data, val FROM " + tableName;
                ResultSet rs = stmt.executeQuery(readTableSQL);
                assertNotNull(rs);
                int i = 0;
                String explainPlan = Joiner.on(" ")
                        .join(((PhoenixStatement) stmt).getQueryPlan().getExplainPlan().getPlanSteps());
                rs = stmt.executeQuery(readTableSQL);
                if (tenantId != null) {
                    rs.next();
                    assertFalse(explainPlan.contains("_IDX_"));
                    assertEquals(((PhoenixConnection) conn).getTenantId().toString(), tenantId);
                    // For tenant ID "o3", the value in table will be 3
                    assertEquals(Character.toString(tenantId.charAt(1)), rs.getString(1));
                    // Only 1 record is inserted per Tenant
                    assertFalse(rs.next());
                } else {
                    while (rs.next()) {
                        assertEquals(Integer.toString(i), rs.getString(1));
                        assertEquals(i, rs.getInt(2));
                        i++;
                    }
                    assertEquals(NUM_RECORDS, i);
                }
            }
            return null;
        }
    };
}