Package java.lang

Examples of java.lang.StringBuilder$Cell


 
 
  //Object functions
 
  public CodeStringBuilder(){
    sb=new StringBuilder();
  }
View Full Code Here


  public void removeChangeListener(Listener listener) {
    myListeners.remove(listener);
  }

  public String toScript(HashMap<String, Object> scriptData) throws ScriptGenException {
    StringBuilder py = new StringBuilder();
        boolean isFourier = true;

        py.append("\n");
       
        for (int i = 0; i < myFunctions.length; i++) {
            if (!(myFunctions[i] instanceof FourierFunction))
            {
                isFourier = false;
                break;
            }
        }

        if (isFourier) {
            StringBuilder base = new StringBuilder("[");
            StringBuilder high = new StringBuilder("[");
            StringBuilder power = new StringBuilder("[");
           
            for (int i = 0; i < myFunctions.length; i++) {          
                FourierFunction func = (FourierFunction)myFunctions[i];
               
                if (func.getFundamental() == 0.0f) {
                    throw new ScriptGenException("Cannot generate a Fourier Function that was built by specifiying all frequencies, amplitudes and phases");
                }

                base.append(func.getFundamental());
                high.append(func.getCutoff());
                power.append(func.getRms());
                if ((i + 1) < myFunctions.length) {
                    base.append(",");
                    high.append(",");
                    power.append(",");
                }
            }

            base.append("]");
            high.append("]");
            power.append("]");

            py.append(String.format("%s.make_fourier_input('%s', dimensions=%d, base=%s, high=%s, power=%s)\n",
                        scriptData.get("netName"),
                        myName,
                        myFunctions.length,
                        base,
                        high,
                        power));
        } else {
            StringBuilder funcs = new StringBuilder("[");
            for (int i = 0; i < myFunctions.length; i++) {
             
              String functionName = String.format("Function%c%s%c%d",
                          (Character)scriptData.get("spaceDelim"),
                          myName.replaceAll("\\p{Blank}|\\p{Punct}", ((Character)scriptData.get("spaceDelim")).toString()),
                          (Character)scriptData.get("spaceDelim"),
                          i);

                if (myFunctions[i] instanceof ConstantFunction) {
                    ConstantFunction func = (ConstantFunction)myFunctions[i];
                   
                    py.append(String.format("%s = ConstantFunction(%d, %.3f)\n",
                                      functionName,
                                      func.getDimension(),
                                      func.getValue()));
                   
                } else if (myFunctions[i] instanceof FourierFunction) {
                    FourierFunction func = (FourierFunction)myFunctions[i];

                    py.append(String.format("%s = FourierFunction(%f, %f, %f, %d)\n",
                          functionName,
                                func.getFundamental(),
                                func.getCutoff(),
                                func.getRms(),
                                func.getSeed()));
                } else if (myFunctions[i] instanceof PostfixFunction) {
                    PostfixFunction func = (PostfixFunction)myFunctions[i];

                    py.append(String.format("%s = PostfixFunction('%s', %d)\n",
                          functionName,
                                func.getExpression(),
                                func.getDimension()));
                }

                funcs.append(functionName);
               
                if ((i + 1) < myFunctions.length) {
                    funcs.append(", ");
                }
            }
            funcs.append("]");
                               
            py.append(String.format("%s.make_input('%s', values=%s)\n",
                    scriptData.get("netName"),
                    myName,
                    funcs.toString()));
        }
       
        return py.toString();
    }
View Full Code Here

    return p;
  }

    @Override
    public String toScript(HashMap<String, Object> scriptData) throws ScriptGenException {
        StringBuilder py = new StringBuilder(String.format("%s.make('%s', %d, %d",
                    scriptData.get("netName"),
                    getName(),
                    getNodes().length,
                    myDimension));

        NodeFactory nodeFactory = myEnsembleFactory.getNodeFactory();
        if (nodeFactory instanceof LIFNeuronFactory) {
            LIFNeuronFactory neuronFactory = (LIFNeuronFactory)nodeFactory;

            if (!(neuronFactory.getMaxRate() instanceof IndicatorPDF) ||
                !(neuronFactory.getIntercept() instanceof IndicatorPDF)) {
                throw new ScriptGenException("Max Rate or Intercept for LIF Neuron Factory not specified as a uniform range");
            }

            py.append(String.format(", tau_rc=%.3f, tau_ref=%.3f, max_rate=(%.1f, %.1f), intercept=(%.1f, %.1f)",
                        neuronFactory.getTauRC(),
                        neuronFactory.getTauRef(),
                        ((IndicatorPDF)neuronFactory.getMaxRate()).getLow(),
                        ((IndicatorPDF)neuronFactory.getMaxRate()).getHigh(),
                        ((IndicatorPDF)neuronFactory.getIntercept()).getLow(),
                        ((IndicatorPDF)neuronFactory.getIntercept()).getHigh()));
        } else {
            throw new ScriptGenException("Neuron Factory not supported. Only LIF Neuron Factory is supported");
        }

        py.append(String.format(", radius=%.2f)\n", myRadii[0]));
        return py.toString();
    }
View Full Code Here

    public static class RegexReader extends AFn {
        static StringReader stringrdr = new StringReader();

        public Object invoke(Object reader, Object doublequote) {
            StringBuilder sb = new StringBuilder();
            Reader r = (Reader) reader;
            for (int ch = read1(r); ch != '"'; ch = read1(r)) {
                if (ch == -1)
                    throw Util.runtimeException("EOF while reading regex");
                sb.append((char) ch);
                if (ch == '\\') // escape
                {
                    ch = read1(r);
                    if (ch == -1)
                        throw Util.runtimeException("EOF while reading regex");
                    sb.append((char) ch);
                }
            }
            return Pattern.compile(sb.toString());
        }
View Full Code Here

        }
    }

    public static class StringReader extends AFn {
        public Object invoke(Object reader, Object doublequote) {
            StringBuilder sb = new StringBuilder();
            Reader r = (Reader) reader;

            for (int ch = read1(r); ch != '"'; ch = read1(r)) {
                if (ch == -1)
                    throw Util.runtimeException("EOF while reading string");
                if (ch == '\\') // escape
                {
                    ch = read1(r);
                    if (ch == -1)
                        throw Util.runtimeException("EOF while reading string");
                    switch (ch) {
                    case 't':
                        ch = '\t';
                        break;
                    case 'r':
                        ch = '\r';
                        break;
                    case 'n':
                        ch = '\n';
                        break;
                    case '\\':
                        break;
                    case '"':
                        break;
                    case 'b':
                        ch = '\b';
                        break;
                    case 'f':
                        ch = '\f';
                        break;
                    case 'u': {
                        ch = read1(r);
                        if (Character.digit(ch, 16) == -1)
                            throw Util.runtimeException("Invalid unicode escape: \\u" + (char) ch);
                        ch = readUnicodeChar((PushbackReader) r, ch, 16, 4, true);
                        break;
                    }
                    default: {
                        if (Character.isDigit(ch)) {
                            ch = readUnicodeChar((PushbackReader) r, ch, 8, 3, false);
                            if (ch > 0377)
                                throw Util
                                        .runtimeException("Octal escape sequence must be in range [0, 377].");
                        } else
                            throw Util.runtimeException("Unsupported escape character: \\"
                                    + (char) ch);
                    }
                    }
                }
                sb.append((char) ch);
            }
            return sb.toString();
        }
View Full Code Here

            // Grab expected barcode data from barcodeData.<LANE>
            IOUtil.assertFileIsReadable(INPUT);
            final TabbedTextFileWithHeaderParser barcodesParser = new TabbedTextFileWithHeaderParser(INPUT);
            for (final TabbedTextFileWithHeaderParser.Row row : barcodesParser) {
                final String barcodeName = row.getField(BARCODE_NAME_COLUMN);
                final StringBuilder barcode = new StringBuilder();
                for (int i = 1; i <= readStructure.barcodes.length(); i++) {
                    barcode.append(row.getField(BARCODE_SEQUENCE_COLUMN_NAME_STUB + i));
                    if (barcodeLength == 0) barcodeLength = barcode.length();
                }

                // Only add the barcode to the hash if it has sequences. For libraries
                // that don't have barcodes this won't be set in the file.
                if (barcode.length() > 0) {
                    barcodeToMetricCounts.put(barcode.toString(), new IlluminaMetricCounts(barcode.toString(), barcodeName, LANE));
                }
            }

            factory = barcodeToMetricCounts.isEmpty()
                    ? new IlluminaDataProviderFactory(
View Full Code Here

  @Override
  public String toString() {
    boolean longList = temperatures.count() > LIST_THRESHOLD ? true : false;
    List<Tuple2<String, Float>> readings =
      temperatures.take(longList ? LIST_THRESHOLD : (int) temperatures.count());
    StringBuilder builder = new StringBuilder();
    builder.append("(");
    boolean first = true;
    for (Tuple2<String, Float> reading : readings) {
      if (!first) {
        builder.append(", ");
      } else {
        first = false;
      }
      builder.append(reading);
    }
    if (longList) {
      builder.append(", ...");
    }
    builder.append(")");
    return builder.toString();
  }
View Full Code Here

      InterruptedException {
    long startTime = System.currentTimeMillis();
    String file = "D:/Dropbox/Life/Blog/goldvase.wordpress.2011-07-12.xml";
    int len = (int) (new File(file).length());
    BufferedReader in = new BufferedReader(new FileReader(file));
    StringBuilder blogXML = new StringBuilder(len);
    String aLine;
    int rowNumber = 0;
    while ((aLine = in.readLine()) != null) {
      blogXML.append(aLine);
      blogXML.append('\n');
      rowNumber++;
    }
    in.close();
    long endTime = System.currentTimeMillis();
    double timeUsed = (endTime - startTime) / 1000d;
    System.out.println("The time used for reading text file is: "
        + timeUsed + ".");
    System.out.println("Number of rows read in: " + rowNumber);
    System.out.println("Original length: " + blogXML.length());
    // ---------- remove comments -------------------------------
    startTime = System.currentTimeMillis();
    String commentStart = "<wp:comment>";
    int commentStartLength = commentStart.length();
    String commentEnd = "</wp:comment>";
    int commentEndLength = commentEnd.length();
    int startIndex = blogXML.indexOf(commentStart);
    int endIndex;
    int count = 0;
    while (startIndex > -1) {
      endIndex = blogXML.indexOf(commentEnd, startIndex
          + commentStartLength);
      blogXML = blogXML.delete(startIndex, endIndex + commentEndLength);
      count++;
      if (count % 1000 == 0) {
        System.out.println(count
            + " occurrences are found and removed. Average speed: "
            + count
            / ((System.currentTimeMillis() - startTime) / 1000.)
            + " occurrences per second.");
      }
      startIndex = blogXML.indexOf(commentStart, startIndex);
    }
    System.out.println(count + " occurrences are found and removed.");
    endTime = System.currentTimeMillis();
    timeUsed = (endTime - startTime) / 1000.;
    System.out.println("The time used for replacement is: " + timeUsed
        + ".");
    startTime = System.currentTimeMillis();
    BufferedWriter out = new BufferedWriter(new FileWriter(
        "D:/Dropbox/Life/Blog/cleanBlog.xml"));
    out.write(blogXML.toString());
    out.close();
    endTime = System.currentTimeMillis();
    timeUsed = (endTime - startTime) / 1000.;
    System.out.println("The time used for writing text is: " + timeUsed
        + ".");
View Full Code Here

TOP

Related Classes of java.lang.StringBuilder$Cell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.