Example usage for java.lang String toString

List of usage examples for java.lang String toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

This object (which is already a string!) is itself returned.

Usage

From source file:com.mmiagency.knime.nodes.moz.api.util.ConnectionUtil.java

/**
 * /* w w w  . j a  v a  2  s .  c o m*/
 * Method to make a GET HTTP connecton to 
 * the given url and return the output
 * 
 * @param urlToFetch url to be connected
 * @return the http get response
 */
public static String makeRequest(String urlToFetch) throws Exception {

    HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
        public void initialize(HttpRequest request) {
        }
    });
    HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(urlToFetch.toString()));
    HttpResponse response = request.execute();
    StringWriter writer = new StringWriter();
    IOUtils.copy(response.getContent(), writer, response.getContentEncoding());
    return writer.toString();
}

From source file:com.amazonaws.mturk.cmd.MakeTemplate.java

private static void generateScript(String scriptTemplateDir, String target, String targetDirPath,
        String command, CreateScriptUtil.ScriptType type) throws Exception {

    String scriptName = targetDirPath + File.separator + command + type.getExtension();

    System.out.println("Generating script: " + scriptName);

    Map<String, String> input = new HashMap<String, String>(1);
    input.put("${target}", target);

    String templateFileName = scriptTemplateDir + File.separator + command + "." + type + ".template";
    String source = CreateScriptUtil.generateScriptSource(type, input, templateFileName.toString());

    FileWriter out = new FileWriter(scriptName);
    out.write(source);/*from  w  w w  . j  a v  a2s .co m*/
    out.close();
}

From source file:com.p5solutions.core.utils.NumberUtils.java

public static boolean isNumeric(String value, boolean allowDOT) {
    if (value == null) {
        return false;
    }/*from  w ww .j a va2 s  .com*/

    byte[] val = value.toString().getBytes();

    for (int i = 0; i < val.length; i++) {
        byte v = val[i];

        if (v < 48 || v > 57) {
            if (allowDOT && v == '.') {
                continue;
            }

            return false;
        }
    }

    return true;
}

From source file:de.zib.scalaris.examples.wikipedia.data.Revision.java

/**
 * Converts a timestamp in ISO8601 format to a {@link Calendar} object.
 * /*www . j a va 2 s  . co m*/
 * @param timestamp
 *            the timestamp to convert
 * 
 * @return a {@link Calendar} with the same date
 */
public static Calendar stringToCalendar(String timestamp) {
    return javax.xml.bind.DatatypeConverter.parseDateTime(timestamp.toString());
}

From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.Evaluator.java

public static void runClassifierCV(WekaClassifier wekaClassifier, Dataset dataset) throws Exception {
    // Set parameters
    int folds = 10;
    Classifier baseClassifier = getClassifier(wekaClassifier);

    // Set up the random number generator
    long seed = new Date().getTime();
    Random random = new Random(seed);

    // Add IDs to the instances
    AddID.main(new String[] { "-i", MODELS_DIR + "/" + dataset.toString() + ".arff", "-o",
            MODELS_DIR + "/" + dataset.toString() + "-plusIDs.arff" });
    Instances data = DataSource.read(MODELS_DIR + "/" + dataset.toString() + "-plusIDs.arff");
    data.setClassIndex(data.numAttributes() - 1);

    // Instantiate the Remove filter
    Remove removeIDFilter = new Remove();
    removeIDFilter.setAttributeIndices("first");

    // Randomize the data
    data.randomize(random);/*w ww . j a v a  2  s.c  o m*/

    // Perform cross-validation
    Instances predictedData = null;
    Evaluation eval = new Evaluation(data);

    for (int n = 0; n < folds; n++) {
        Instances train = data.trainCV(folds, n, random);
        Instances test = data.testCV(folds, n);

        // Apply log filter
        //          Filter logFilter = new LogFilter();
        //           logFilter.setInputFormat(train);
        //           train = Filter.useFilter(train, logFilter);        
        //           logFilter.setInputFormat(test);
        //           test = Filter.useFilter(test, logFilter);

        // Copy the classifier
        Classifier classifier = AbstractClassifier.makeCopy(baseClassifier);

        // Instantiate the FilteredClassifier
        FilteredClassifier filteredClassifier = new FilteredClassifier();
        filteredClassifier.setFilter(removeIDFilter);
        filteredClassifier.setClassifier(classifier);

        // Build the classifier
        filteredClassifier.buildClassifier(train);

        // Evaluate
        eval.evaluateModel(filteredClassifier, test);

        // Add predictions
        AddClassification filter = new AddClassification();
        filter.setClassifier(filteredClassifier);
        filter.setOutputClassification(true);
        filter.setOutputDistribution(false);
        filter.setOutputErrorFlag(true);
        filter.setInputFormat(train);
        Filter.useFilter(train, filter); // trains the classifier

        Instances pred = Filter.useFilter(test, filter); // performs predictions on test set
        if (predictedData == null)
            predictedData = new Instances(pred, 0);
        for (int j = 0; j < pred.numInstances(); j++)
            predictedData.add(pred.instance(j));
    }

    // Prepare output classification
    String[] scores = new String[predictedData.numInstances()];

    for (Instance predInst : predictedData) {
        int id = new Double(predInst.value(predInst.attribute(0))).intValue() - 1;

        int valueIdx = predictedData.numAttributes() - 2;

        String value = predInst.stringValue(predInst.attribute(valueIdx));

        scores[id] = value;
    }

    // Output
    StringBuilder sb = new StringBuilder();
    for (String score : scores)
        sb.append(score.toString() + LF);

    FileUtils.writeStringToFile(
            new File(OUTPUT_DIR + "/" + dataset.toString() + "/" + wekaClassifier.toString() + "/output.csv"),
            sb.toString());
}

From source file:com.hichinaschool.flashcards.anki.ReadText.java

public static void speak(String text, String loc) {
    int result = mTts.setLanguage(new Locale(loc));
    if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
        Log.e(AnkiDroidApp.TAG, "Error loading locale " + loc.toString());
    } else {//from   www.j  av  a2 s .com
        if (mTts.isSpeaking()) {
            sTextQueue.add(new String[] { text, loc });
        } else {
            mTts.speak(mTextToSpeak, TextToSpeech.QUEUE_FLUSH, mTtsParams);
        }
    }
}

From source file:com.fluidops.iwb.util.UIUtil.java

/**
 * The string representation of this default value, i.e. "Default: <VALUE>"
 * If the default value is undefined or the empty string, this method 
 * returns an empty string// w w  w . ja  v  a2 s . c om
 * 
 * @param configAnnotation
 * @return
 */
public static String configDefaultValueToString(ParameterConfigDoc configAnnotation) {
    if (configAnnotation == null)
        throw new IllegalArgumentException("Argument must not be null.");
    String defaultValue = configAnnotation.defaultValue();
    if (defaultValue != null && !StringUtil.isNullOrEmpty(defaultValue))
        return "Default: " + defaultValue.toString();
    return "";
}

From source file:com.memetix.mst.MicrosoftTranslatorAPI.java

private static String jsonToString(final String inputString) throws Exception {
    String json = (String) JSONValue.parse(inputString);
    return json.toString();
}

From source file:coral.model.ExpData.java

private static Object stringToObject(String e) {
    if (e != null && e.toString().startsWith("[[")) {
        String[] parts = e.substring(2, e.length() - 1).split(", ");
        Object[] array = new Object[parts.length];
        int i = 0;

        long[] longs = new long[parts.length];
        boolean islong = true;

        int[] ints = new int[parts.length];
        boolean isint = true;

        double[] doubles = new double[parts.length];
        boolean isdouble = true;

        for (String part : parts) {
            Object o = stringToObject(part);

            if (!(o instanceof Long) && !(o instanceof Integer)) {
                islong = false;/*www.j av a2  s.  c om*/
            } else if ((o instanceof Long)) {
                longs[i] = (Long) o;
            }

            if (!(o instanceof Integer)) {
                isint = false;
            } else {
                ints[i] = (Integer) o;
                longs[i] = (Integer) o;
            }

            if (!(o instanceof Double)) {
                isdouble = false;
            } else {
                doubles[i] = (Double) o;
            }

            array[i++] = o;
        }
        if (isint) {
            return ints;
        } else if (islong) {
            return longs;
        } else if (isdouble) {
            return doubles;
        } else {
            return array;
        }
    }

    if (e != null && !e.toString().equals("")) {
        Object value = e;

        try {
            try {
                try {
                    value = Integer.parseInt(value.toString());
                } catch (NumberFormatException ex) {
                    value = Long.parseLong(value.toString());
                }
            } catch (NumberFormatException ex) {
                double v = Double.parseDouble(value.toString());
                if (Math.round(v) == v) {
                    value = Math.round(v);
                    int newvalue = ((Long) value).intValue();
                    long compvalue = ((Long) value).longValue();
                    if ((long) newvalue == compvalue) {
                        value = newvalue;
                    }
                } else {
                    value = v;
                }
            }
        } catch (NumberFormatException ex) {
        }
        // System.out.println(value.getClass());
        return value;
    } else {
        return e;
    }

}

From source file:com.strategicgains.docussandra.controller.perf.remote.parent.PerfTestParent.java

protected static void postIndex(Database database, Table table, Index index) {
    logger.info("POSTing index: " + index.toString());
    String tableStr = Fixtures.generateIndexCreationStringWithFields(index);
    //act//w w w  . j  ava 2 s. c o m
    given().body(tableStr.toString()).when()
            .post(database.name() + "/" + table.name() + "/indexes/" + index.getName());
    //check
    Response r = expect().statusCode(200).body("name", equalTo(index.getName())).body("fields", notNullValue())
            .body("createdAt", notNullValue()).body("updatedAt", notNullValue())
            .get(database.name() + "/" + table.name() + "/indexes/" + index.getName()).andReturn();
    logger.debug("Index created: \r\n" + r.getBody().prettyPrint());
}