コード例 #1
0
ファイル: RedactedExtension.java プロジェクト: crazybob/wire
 @Override
 public RedactedExtension redact(RedactedExtension value) {
   Builder builder = value.newBuilder();
   builder.d = null;
   builder.clearUnknownFields();
   return builder.build();
 }
コード例 #2
0
 private static Builder create() {
   Builder builder = new Builder();
   builder.result =
       new com.alachisoft.tayzgrid.common.protobuf.DSUpdatedCallbackResponseProtocol
           .DSUpdatedCallbackResponse();
   return builder;
 }
コード例 #3
0
ファイル: Fuzzy.java プロジェクト: GhostInAMachine/radargun
 @Override
 public Fuzzy<T> convert(String string, Type type) {
   string = string.trim();
   if (string.startsWith("[") && string.endsWith("]")) {
     string = string.substring(1, string.length() - 1);
   }
   String[] parts = string.split(",", 0);
   Builder<T> builder = new Builder<T>();
   for (String part : parts) {
     int colon = part.indexOf(':');
     if (colon < 0) {
       builder.addWeighted(parse(part.trim()), 1.0);
     } else {
       int percent = part.indexOf('%');
       if (percent >= 0 && percent < colon) {
         double probability = Double.parseDouble(part.substring(0, percent).trim()) / 100;
         builder.addFixed(parse(part.substring(colon + 1).trim()), probability);
       } else {
         double weight = Double.parseDouble(part.substring(0, colon).trim());
         builder.addWeighted(parse(part.substring(colon + 1).trim()), weight);
       }
     }
   }
   return builder.create();
 }
コード例 #4
0
 @Override
 public Builder newBuilder() {
   Builder builder = new Builder();
   builder.a = a;
   builder.addUnknownFields(unknownFields());
   return builder;
 }
コード例 #5
0
ファイル: Foos.java プロジェクト: amikey/wire
 @Override
 public Builder newBuilder() {
   Builder builder = new Builder();
   builder.foos = copyOf(foos);
   builder.addUnknownFields(unknownFields());
   return builder;
 }
コード例 #6
0
  public static void testBumpSubBuilders() throws Exception {
    File tmp = new File("tmp-ws");
    if (tmp.exists()) IO.deleteWithException(tmp);
    tmp.mkdir();
    assertTrue(tmp.isDirectory());

    try {
      IO.copy(new File("test/ws"), tmp);
      Workspace ws = Workspace.getWorkspace(tmp);
      Project project = ws.getProject("bump-sub");
      project.setTrace(true);

      assertNull(project.getProperty("Bundle-Version"));

      project.bump("=+0");

      assertNull(project.getProperty("Bundle-Version"));

      for (Builder b : project.getSubBuilders()) {
        assertEquals(new Version(1, 1, 0), new Version(b.getVersion()));
      }
    } finally {
      IO.deleteWithException(tmp);
    }
  }
コード例 #7
0
  private static void load(HttpServletRequest request, Builder b) {
    Enumeration<String> e = request.getHeaderNames();
    String s;
    while (e.hasMoreElements()) {
      s = e.nextElement();
      b.headers.put(s, request.getHeader(s));
    }

    e = request.getAttributeNames();
    while (e.hasMoreElements()) {
      s = e.nextElement();
      b.localAttributes.put(s, attributeWithoutException(request, s));
    }

    e = request.getParameterNames();
    while (e.hasMoreElements()) {
      s = e.nextElement();
      b.queryStrings.put(s, request.getParameterValues(s));
    }
    b.queryString = request.getQueryString();

    Enumeration<Locale> l = request.getLocales();
    while (l.hasMoreElements()) {
      b.locale(l.nextElement());
    }
  }
コード例 #8
0
 private static Builder create() {
   Builder builder = new Builder();
   builder.result =
       new com.alachisoft.tayzgrid.common.protobuf.GetCacheBindingCommandProtocol
           .GetCacheBindingCommand();
   return builder;
 }
コード例 #9
0
ファイル: Country.java プロジェクト: jameysundevil/kuali_rice
 public static Builder create(CountryContract cc) {
   Builder builder =
       new Builder(
           cc.getCode(), cc.getAlternateCode(), cc.getName(), cc.isRestricted(), cc.isActive());
   builder.setVersionNumber(cc.getVersionNumber());
   return builder;
 }
コード例 #10
0
ファイル: RawHeaders.java プロジェクト: hongxixi/okhttp
 /** Returns headers for a name value block containing a SPDY response. */
 public static RawHeaders fromNameValueBlock(List<String> nameValueBlock) throws IOException {
   if (nameValueBlock.size() % 2 != 0) {
     throw new IllegalArgumentException("Unexpected name value block: " + nameValueBlock);
   }
   String status = null;
   String version = null;
   Builder builder = new Builder();
   builder.set(ResponseHeaders.SELECTED_TRANSPORT, "spdy/3");
   for (int i = 0; i < nameValueBlock.size(); i += 2) {
     String name = nameValueBlock.get(i);
     String values = nameValueBlock.get(i + 1);
     for (int start = 0; start < values.length(); ) {
       int end = values.indexOf('\0', start);
       if (end == -1) {
         end = values.length();
       }
       String value = values.substring(start, end);
       if (":status".equals(name)) {
         status = value;
       } else if (":version".equals(name)) {
         version = value;
       } else {
         builder.namesAndValues.add(name);
         builder.namesAndValues.add(value);
       }
       start = end + 1;
     }
   }
   if (status == null) throw new ProtocolException("Expected ':status' header not present");
   if (version == null) throw new ProtocolException("Expected ':version' header not present");
   builder.setStatusLine(version + " " + status);
   return builder.build();
 }
コード例 #11
0
ファイル: FSTTest.java プロジェクト: akkikiki/kuromoji
  @Test
  public void testFST2() throws IOException {
    String inputValues[] = {
      "brats", "cat", "dog", "dogs", "rat",
    };

    int outputValues[] = {1, 3, 5, 7, 11};

    Builder builder = new Builder();
    builder.build(inputValues, outputValues);

    for (int i = 0; i < inputValues.length; i++) {
      assertEquals(outputValues[i], builder.transduce(inputValues[i]));
    }

    Compiler compiledFST = builder.getCompiler();
    FST fst = new FST(compiledFST.getByteArray());

    assertEquals(0, fst.lookup("brat")); // Prefix match
    assertEquals(1, fst.lookup("brats"));
    assertEquals(3, fst.lookup("cat"));
    assertEquals(5, fst.lookup("dog"));
    assertEquals(7, fst.lookup("dogs"));
    assertEquals(11, fst.lookup("rat"));
    assertEquals(-1, fst.lookup("rats")); // No match
  }
コード例 #12
0
 protected void onEnable() {
   // We have to check because the first time through
   // it won't be paused.
   if (builder.isPaused()) {
     builder.resume();
   }
 }
コード例 #13
0
 private TermParameterDefinition(Builder builder) {
   id = builder.getId();
   termId = builder.getTermId();
   name = builder.getName();
   value = builder.getValue();
   versionNumber = builder.getVersionNumber();
 }
コード例 #14
0
 public static Builder newBuilder(Wheel copy) {
   Builder builder = new Builder();
   builder.size = copy.size;
   builder.type = copy.type;
   builder.colour = copy.colour;
   return builder;
 }
コード例 #15
0
ファイル: Test.java プロジェクト: yangnn/design-pattern
 public static void main(String args[]) {
   Builder builder = new Builder();
   list = builder.produceMailSender(10);
   for (Sender s : list) {
     s.send();
   }
 }
コード例 #16
0
 private static Builder create() {
   Builder builder = new Builder();
   builder.result =
       new org.waveprotocol.box.server.persistence.protos.ProtoDeltaStoreData
           .ProtoTransformedWaveletDelta();
   return builder;
 }
コード例 #17
0
  /** Check if the getSubBuilders properly predicts the output. */
  public static void testSubBuilders() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    Project project = ws.getProject("p4-sub");

    Collection<? extends Builder> bs = project.getSubBuilders();
    assertNotNull(bs);
    assertEquals(3, bs.size());
    Set<String> names = new HashSet<String>();
    for (Builder b : bs) {
      names.add(b.getBsn());
    }
    assertTrue(names.contains("p4-sub.a"));
    assertTrue(names.contains("p4-sub.b"));
    assertTrue(names.contains("p4-sub.c"));

    File[] files = project.build();
    assertTrue(project.check());

    System.err.println(Processor.join(project.getErrors(), "\n"));
    System.err.println(Processor.join(project.getWarnings(), "\n"));
    assertEquals(0, project.getErrors().size());
    assertEquals(0, project.getWarnings().size());
    assertNotNull(files);
    assertEquals(3, files.length);
    for (File file : files) {
      Jar jar = new Jar(file);
      Manifest m = jar.getManifest();
      assertTrue(names.contains(m.getMainAttributes().getValue("Bundle-SymbolicName")));
    }
  }
コード例 #18
0
ファイル: Cause.java プロジェクト: CrystalMageX/SpongeAPI
 public static Cause of(Iterable<NamedCause> iterable) {
   Builder builder = builder();
   for (NamedCause cause : iterable) {
     builder.named(cause);
   }
   return builder.build();
 }
コード例 #19
0
 private static Builder create() {
   Builder builder = new Builder();
   builder.result =
       new com.alachisoft.tayzgrid.common.protobuf.TaskEnumeratorEntryProtocol
           .TaskEnumeratorEntry();
   return builder;
 }
コード例 #20
0
 @Override
 public MetadataFieldMapper.Builder parse(
     String name, Map<String, Object> node, ParserContext parserContext)
     throws MapperParsingException {
   Builder builder = new Builder(parserContext.type());
   for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator();
       iterator.hasNext(); ) {
     Map.Entry<String, Object> entry = iterator.next();
     String fieldName = Strings.toUnderscoreCase(entry.getKey());
     Object fieldNode = entry.getValue();
     if (fieldName.equals("type")) {
       builder.type(fieldNode.toString());
       iterator.remove();
     } else if (fieldName.equals("postings_format")
         && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
       // ignore before 2.0, reject on and after 2.0
       iterator.remove();
     } else if (fieldName.equals("fielddata")) {
       // Only take over `loading`, since that is the only option now that is configurable:
       Map<String, String> fieldDataSettings =
           SettingsLoader.Helper.loadNestedFromMap(nodeMapValue(fieldNode, "fielddata"));
       if (fieldDataSettings.containsKey(MappedFieldType.Loading.KEY)) {
         Settings settings =
             settingsBuilder()
                 .put(
                     MappedFieldType.Loading.KEY,
                     fieldDataSettings.get(MappedFieldType.Loading.KEY))
                 .build();
         builder.fieldDataSettings(settings);
       }
       iterator.remove();
     }
   }
   return builder;
 }
コード例 #21
0
  /** Test the {@link PaymentCalc#multiply(java.math.BigDecimal)} method. */
  @Test
  public void multiply() {
    PaymentCalc calc =
        Builder.n()
            .grossAmount(new BigDecimal(500d))
            .fees(new BigDecimal(100.25d))
            .interest(new BigDecimal(50d))
            .other1(new BigDecimal(100d))
            .other2(new BigDecimal(75))
            .settlementAmount(new BigDecimal(175d))
            .nettAmount(new BigDecimal(400d))
            .get();

    PaymentCalc actual = calc.clone();
    actual.multiply(new BigDecimal(0.50d));

    PaymentCalc expected =
        Builder.n()
            .grossAmount(new BigDecimal(250d))
            .fees(new BigDecimal("50.12"))
            .interest(new BigDecimal(25d))
            .other1(new BigDecimal(50d))
            .other2(new BigDecimal(37.5))
            .settlementAmount(new BigDecimal(87.5d))
            .nettAmount(new BigDecimal(200d))
            .get();
    // This is just to sen the scale and rounding.
    expected.multiply(new BigDecimal(1));

    assertThat(actual).isEqualTo(expected);
  }
コード例 #22
0
ファイル: SingleParser.java プロジェクト: dirkk/basex
 @Override
 public final void parse(final Builder build) throws IOException {
   builder = build;
   builder.openDoc(token(target + source.name()));
   parse();
   builder.closeDoc();
 }
コード例 #23
0
ファイル: Foos.java プロジェクト: amikey/wire
 @Override
 public Foos redact(Foos value) {
   Builder builder = value.newBuilder();
   redactElements(builder.foos, Foo.ADAPTER);
   builder.clearUnknownFields();
   return builder.build();
 }
コード例 #24
0
ファイル: Parser.java プロジェクト: ironted/knox
 private void consumeAuthorityToken(String token) {
   if (token != null) {
     Token paramPattern;
     String[] usernamePassword = null, hostPort;
     String[] userAddr = split(token, '@');
     if (userAddr.length == 1) {
       hostPort = split(userAddr[0], ':');
     } else {
       usernamePassword = split(userAddr[0], ':');
       hostPort = split(userAddr[1], ':');
     }
     if (usernamePassword != null) {
       if (usernamePassword[0].length() > 0) {
         paramPattern =
             makeTokenSingular(parseTemplateToken(usernamePassword[0], Segment.STAR_PATTERN));
         builder.setUsername(paramPattern);
       }
       if (usernamePassword.length > 1 && usernamePassword[1].length() > 0) {
         paramPattern =
             makeTokenSingular(parseTemplateToken(usernamePassword[1], Segment.STAR_PATTERN));
         builder.setPassword(paramPattern);
       }
     }
     if (hostPort[0].length() > 0) {
       paramPattern = makeTokenSingular(parseTemplateToken(hostPort[0], Segment.STAR_PATTERN));
       builder.setHost(paramPattern);
     }
     if (hostPort.length > 1 && hostPort[1].length() > 0) {
       paramPattern = makeTokenSingular(parseTemplateToken(hostPort[1], Segment.STAR_PATTERN));
       builder.setPort(paramPattern);
     }
   }
 }
コード例 #25
0
 public static Builder newBuilder(Location copy) {
   Builder builder = new Builder();
   builder.id = copy.id;
   builder.address = copy.address;
   builder.channel = copy.channel;
   return builder;
 }
コード例 #26
0
ファイル: Parser.java プロジェクト: ironted/knox
 private void consumeQuerySegment(String token) {
   if (token != null && token.length() > 0) {
     // Shorthand format {queryParam} == queryParam={queryParam=*}
     if (TEMPLATE_OPEN_MARKUP == token.charAt(0)) {
       Token paramPattern = parseTemplateToken(token, Segment.GLOB_PATTERN);
       String paramName = paramPattern.parameterName;
       if (paramPattern.originalPattern == null) {
         builder.addQuery(paramName, new Token(paramName, null, Segment.GLOB_PATTERN));
         //          if( Segment.STAR_PATTERN.equals( paramName ) || Segment.GLOB_PATTERN.equals(
         // paramName ) ) {
         //            builder.addQuery( paramName, new Token( paramName, null,
         // Segment.GLOB_PATTERN ) );
         //          } else {
         //            builder.addQuery( paramName, new Token( paramName, null,
         // Segment.GLOB_PATTERN ) );
         //          }
       } else {
         builder.addQuery(paramName, new Token(paramName, paramPattern.originalPattern));
       }
     } else {
       String nameValue[] = split(token, '=');
       if (nameValue.length == 1) {
         String queryName = nameValue[0];
         builder.addQuery(queryName, new Token(Segment.ANONYMOUS_PARAM, null));
       } else {
         String queryName = nameValue[0];
         Token paramPattern = parseTemplateToken(nameValue[1], Segment.GLOB_PATTERN);
         builder.addQuery(queryName, paramPattern);
       }
     }
   }
 }
コード例 #27
0
ファイル: Chip.java プロジェクト: shroman3/SSDPlayer
 @SuppressWarnings("unchecked")
 public Pair<Chip<P, B, T>, Integer> clean(int chipIndex) {
   List<T> cleanPlanes = new ArrayList<T>(getPlanesNum());
   int moved = 0;
   int i = 0;
   boolean cleaningInvoked = false;
   for (T plane : getPlanes()) {
     Pair<? extends Plane<P, B>, Integer> clean = plane.clean();
     if (clean == null) {
       cleanPlanes.add(plane);
     } else {
       cleaningInvoked = true;
       moved += clean.getValue1();
       ActionLog.addAction(new CleanAction(chipIndex, i, clean.getValue1()));
       cleanPlanes.add((T) clean.getValue0());
     }
     i++;
   }
   if (!cleaningInvoked) {
     return null;
   }
   Builder<P, B, T> builder = getSelfBuilder();
   builder.setPlanes(cleanPlanes).setTotalGCInvocations(getTotalGCInvocations() + 1);
   return new Pair<Chip<P, B, T>, Integer>(builder.build(), moved);
 }
コード例 #28
0
ファイル: PairList.java プロジェクト: bedatadriven/renjin
 public Builder newCopyBuilder() {
   Builder builder = new Builder();
   for (Node node : nodes()) {
     builder.add(node.getRawTag(), node.getValue());
   }
   return builder;
 }
コード例 #29
0
ファイル: InvertedIndex1.java プロジェクト: wubs/485-Project
    public void map(LongWritable key, Text value, Context context)
        throws IOException, InterruptedException {

      String strId = "";
      String strBody = "";

      // Parse the xml and read data (page id and article body)
      // Using XOM library
      Builder builder = new Builder();

      try {
        Document doc = builder.build(value.toString(), null);

        Nodes nodeId = doc.query("//eecs485_article_id");
        strId = nodeId.get(0).getChild(0).getValue();

        Nodes nodeBody = doc.query("//eecs485_article_body");
        strBody = nodeBody.get(0).getChild(0).getValue();
      } catch (ParsingException ex) {
        System.out.println("Not well-formed.");
        System.out.println(ex.getMessage());
      } catch (IOException ex) {
        System.out.println("io exception");
      }

      // Tokenize document body
      Pattern pattern = Pattern.compile("\\w+");
      Matcher matcher = pattern.matcher(strBody);

      while (matcher.find()) {
        // Write the parsed token
        // key = term, docid   value = 1
        context.write(new Text(matcher.group() + "," + strId), one);
      }
    }
コード例 #30
0
ファイル: FooBar.java プロジェクト: pforhan/wire
 @Override
 public Builder newBuilder() {
   Builder builder = new Builder();
   builder.serial = WireInternal.copyOf("serial", serial);
   builder.addUnknownFields(unknownFields());
   return builder;
 }