Example usage for java.lang CharSequence toString

List of usage examples for java.lang CharSequence toString

Introduction

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

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:com.heliosapm.mws.server.net.json.JSONRequest.java

/**
 * Returns an error {@link JSONResponse} for this request
 * @param message The error message to send
 * @param t The exception to render in the error message. Ignored if null.
 * @return an error {@link JSONResponse} for this request
 *//* ww  w . j av  a  2  s.  co  m*/
public JSONResponse error(CharSequence message, Throwable t) {
    JSONResponse response = new JSONResponse(requestId, ResponseType.ERR, channel, this);
    Map<String, String> map = new HashMap<String, String>(t == null ? 1 : 2);
    map.put("err", message.toString());
    if (t != null) {
        map.put("ex", StringHelper.formatStackTrace(t));
    }
    response.setContent(map);
    return response;
}

From source file:de.schildbach.pte.NegentweeProvider.java

@Override
public SuggestLocationsResult suggestLocations(CharSequence constraint) throws IOException {
    HttpUrl url = buildApiUrl("locations", Arrays.asList(new QueryParameter("q", constraint.toString())));
    final CharSequence page;
    try {/*from  w ww  .  ja v a 2s .  co m*/
        page = httpClient.get(url);
    } catch (InternalErrorException e) {
        return new SuggestLocationsResult(this.resultHeader, SuggestLocationsResult.Status.SERVICE_DOWN);
    }

    final List<SuggestedLocation> foundLocations = new ArrayList<>();
    try {
        final JSONObject head = new JSONObject(page.toString());
        final JSONArray locations = head.optJSONArray("locations");

        if (head.has("error")) {
            return new SuggestLocationsResult(this.resultHeader, SuggestLocationsResult.Status.SERVICE_DOWN);
        }

        for (int i = 0; i < locations.length(); i++) {
            JSONObject location = locations.getJSONObject(i);

            foundLocations.add(new SuggestedLocation(locationFromJSONObject(location)));
        }
    } catch (final JSONException x) {
        throw new RuntimeException("cannot parse: '" + page + "' on " + url, x);
    }

    return new SuggestLocationsResult(this.resultHeader, foundLocations);
}

From source file:com.cyberway.issue.crawler.extractor.ExtractorHTML.java

/**
 * Handle generic HREF cases./* w w  w . j a va 2  s . c  om*/
 * 
 * @param curi
 * @param value
 * @param context
 */
protected void processLink(CrawlURI curi, final CharSequence value, CharSequence context) {
    if (TextUtils.matches(JAVASCRIPT, value) || TextUtils.matches(JAVASCRIPT2, value)) {
        processScriptCode(curi, value.subSequence(11, value.length()));
    } else {
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("link: " + value.toString() + " from " + curi);
        }
        addLinkFromString(curi, (value instanceof String) ? (String) value : value.toString(), context,
                Link.NAVLINK_HOP);
        this.numberOfLinksExtracted++;
    }
}

From source file:eu.edisonproject.training.wsd.BabelNet.java

private void addToEdgesDB(CharSequence id, String jsonString) throws IOException {
    List<String> families = new ArrayList<>();
    families.add("jsonString");
    DBTools.createOrUpdateTable(EDGES_TBL_NAME, families, false);

    try (Admin admin = DBTools.getConn().getAdmin()) {
        try (Table tbl = DBTools.getConn().getTable(EDGES_TBL_NAME)) {
            Put put = new Put(Bytes.toBytes(id.toString()));
            put.addColumn(Bytes.toBytes("jsonString"), Bytes.toBytes("jsonString"), Bytes.toBytes(jsonString));
            tbl.put(put);//from   www . java  2  s  . co m
        }
        admin.flush(EDGES_TBL_NAME);
    }
}

From source file:com.cloverstudio.spika.MyProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        params.copyFrom(window.getAttributes());
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);/*from ww  w.jav  a2s  .c o  m*/

        final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery);
        btnGallery.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera);
        btnCamera.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto);
        btnRemovePhoto.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnRemovePhoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mNewAvatarId = "";
                gProfileImage = null;
                Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
                        R.drawable.user_stub_large, false);
                mGetImageDialog.dismiss();

            }
        });

        return mGetImageDialog;
    case GET_BIRTHDAY_DIALOG:

        int intMaxYear = Calendar.getInstance().get(Calendar.YEAR);
        int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH);
        int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time chosenDate = new Time();
                chosenDate.set(dayOfMonth, monthOfYear, year);
                mNewBirthday = chosenDate.toMillis(true) / 1000;
                CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format),
                        chosenDate.toMillis(true));
                mEtUserBirthday.setText(stringDate.toString());
            }
        }, intMaxYear, intMaxMonth, intMaxDay);
        mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday));
        return mGetBirthdayDialog;
    default:
        return null;
    }
}

From source file:info.hl.mediam.MyProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        params.copyFrom(window.getAttributes());
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);//from  w  ww . j  a  v  a  2  s.com

        final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery);
        btnGallery.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera);
        btnCamera.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto);
        btnRemovePhoto.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnRemovePhoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mNewAvatarId = "";
                gProfileImage = null;
                Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
                        R.drawable.user_stub_large, false);
                mGetImageDialog.dismiss();

            }
        });

        return mGetImageDialog;
    case GET_BIRTHDAY_DIALOG:

        int intMaxYear = Calendar.getInstance().get(Calendar.YEAR);
        int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH);
        int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time chosenDate = new Time();
                chosenDate.set(dayOfMonth, monthOfYear, year);
                mNewBirthday = chosenDate.toMillis(true) / 1000;
                CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format),
                        chosenDate.toMillis(true));
                mEtUserBirthday.setText(stringDate.toString());
            }
        }, intMaxYear, intMaxMonth, intMaxDay);
        mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday));
        return mGetBirthdayDialog;
    default:
        return null;
    }
}

From source file:com.cyberway.issue.crawler.extractor.ExtractorHTML.java

private void addLinkFromString(CrawlURI curi, String uri, CharSequence context, char hopType) {
    try {//from  w  w  w  .  ja v a 2  s.  c  o m
        // We do a 'toString' on context because its a sequence from
        // the underlying ReplayCharSequence and the link its about
        // to become a part of is expected to outlive the current
        // ReplayCharSequence.
        curi.createAndAddLinkRelativeToBase(uri, context.toString(), hopType);
    } catch (URIException e) {
        if (getController() != null) {
            getController().logUriError(e, curi.getUURI(), uri);
        } else {
            logger.info("Failed createAndAddLinkRelativeToBase " + curi + ", " + uri + ", " + context + ", "
                    + hopType + ": " + e);
        }
    }
}

From source file:de.schildbach.pte.AbstractTsiProvider.java

@Override
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
    final HttpUrl.Builder url = stopFinderEndpoint.newBuilder().addPathSegments("SearchTripPoint/json");
    appendCommonRequestParams(url);/*  w  ww  .j  a  v  a2s.c o  m*/
    url.addQueryParameter("MaxItems", "50"); // XXX good value?
    url.addQueryParameter("Keywords", constraint.toString());

    final CharSequence page = httpClient.get(url.build());
    try {
        final List<SuggestedLocation> locations = new ArrayList<>();
        final JSONObject head = new JSONObject(page.toString());

        final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);

        final int status = head.getInt("StatusCode");

        if (status != 200)
            return new SuggestLocationsResult(header, SuggestLocationsResult.Status.SERVICE_DOWN);

        JSONArray dataArray = head.getJSONArray("Data");
        for (int i = 0; i < dataArray.length(); i++) {
            JSONObject data = dataArray.getJSONObject(i);
            final Location location = parseJsonTransportLocation(data);

            if (location.isIdentified()) // make sure the location is really identified
                // some addresses may not contain coordinates, we ignore them
                locations.add(new SuggestedLocation(location));
        }

        return new SuggestLocationsResult(header, locations);
    } catch (final JSONException x) {
        throw new ParserException(x);
    }
}

From source file:com.safi.workshop.sqlexplorer.parsers.BasicQueryParser.java

/**
 * Gets the next query, or returns null if there are no more
 * //from   w  w  w.j  av  a2s  .  c o  m
 * @return
 */
private BasicQuery getNextQuery() {
    if (charIndex >= sql.length())
        return null;

    int start = charIndex;
    int startOfLine = -1;
    char cQuote = 0;
    boolean inSLComment = false;
    boolean inMLComment = false;
    int startLineNo = -1;
    for (; charIndex < sql.length(); charIndex++) {
        char c = sql.charAt(charIndex);
        char nextC = 0;
        if (charIndex < sql.length() - 1)
            nextC = sql.charAt(charIndex + 1);

        // Skip comments
        if (inSLComment) {
            if (c == '\n') {
                inSLComment = false;
            } else {
                continue;
            }
        }
        if (inMLComment) {
            if (c == '\n') {
                startOfLine = -1;
                lineNo++;
            }
            inMLComment = !nextIs(mlCommentEnd);
            continue;
        }
        // If we're quoting
        if (cQuote != 0) {
            if (c == quoteEscapes && QUOTE_CHARS.indexOf(nextC) > -1)
                charIndex++;
            else if (cQuote == c)
                cQuote = 0;
            continue;
        }

        // Skip leading whitespace
        if (start == charIndex && Character.isWhitespace(c)) {
            start++;
            if (c == '\n') {
                startOfLine = -1;
                lineNo++;
            }
            continue;
        }
        // Calculate the start of line (gets reset to -1 on every \n)
        if (startOfLine < 0 && !Character.isWhitespace(c))
            startOfLine = charIndex;

        if (cmdSeparator != null && nextIs(cmdSeparator)) {
            int oldCharIndex = charIndex;
            charIndex += cmdSeparator.length();
            if (startLineNo < 0 || start + cmdSeparator.length() >= oldCharIndex) {
                start = charIndex;
                startLineNo = -1;
                startOfLine = -1;
                continue;
            }
            CharSequence qry = sql.subSequence(start, oldCharIndex);
            Set<com.safi.workshop.sqlexplorer.parsers.QueryParameter> parms = null;
            try {
                parms = parseArgs(qry.toString());
            } catch (ParserException e) {
                e.printStackTrace();
                MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Parse Param Error",
                        "Error caught while parsing parameters: " + e.getLocalizedMessage());
                return null;
            }

            BasicQuery bq = new BasicQuery(qry, startLineNo);
            bq.setQueryParameters((LinkedHashSet<com.safi.workshop.sqlexplorer.parsers.QueryParameter>) parms);
            return bq;
            // return new BasicQuery(sql.subSequence(start, oldCharIndex), startLineNo);
        }
        // Starting a quote?
        if (QUOTE_CHARS.indexOf(c) > -1) {
            cQuote = c;
            continue;
        }

        // Newlines - count line numbers, and look for "GO" (or equivelant)
        if (c == '\n') {
            if (rangeIs(startOfLine, charIndex, altSeparator)) {
                if (startLineNo < 0 || start + altSeparator.length() >= startOfLine) {
                    start = charIndex + 1;
                    startLineNo = -1;
                    startOfLine = -1;
                    lineNo++;
                    continue;
                }

                CharSequence qry = sql.subSequence(start, startOfLine);
                Set<com.safi.workshop.sqlexplorer.parsers.QueryParameter> parms = null;
                try {
                    parms = parseArgs(qry.toString());
                } catch (ParserException e) {
                    e.printStackTrace();
                    MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Parse Param Error",
                            "Error caught while parsing parameters: " + e.getLocalizedMessage());
                    return null;
                }

                BasicQuery bq = new BasicQuery(qry, startLineNo);
                bq.setQueryParameters(
                        (LinkedHashSet<com.safi.workshop.sqlexplorer.parsers.QueryParameter>) parms);
                return bq;
            }
            if (startOfLine >= 0) {
                String lineStart = sql.subSequence(startOfLine, Math.min(charIndex, startOfLine + 15))
                        .toString().toLowerCase();
                if (lineStart.startsWith("delimiter")) {
                    String delimiter = lineStart.substring(9).trim();
                    if (delimiter.length() == 1) {
                        setCmdSeparator(delimiter);
                        setAltSeparator(null);
                    } else {
                        setCmdSeparator(new String(new byte[] { 0 }));
                        setAltSeparator(delimiter);
                    }
                    if (startLineNo < 0 || start + lineStart.length() >= startOfLine) {
                        start = charIndex + 1;
                        startLineNo = -1;
                        startOfLine = -1;
                        lineNo++;
                        continue;
                    }

                    CharSequence qry = sql.subSequence(start, startOfLine);
                    Set<com.safi.workshop.sqlexplorer.parsers.QueryParameter> parms = null;
                    try {
                        parms = parseArgs(qry.toString());
                    } catch (ParserException e) {
                        e.printStackTrace();
                        MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Parse Param Error",
                                "Error caught while parsing parameters: " + e.getLocalizedMessage());
                        return null;
                    }

                    BasicQuery bq = new BasicQuery(qry, startLineNo);
                    bq.setQueryParameters(
                            (LinkedHashSet<com.safi.workshop.sqlexplorer.parsers.QueryParameter>) parms);
                    return bq;
                    // return new BasicQuery(sql.subSequence(start, startOfLine), startLineNo);
                }
            }
            startOfLine = -1;
            lineNo++;
            if (inSLComment) {
                inSLComment = false;
                continue;
            }
        }

        // Starting a single-line comment
        if (nextIs(slComment)) {
            if (rangeIs(startOfLine, charIndex, altSeparator)) {
                if (startLineNo < 0 || start + altSeparator.length() >= startOfLine) {
                    start = charIndex;
                    startLineNo = -1;
                    startOfLine = -1;
                    continue;
                }

                CharSequence qry = sql.subSequence(start, startOfLine);
                Set<com.safi.workshop.sqlexplorer.parsers.QueryParameter> parms = null;
                try {
                    parms = parseArgs(qry.toString());
                } catch (ParserException e) {
                    e.printStackTrace();
                    MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Parse Param Error",
                            "Error caught while parsing parameters: " + e.getLocalizedMessage());
                    return null;
                }

                BasicQuery bq = new BasicQuery(qry, startLineNo);
                bq.setQueryParameters(
                        (LinkedHashSet<com.safi.workshop.sqlexplorer.parsers.QueryParameter>) parms);
                return bq;

                // return new BasicQuery(sql.subSequence(start, startOfLine), startLineNo);
            }
            inSLComment = true;
            continue;
        }

        // Starting a multi-line comment
        if (nextIs(mlCommentStart)) {
            if (rangeIs(startOfLine, charIndex, altSeparator)) {
                if (startLineNo < 0 || start + altSeparator.length() >= startOfLine) {
                    start = charIndex;
                    startLineNo = -1;
                    startOfLine = -1;
                    continue;
                }
                CharSequence qry = sql.subSequence(start, startOfLine);
                Set<com.safi.workshop.sqlexplorer.parsers.QueryParameter> parms = null;
                try {
                    parms = parseArgs(qry.toString());
                } catch (ParserException e) {
                    e.printStackTrace();
                    MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Parse Param Error",
                            "Error caught while parsing parameters: " + e.getLocalizedMessage());
                    return null;
                }

                BasicQuery bq = new BasicQuery(qry, startLineNo);
                bq.setQueryParameters(
                        (LinkedHashSet<com.safi.workshop.sqlexplorer.parsers.QueryParameter>) parms);
                return bq;
                // return new BasicQuery(sql.subSequence(start, startOfLine), startLineNo);
            }
            inMLComment = true;
            continue;
        }

        // Only update the startLineNo when we know when code starts
        if (startLineNo < 0 && !Character.isWhitespace(c))
            startLineNo = lineNo;
    }

    // Returns something if there is something to return
    if (start < charIndex) {
        if (rangeIs(startOfLine, charIndex, altSeparator)) {
            charIndex = sql.length();
            if (startLineNo < 0 || start + altSeparator.length() >= startOfLine)
                return null;

            CharSequence qry = sql.subSequence(start, startOfLine);
            Set<com.safi.workshop.sqlexplorer.parsers.QueryParameter> parms = null;
            try {
                parms = parseArgs(qry.toString());
            } catch (ParserException e) {
                e.printStackTrace();
                MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Parse Param Error",
                        "Error caught while parsing parameters: " + e.getLocalizedMessage());
                return null;
            }

            BasicQuery bq = new BasicQuery(qry, startLineNo);
            bq.setQueryParameters((LinkedHashSet<com.safi.workshop.sqlexplorer.parsers.QueryParameter>) parms);
            return bq;
            // return new BasicQuery(sql.subSequence(start, startOfLine), startLineNo);
        }

        CharSequence qry = sql.subSequence(start, charIndex);
        Set<com.safi.workshop.sqlexplorer.parsers.QueryParameter> parms = null;
        try {
            parms = parseArgs(qry.toString());
        } catch (ParserException e) {
            e.printStackTrace();
            MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Parse Param Error",
                    "Error caught while parsing parameters: " + e.getLocalizedMessage());
            return null;
        }

        BasicQuery bq = new BasicQuery(qry, startLineNo);
        bq.setQueryParameters((LinkedHashSet<com.safi.workshop.sqlexplorer.parsers.QueryParameter>) parms);
        return bq;

        // return new BasicQuery(sql.subSequence(start, charIndex), startLineNo);
    }
    return null;
}

From source file:gsn.storage.StorageManager.java

public StringBuilder getStatementCreateTable(CharSequence tableName, DataField[] structure,
        Connection connection) throws SQLException {
    return getStatementCreateTable(tableName.toString(), structure);
}