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:org.yamj.core.database.dao.ArtworkDao.java

@SuppressWarnings("unchecked")
public List<QueueDTO> getArtworkLocatedQueue(final CharSequence sql, final int maxResults) {
    SQLQuery query = getSession().createSQLQuery(sql.toString());
    query.setReadOnly(true);//  w  ww  . j a  va 2 s .co  m
    query.setCacheable(true);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }

    List<QueueDTO> queueElements = new ArrayList<QueueDTO>();
    List<Object[]> objects = query.list();
    for (Object[] object : objects) {
        QueueDTO queueElement = new QueueDTO();
        queueElement.setId(convertRowElementToLong(object[0]));
        queueElement.setDate(convertRowElementToDate(object[2]));
        if (queueElement.getDate() == null) {
            queueElement.setDate(convertRowElementToDate(object[1]));
        }
        queueElements.add(queueElement);
    }

    Collections.sort(queueElements, new QueueDTOComparator());
    return queueElements;
}

From source file:org.yamj.core.database.dao.ArtworkDao.java

@SuppressWarnings("unchecked")
public List<QueueDTO> getArtworkQueue(final CharSequence sql, final int maxResults) {
    SQLQuery query = getSession().createSQLQuery(sql.toString());
    query.setReadOnly(true);/*from  ww w . jav a  2  s .  co  m*/
    query.setCacheable(true);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }

    List<QueueDTO> queueElements = new ArrayList<QueueDTO>();
    List<Object[]> objects = query.list();
    for (Object[] object : objects) {
        QueueDTO queueElement = new QueueDTO();
        queueElement.setId(convertRowElementToLong(object[0]));
        queueElement.setArtworkType(convertRowElementToString(object[1]));
        queueElement.setDate(convertRowElementToDate(object[3]));
        if (queueElement.getDate() == null) {
            queueElement.setDate(convertRowElementToDate(object[2]));
        }
        queueElements.add(queueElement);
    }

    Collections.sort(queueElements, new QueueDTOComparator());
    return queueElements;
}

From source file:de.perdian.apps.dashboard.support.clients.JsonClient.java

/**
 * Executes the given job and return the response
 *
 * @param requestUri//from  w w w  .  ja va  2s  .  co  m
 *     the URI to which the request should be sent
 * @return
 *     the JSON result
 */
public JsonNode sendRequest(CharSequence requestUri) {
    try {

        HttpGet httpGet = new HttpGet(requestUri.toString());
        if (this.getUsername() != null && this.getPassword() != null) {
            httpGet.addHeader(new BasicScheme().authenticate(
                    new UsernamePasswordCredentials(this.getUsername(), this.getPassword()), httpGet,
                    new BasicHttpContext()));
        }
        for (Map.Entry<Object, Object> defaultHeaderEntry : this.getDefaultHeaders().entrySet()) {
            httpGet.addHeader((String) defaultHeaderEntry.getKey(), (String) defaultHeaderEntry.getValue());
        }

        String httpResponseString = this.getHttpClient().execute(httpGet, new BasicResponseHandler());
        return JsonUtil.fromJsonString(httpResponseString);

    } catch (Exception e) {
        StringBuilder errorMessage = new StringBuilder();
        errorMessage.append("Cannot send HTTP request [").append(requestUri);
        errorMessage.append("] using client [").append(this).append("]");
        log.debug(errorMessage.toString(), e);
        throw new DashboardException(errorMessage.toString(), e);
    }
}

From source file:de.cosmocode.json.JsonRenderer.java

@Override
public Renderer key(CharSequence key) throws RenderingException {
    try {//from w  ww.j a  v  a 2s  .  c  o m
        writer.key(key == null ? "null" : key.toString());
    } catch (JSONException e) {
        throw new RenderingException(e);
    }
    return this;
}

From source file:cn.edu.zjnu.acm.judge.security.password.MessageDigestPasswordEncoder.java

@Override
public String encode(CharSequence password) {
    MessageDigest digest = getMessageDigest(algorithm);
    return new String(Hex.encode(digest
            .digest(password != null ? password.toString().getBytes(StandardCharsets.UTF_8) : new byte[0])));
}

From source file:fr.landel.utils.commons.exception.AbstractException.java

/**
 * Constructor with message and exception. (inverse parameter order to keep
 * compatibility with standard signature)
 * /*from   w  ww .j  ava 2  s  .c o m*/
 * @param message
 *            The message
 * @param exception
 *            The exception
 */
public AbstractException(final CharSequence message, final Throwable exception) {
    super(message.toString(), exception);
}

From source file:fr.landel.utils.commons.exception.AbstractRuntimeException.java

/**
 * Constructor with message and exception. (inverse parameter order to keep
 * compatibility with standard signature)
 * /*from   ww w.  ja  v a 2s .c o  m*/
 * @param message
 *            The message
 * @param exception
 *            The exception
 */
public AbstractRuntimeException(final CharSequence message, final Throwable exception) {
    super(message.toString(), exception);
}

From source file:com.github.jknack.amd4j.WhiteMinifier.java

@Override
public CharSequence minify(final Config config, final CharSequence input) {
    Parser parser = new Parser();
    String fname = removeExtension(config.getName()) + ".js";
    AstRoot tree = parser.parse(input.toString(), fname, 1);

    return strip(tree.toSource());
}

From source file:de.undercouch.citeproc.tool.shell.ShellCommandCompleter.java

@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    boolean allparsed;
    Set<String> result = new HashSet<String>();

    try {//from   w w w  .  j a  va2 s.  com
        Result pr = ShellCommandParser.parse(buffer, excludedCommands);
        if (pr.getFirstCommand() == HelpCommand.class || pr.getFirstCommand() == ShellHelpCommand.class) {
            //parse again, but skip 'help'
            pr = ShellCommandParser.parse(pr.getRemainingArgs(), excludedCommands);
        }

        if (pr.getRemainingArgs().length > 1) {
            //command line could not be parsed completely. we cannot
            //provide suggestions for more than one unrecognized argument.
            allparsed = false;
        } else {
            OptionGroup<ID> options;
            if (pr.getLastCommand() == null) {
                options = OptionIntrospector.introspect(CSLTool.class, AdditionalShellCommands.class);
            } else {
                options = OptionIntrospector.introspect(pr.getLastCommand());
            }

            String[] ra = pr.getRemainingArgs();
            allparsed = (ra == null || ra.length == 0);

            //add completions
            for (Option<ID> o : options.getCommands()) {
                Class<? extends Command> cmd = OptionIntrospector.getCommand(o.getId());
                if (excludedCommands.contains(cmd)) {
                    continue;
                }

                if (allparsed || o.getLongName().startsWith(ra[0])) {
                    result.add(o.getLongName());
                }
            }
        }

        if (pr.getLastCommand() != null && Completer.class.isAssignableFrom(pr.getLastCommand())) {
            Completer cc;
            try {
                cc = (Completer) pr.getLastCommand().newInstance();
            } catch (Exception e) {
                //should never happen
                throw new RuntimeException(e);
            }
            List<CharSequence> ccl = new ArrayList<CharSequence>();
            String jra = StringUtils.join(pr.getRemainingArgs(), " ");
            cc.complete(jra, jra.length(), ccl);
            for (CharSequence cs : ccl) {
                result.add(cs.toString());
            }
        }
    } catch (InvalidOptionException e) {
        //there's an option, we cannot calculate completions anymore
        //because options are not allowed in the interactive shell
        allparsed = false;
    } catch (IntrospectionException e) {
        throw new RuntimeException("Could not inspect command", e);
    }

    //sort completions
    List<String> resultList = new ArrayList<String>(result);
    Collections.sort(resultList);
    candidates.addAll(resultList);

    //determine place to insert completion
    int pos = buffer.length();
    if (!allparsed && pos > 0) {
        while (pos > 0 && Character.isWhitespace(buffer.charAt(pos - 1)))
            --pos;
        if (pos == 0) {
            //buffer consists of whitespaces only
            pos = buffer.length();
        }
        while (pos > 0 && !Character.isWhitespace(buffer.charAt(pos - 1)))
            --pos;
    } else if (allparsed && buffer.length() > 0
            && !Character.isWhitespace(buffer.charAt(buffer.length() - 1))) {
        ++pos;
    }

    return candidates.isEmpty() ? -1 : pos;
}

From source file:it.unimi.di.big.mg4j.tool.URLMPHVirtualDocumentResolver.java

@Override
public long resolve(final CharSequence virtualDocumentSpec) {
    try {// w ww . j  av  a  2  s .c  om
        URI virtualURI = URI.create(virtualDocumentSpec.toString());
        if (!virtualURI.isAbsolute()) {
            if (documentURI == null)
                return -1;
            virtualURI = documentURI.resolve(virtualURI);
        }

        return url2DocumentPointer.getLong(virtualURI.toString());
    } catch (Exception e) {
        return -1;
    }
}