Example usage for java.lang StringBuilder append

List of usage examples for java.lang StringBuilder append

Introduction

In this page you can find the example usage for java.lang StringBuilder append.

Prototype

@Override
    public StringBuilder append(double d) 

Source Link

Usage

From source file:br.ufjf.video.Video.java

public static void main(String args[]) {

    StringBuilder sb = new StringBuilder();

    XMLManager.loadXMLFile("../files/ead_fonseca_05_sd.xml");

    sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.TITLE,
            StringEscapeUtils.escapeJava(XMLManager.getValue("title"))));
    sb.append("\n");
    sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.ABSTRACT,
            StringEscapeUtils.escapeJava(XMLManager.getValue("course"))));
    sb.append("\n");
    sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.DATE, XMLManager.getValue("date")));
    sb.append("\n");
    //sb.append(getTriple(XMLManager.getValue("entry"),QodraOntology.REFERENCES,XMLManager.getValue("title")));
    //sb.append("\n");
    //sb.append(getTriple(XMLManager.getValue("entry"),QodraOntology.DESCRIPTION,XMLManager.getValue("title")));
    //sb.append("\n");
    sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.PUBLISHER,
            StringEscapeUtils.escapeJava(XMLManager.getValue("name"))));
    sb.append("\n");
    sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.CREATOR,
            StringEscapeUtils.escapeJava(XMLManager.getValue("entity"))));
    sb.append("\n");
    //sb.append(getTriple(XMLManager.getValue("entry"),QodraOntology.LICENSE,XMLManager.getValue("title")));
    //sb.append("\n");
    sb.append(getTriple(XMLManager.getValue("entry"), QodraOntology.LANGUAGE, XMLManager.getValue("language")));
    sb.append("\n");
    //sb.append(getTriple(XMLManager.getValue("entry"),QodraOntology.EDUCATIONLEVEL,XMLManager.getValue("title")));
    //sb.append("\n");

    FileManager.writeFile("../files/allegro.graph.nt", sb.toString());

    System.out.println(sb.toString());

}

From source file:NavigableSetDemo.java

public static void main(String[] args) {
    List<Integer> list = Arrays.asList(3, 2, 4, 1, 5);
    NavigableSet<Integer> ns = new TreeSet<Integer>(list);
    System.out.println("Ascending order (default): " + ns);

    Iterator<Integer> descendingIterator = ns.descendingIterator();
    StringBuilder sb = new StringBuilder("Descending order: ");
    while (descendingIterator.hasNext()) {
        int m = descendingIterator.next();
        sb.append(m + " ");
    }//w  ww  .j  av  a2 s  .c om
    System.out.println(sb);

    int greatest = ns.lower(3);
    System.out.println("Lower of 3 = " + greatest);

    int smallest = ns.higher(3);
    System.out.println("Higher of 3 = " + smallest);
}

From source file:facade.examples.Collections.java

/**
 * Run the examples//  w  w  w . j  a  va  2 s  . c  om
 * @param args <i>ignored</i>
 */
public static void main(String[] args) {

    /* RESISTORS IN PARALLEL WITH FACADE */

    System.out.println("-> With facade: ");
    /* Empty collection of resistors */
    Collection<Double> resistors = new ArrayList<Double>();
    /* adding values. on() modifies the collection in place */
    on(resistors).add(1.5, 3.0, 15.0, 30.0, 150.0);
    /* computing resistance. with() works on a collection copy. */
    double r = 1.0 / with(resistors).map(inverse).reduce(sum);
    /* pretty printing the resistors */
    System.out.println("[ " + with(resistors).join(", ") + " ]");
    /* printing the equivalent resistor */
    System.out.println(r);

    /* --------------------------------------------------------------- */
    System.out.println();
    /* --------------------------------------------------------------- */

    /* RESISTORS IN PARALLEL WITH CLASSIC JAVA */

    System.out.println("-> Without facade: ");
    /* Empty collection of resistors */
    resistors = new ArrayList<Double>();
    /* adding values */
    resistors.add(1.5);
    resistors.add(3.0);
    resistors.add(15.0);
    resistors.add(30.0);
    resistors.add(150.0);
    /* computing resistance */
    double sum = 0.0;
    for (Double resistor : resistors) {
        sum += 1.0 / resistor;
    }
    r = 1.0 / sum;
    /* pretty printing the resistors */
    StringBuilder sb = new StringBuilder();
    sb.append("[ ");
    Iterator<Double> it = resistors.iterator();
    if (it.hasNext()) {
        sb.append(it.next());
    }
    while (it.hasNext()) {
        sb.append(", ").append(it.next());
    }
    sb.append(" ]");
    System.out.println(sb.toString());
    /* printing the equivalent resistor */
    System.out.println(r);

}

From source file:com.liferay.mobile.sdk.BuilderAntTask.java

public static void main(String[] args) {
    Map<String, String> arguments = parseArguments(args);

    String url = arguments.get("url");
    String context = arguments.get("context");
    String filter = arguments.get("filter");

    StringBuilder sb = new StringBuilder();

    sb.append(url);

    if (Validator.isNotNull(context)) {
        sb.append("/");
        sb.append(context);/*w w  w . j  av  a2  s .  c  o m*/
    }

    sb.append("/api/jsonws?discover");

    if (Validator.isNull(filter)) {
        sb.append("=/*");
    } else {
        sb.append("=/");
        sb.append(filter);
        sb.append("/*");
    }

    HttpClient client = new DefaultHttpClient();

    HttpGet get = new HttpGet(sb.toString());

    DiscoveryResponseHandler handler = new DiscoveryResponseHandler();

    try {
        String builderType = arguments.get("builder");

        Builder builder = null;

        if (builderType.equals("android")) {
            builder = new AndroidBuilder();
        }

        Discovery discovery = client.execute(get, handler);

        PortalVersion version = HttpUtil.getPortalVersion(url);

        if (Validator.isNull(filter)) {
            builder.buildAll(version, discovery);
        } else {
            builder.build(filter, version, discovery);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String password = "secret";
    String algorithm = "SHA";

    byte[] plainText = password.getBytes();

    MessageDigest md = MessageDigest.getInstance(algorithm);

    md.reset();/*  w  w w .  ja v a  2 s  .  c  o  m*/
    md.update(plainText);
    byte[] encodedPassword = md.digest();

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < encodedPassword.length; i++) {
        if ((encodedPassword[i] & 0xff) < 0x10) {
            sb.append("0");
        }
        sb.append(Long.toString(encodedPassword[i] & 0xff, 16));
    }
    System.out.println("Plain    : " + password);
    System.out.println("Encrypted: " + sb.toString());
}

From source file:org.eclipse.swt.snippets.Snippet222.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText Bullet Example");
    shell.setLayout(new FillLayout());
    final StyledText styledText = new StyledText(shell,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    StringBuilder text = new StringBuilder();
    text.append("Here is StyledText with some bulleted lists:\n\n");
    for (int i = 0; i < 4; i++)
        text.append("Red Bullet List Item " + i + "\n");
    text.append("\n");
    for (int i = 0; i < 2; i++)
        text.append("Numbered List Item " + i + "\n");
    for (int i = 0; i < 4; i++)
        text.append("Sub List Item " + i + "\n");
    for (int i = 0; i < 2; i++)
        text.append("Numbered List Item " + (2 + i) + "\n");
    text.append("\n");
    for (int i = 0; i < 4; i++)
        text.append("Custom Draw List Item " + i + "\n");
    styledText.setText(text.toString());

    StyleRange style0 = new StyleRange();
    style0.metrics = new GlyphMetrics(0, 0, 40);
    style0.foreground = display.getSystemColor(SWT.COLOR_RED);
    Bullet bullet0 = new Bullet(style0);
    StyleRange style1 = new StyleRange();
    style1.metrics = new GlyphMetrics(0, 0, 50);
    style1.foreground = display.getSystemColor(SWT.COLOR_BLUE);
    Bullet bullet1 = new Bullet(ST.BULLET_NUMBER | ST.BULLET_TEXT, style1);
    bullet1.text = ".";
    StyleRange style2 = new StyleRange();
    style2.metrics = new GlyphMetrics(0, 0, 80);
    style2.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    Bullet bullet2 = new Bullet(ST.BULLET_TEXT, style2);
    bullet2.text = "\u2713";
    StyleRange style3 = new StyleRange();
    style3.metrics = new GlyphMetrics(0, 0, 50);
    Bullet bullet3 = new Bullet(ST.BULLET_CUSTOM, style2);

    styledText.setLineBullet(2, 4, bullet0);
    styledText.setLineBullet(7, 2, bullet1);
    styledText.setLineBullet(9, 4, bullet2);
    styledText.setLineBullet(13, 2, bullet1);
    styledText.setLineBullet(16, 4, bullet3);

    styledText.addPaintObjectListener(event -> {
        Display display1 = event.display;
        StyleRange style = event.style;/*  ww w . j  a va2s  .  co  m*/
        Font font = style.font;
        if (font == null)
            font = styledText.getFont();
        TextLayout layout = new TextLayout(display1);
        layout.setAscent(event.ascent);
        layout.setDescent(event.descent);
        layout.setFont(font);
        layout.setText("\u2023 1." + event.bulletIndex + ")");
        layout.draw(event.gc, event.x + 10, event.y);
        layout.dispose();
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:HrefMatch.java

public static void main(String[] args) {
    try {/*  w  ww  .jav  a 2 s.  c  o  m*/
        // get URL string from command line or use default
        String urlString;
        if (args.length > 0)
            urlString = args[0];
        else
            urlString = "http://java.sun.com";

        // open reader for URL
        InputStreamReader in = new InputStreamReader(new URL(urlString).openStream());

        // read contents into string builder
        StringBuilder input = new StringBuilder();
        int ch;
        while ((ch = in.read()) != -1)
            input.append((char) ch);

        // search for all occurrences of pattern
        String patternString = "<a\\s+href\\s*=\\s*(\"[^\"]*\"|[^\\s>]*)\\s*>";
        Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(input);

        while (matcher.find()) {
            int start = matcher.start();
            int end = matcher.end();
            String match = input.substring(start, end);
            System.out.println(match);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (PatternSyntaxException e) {
        e.printStackTrace();
    }
}

From source file:mxnet.ObjectDetection.java

public static void main(String[] args) {
    List<Context> context = new ArrayList<Context>();
    context.add(Context.cpu());// w  w  w .j  a v a 2s.  co  m
    downloadModelImage();

    List<List<ObjectDetectorOutput>> output = runObjectDetectionSingle(modelPath, imagePath, context);

    Shape inputShape = new Shape(new int[] { 1, 3, 512, 512 });
    Shape outputShape = new Shape(new int[] { 1, 6132, 6 });
    int width = inputShape.get(2);
    int height = inputShape.get(3);
    String outputStr = "\n";

    for (List<ObjectDetectorOutput> ele : output) {
        for (ObjectDetectorOutput i : ele) {
            outputStr += "Class: " + i.getClassName() + "\n";
            outputStr += "Probabilties: " + i.getProbability() + "\n";

            List<Float> coord = Arrays.asList(i.getXMin() * width, i.getXMax() * height, i.getYMin() * width,
                    i.getYMax() * height);
            StringBuilder sb = new StringBuilder();
            for (float c : coord) {
                sb.append(", ").append(c);
            }
            outputStr += "Coord:" + sb.substring(2) + "\n";
        }
    }
    System.out.println(outputStr);
}

From source file:edu.illinois.cs.cogcomp.wikifier.utils.freebase.cleanDL.java

public static void main(String[] args) throws IOException {
    List<String> lines = FileUtils.readLines(new File("/Users/Shyam/mention.eval.dl"));

    for (String line : lines) {
        String[] parts = line.split("\\s+");
        System.out.println(parts[0] + parts[1] + parts[2]);
        StringBuilder sb = new StringBuilder();
        for (int i = 3; i < parts.length; i++)
            sb.append(parts[i] + " ");
        if (mentionFilter(parts)) {
            System.out.println("removing " + Arrays.asList(parts));
            continue;
        }//from  w  w w. j  ava 2s  . co  m
        if (mentions.containsKey(parts[0])) {
            mentions.get(parts[0]).add(new DocMention(parts[0], sb.toString(), Integer.parseInt(parts[1]),
                    Integer.parseInt(parts[2])));
        } else {
            mentions.put(parts[0], new ArrayList<DocMention>());
            mentions.get(parts[0]).add(new DocMention(parts[0], sb.toString(), Integer.parseInt(parts[1]),
                    Integer.parseInt(parts[2])));
        }
    }
    for (String doc : mentions.keySet()) {
        handleDoc(mentions.get(doc));
    }

    outputMentions();
}

From source file:com.nextdoor.bender.ValidateSchema.java

public static void main(String[] args) throws ParseException, InterruptedException, IOException {

    /*//  www.jav a2s  . c o m
     * Parse cli arguments
     */
    Options options = new Options();
    options.addOption(Option.builder().longOpt("schema").hasArg()
            .desc("Filename to output schema to. Default: schema.json").build());
    options.addOption(Option.builder().longOpt("configs").hasArgs()
            .desc("List of config files to validate against schema.").build());
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    String schemaFilename = cmd.getOptionValue("schema", "schema.json");
    String[] configFilenames = cmd.getOptionValues("configs");

    /*
     * Validate config files against schema
     */
    boolean hasFailures = false;
    for (String configFilename : configFilenames) {
        StringBuilder sb = new StringBuilder();
        Files.lines(Paths.get(configFilename), StandardCharsets.UTF_8).forEach(p -> sb.append(p + "\n"));

        System.out.println("Attempting to validate " + configFilename);
        try {
            ObjectMapper mapper = BenderConfig.getObjectMapper(configFilename);
            mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
            BenderConfig.load(configFilename, sb.toString(), mapper, true);
            System.out.println("Valid");
            BenderConfig config = BenderConfig.load(configFilename, sb.toString());
        } catch (ConfigurationException e) {
            System.out.println("Invalid");
            e.printStackTrace();
            hasFailures = true;
        }
    }

    if (hasFailures) {
        System.exit(1);
    }
}