public static AliasMetaData fromXContent(XContentParser parser) throws IOException {
      Builder builder = new Builder(parser.currentName());

      String currentFieldName = null;
      XContentParser.Token token = parser.nextToken();
      if (token == null) {
        // no data...
        return builder.build();
      }
      while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
          currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
          if ("filter".equals(currentFieldName)) {
            Map<String, Object> filter = parser.mapOrdered();
            builder.filter(filter);
          }
        } else if (token == XContentParser.Token.VALUE_EMBEDDED_OBJECT) {
          if ("filter".equals(currentFieldName)) {
            builder.filter(new CompressedString(parser.binaryValue()));
          }
        } else if (token == XContentParser.Token.VALUE_STRING) {
          if ("routing".equals(currentFieldName)) {
            builder.routing(parser.text());
          } else if ("index_routing".equals(currentFieldName)
              || "indexRouting".equals(currentFieldName)) {
            builder.indexRouting(parser.text());
          } else if ("search_routing".equals(currentFieldName)
              || "searchRouting".equals(currentFieldName)) {
            builder.searchRouting(parser.text());
          }
        }
      }
      return builder.build();
    }
Exemple #2
0
 @Override
 public Nested decode(ProtoReader reader) throws IOException {
   Builder builder = new Builder();
   long token = reader.beginMessage();
   for (int tag; (tag = reader.nextTag()) != -1; ) {
     switch (tag) {
       case 1:
         {
           try {
             builder.value(FooBarBazEnum.ADAPTER.decode(reader));
           } catch (ProtoAdapter.EnumConstantNotFoundException e) {
             builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
           }
           break;
         }
       default:
         {
           FieldEncoding fieldEncoding = reader.peekFieldEncoding();
           Object value = fieldEncoding.rawProtoAdapter().decode(reader);
           builder.addUnknownField(tag, fieldEncoding, value);
         }
     }
   }
   reader.endMessage(token);
   return builder.build();
 }
 public Notification build() {
   Notification notification = null;
   if (mBuilder != null) {
     notification = mBuilder.build();
   }
   return notification;
 }
Exemple #4
0
 @Override
 public MethodOptions redact(MethodOptions value) {
   Builder builder = value.newBuilder();
   Internal.redactElements(builder.uninterpreted_option, UninterpretedOption.ADAPTER);
   builder.clearUnknownFields();
   return builder.build();
 }
 @Override
 public IndexMetaData readFrom(StreamInput in) throws IOException {
   Builder builder = new Builder(in.readString());
   builder.version(in.readLong());
   builder.state(State.fromId(in.readByte()));
   builder.settings(readSettingsFromStream(in));
   int mappingsSize = in.readVInt();
   for (int i = 0; i < mappingsSize; i++) {
     MappingMetaData mappingMd = MappingMetaData.PROTO.readFrom(in);
     builder.putMapping(mappingMd);
   }
   int aliasesSize = in.readVInt();
   for (int i = 0; i < aliasesSize; i++) {
     AliasMetaData aliasMd = AliasMetaData.Builder.readFrom(in);
     builder.putAlias(aliasMd);
   }
   int customSize = in.readVInt();
   for (int i = 0; i < customSize; i++) {
     String type = in.readString();
     Custom customIndexMetaData = lookupPrototypeSafe(type).readFrom(in);
     builder.putCustom(type, customIndexMetaData);
   }
   int activeAllocationIdsSize = in.readVInt();
   for (int i = 0; i < activeAllocationIdsSize; i++) {
     int key = in.readVInt();
     Set<String> allocationIds =
         DiffableUtils.StringSetValueSerializer.getInstance().read(in, key);
     builder.putActiveAllocationIds(key, allocationIds);
   }
   return builder.build();
 }
Exemple #6
0
    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);
      }
    }
Exemple #7
0
  public static void testEnum() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());

    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Enums.xml");
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());
    assertEquals(
        "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI());

    Properties p = new Properties();
    p.setProperty("r", "requireConfiguration");
    p.setProperty("i", "ignoreConfiguration");
    p.setProperty("o", "optionalConfiguration");
    Enums enums = Configurable.createConfigurable(Enums.class, (Map<Object, Object>) p);
    assertEquals(Enums.X.requireConfiguration, enums.r());
    assertEquals(Enums.X.ignoreConfiguration, enums.i());
    assertEquals(Enums.X.optionalConfiguration, enums.o());
  }
Exemple #8
0
 @Override
 public RedactedExtension redact(RedactedExtension value) {
   Builder builder = value.newBuilder();
   builder.d = null;
   builder.clearUnknownFields();
   return builder.build();
 }
Exemple #9
0
 public static Cause of(Iterable<NamedCause> iterable) {
   Builder builder = builder();
   for (NamedCause cause : iterable) {
     builder.named(cause);
   }
   return builder.build();
 }
Exemple #10
0
  @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
  }
Exemple #11
0
 @Override
 public Foos redact(Foos value) {
   Builder builder = value.newBuilder();
   redactElements(builder.foos, Foo.ADAPTER);
   builder.clearUnknownFields();
   return builder.build();
 }
Exemple #12
0
 /** 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();
 }
Exemple #13
0
 @Override
 public RedactedChild decode(ProtoReader reader) throws IOException {
   Builder builder = new Builder();
   long token = reader.beginMessage();
   for (int tag; (tag = reader.nextTag()) != -1; ) {
     switch (tag) {
       case 1:
         builder.a(ProtoAdapter.STRING.decode(reader));
         break;
       case 2:
         builder.b(Redacted.ADAPTER.decode(reader));
         break;
       case 3:
         builder.c(NotRedacted.ADAPTER.decode(reader));
         break;
       default:
         {
           FieldEncoding fieldEncoding = reader.peekFieldEncoding();
           Object value = fieldEncoding.rawProtoAdapter().decode(reader);
           builder.addUnknownField(tag, fieldEncoding, value);
         }
     }
   }
   reader.endMessage(token);
   return builder.build();
 }
Exemple #14
0
 @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);
 }
Exemple #15
0
 public Template parseTemplate(String template) throws URISyntaxException {
   this.template = template;
   builder = new Builder(template);
   builder.setHasScheme(false);
   builder.setHasAuthority(
       false); // Assume no until found otherwise.  If true, will cause // in output URL.
   builder.setIsAuthorityOnly(false);
   builder.setIsAbsolute(
       false); // Assume relative until found otherwise.  If true, will cause leading / in output
   // URL.
   builder.setIsDirectory(
       false); // Assume a file path until found otherwise.  If true, will cause trailing / in
   // output URL.
   builder.setHasQuery(
       false); // Assume no ? until found otherwise.  If true, will cause ? in output URL.
   builder.setHasFragment(
       false); // Assume no # until found otherwise.  If true, will cause # in output URL.
   Matcher match = PATTERN.matcher(template);
   if (match.matches()) {
     consumeSchemeMatch(match);
     consumeAuthorityMatch(match);
     consumePathMatch(match);
     consumeQueryMatch(match);
     consumeFragmentMatch(match);
     fixNakedAuthority();
   } else {
     throw new URISyntaxException(template, RES.parseTemplateFailureReason(template));
   }
   return builder.build();
 }
 public static Settings readSettingsFromStream(StreamInput in) throws IOException {
   Builder builder = new Builder();
   int numberOfSettings = in.readVInt();
   for (int i = 0; i < numberOfSettings; i++) {
     builder.put(in.readString(), in.readString());
   }
   return builder.build();
 }
Exemple #17
0
 @Override
 public A redact(A value) {
   Builder builder = value.newBuilder();
   if (builder.c != null) builder.c = B.ADAPTER.redact(builder.c);
   if (builder.d != null) builder.d = D.ADAPTER.redact(builder.d);
   builder.clearUnknownFields();
   return builder.build();
 }
Exemple #18
0
 /**
  * Builds the <code>Project</code>. If the input argument is <code>false</code>, the <code>
  * build(boolean)</code> method rebuilds the <code>Project</code>. If the input argument is <code>
  * true</code>, this method builds incrementally.
  *
  * <p>All the <code>Application</code> and <code>Library</code> objects have their output
  * destinations set with the <code>Application.setOutput()</code> and <code>
  * Library.setOutput/setDirectory()</code> methods.
  *
  * @param incremental If <code>true</code>, build incrementally; if <code>false</code>, rebuild.
  * @throws IOException when an I/O error occurs in any one of the compilations.
  */
 public void build(boolean incremental) throws IOException {
   for (Iterator<Builder> i = getBuildOrder(); i.hasNext(); ) {
     Builder builder = i.next();
     if (builder != null) {
       builder.build(incremental);
     }
   }
 }
Exemple #19
0
 @Override
 public FieldDescriptorProto redact(FieldDescriptorProto value) {
   Builder builder = value.newBuilder();
   if (builder.options != null)
     builder.options = FieldOptions.ADAPTER.redact(builder.options);
   builder.clearUnknownFields();
   return builder.build();
 }
Exemple #20
0
 /** The default policy is truncate micro. Check if this is applied to the import. */
 public static void testImportMicroTruncated() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.setProperty("Import-Package", "org.osgi.service.event");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   assertEquals("[1.0,2)", s);
 }
 private void carregarFitxer(String rutaFitxer) throws ParcAtraccionsExcepcio {
   Builder builder = new Builder();
   try {
     doc = builder.build(rutaFitxer);
   } catch (Exception e) {
     throw new ParcAtraccionsExcepcio("GestorXML.carregar");
   }
 }
Exemple #22
0
 public static Cause of(NamedCause cause, NamedCause... causes) {
   Builder builder = builder();
   builder.named(cause);
   for (NamedCause namedCause : causes) {
     builder.named(namedCause);
   }
   return builder.build();
 }
Exemple #23
0
 @Override
 public FooBar redact(FooBar value) {
   Builder builder = value.newBuilder();
   if (builder.baz != null) builder.baz = Nested.ADAPTER.redact(builder.baz);
   WireInternal.redactElements(builder.nested, FooBar.ADAPTER);
   builder.clearUnknownFields();
   return builder.build();
 }
Exemple #24
0
 @Override
 public RedactedChild redact(RedactedChild value) {
   Builder builder = value.newBuilder();
   if (builder.b != null) builder.b = Redacted.ADAPTER.redact(builder.b);
   if (builder.c != null) builder.c = NotRedacted.ADAPTER.redact(builder.c);
   builder.clearUnknownFields();
   return builder.build();
 }
 Object readResolve() {
   int n = elements.length;
   Builder<E> builder = new Builder<E>(comparator);
   for (int i = 0; i < n; i++) {
     builder.addCopies(elements[i], counts[i]);
   }
   return builder.build();
 }
 private ImmutableSetMultimap<V, K> invert() {
   Builder<V, K> builder = builder();
   for (Entry<K, V> entry : entries()) {
     builder.put(entry.getValue(), entry.getKey());
   }
   ImmutableSetMultimap<V, K> invertedMultimap = builder.build();
   invertedMultimap.inverse = this;
   return invertedMultimap;
 }
 public DiscoveryNodes removeDeadMembers(Set<String> newNodes, String masterNodeId) {
   Builder builder = new Builder().masterNodeId(masterNodeId).localNodeId(localNodeId);
   for (DiscoveryNode node : this) {
     if (newNodes.contains(node.id())) {
       builder.put(node);
     }
   }
   return builder.build();
 }
Exemple #28
0
 /**
  * Create a new instance with the given objects as the cause, where the first-most object is the
  * initial initiator and those following it are controlled by the previous entry.
  *
  * @param cause An array of causing objects
  * @return A cause
  */
 public static Cause create(@Nullable Object... cause) {
   if (cause != null) {
     Builder builder = new Builder(cause.length);
     builder.addAll(cause);
     return builder.build();
   } else {
     return UNKNOWN;
   }
 }
Exemple #29
0
 @Override
 public FooBar decode(ProtoReader reader) throws IOException {
   Builder builder = new Builder();
   long token = reader.beginMessage();
   for (int tag; (tag = reader.nextTag()) != -1; ) {
     switch (tag) {
       case 1:
         builder.foo(ProtoAdapter.INT32.decode(reader));
         break;
       case 2:
         builder.bar(ProtoAdapter.STRING.decode(reader));
         break;
       case 3:
         builder.baz(Nested.ADAPTER.decode(reader));
         break;
       case 4:
         builder.qux(ProtoAdapter.UINT64.decode(reader));
         break;
       case 5:
         builder.fred.add(ProtoAdapter.FLOAT.decode(reader));
         break;
       case 6:
         builder.daisy(ProtoAdapter.DOUBLE.decode(reader));
         break;
       case 7:
         builder.nested.add(FooBar.ADAPTER.decode(reader));
         break;
       case 101:
         {
           try {
             builder.ext(FooBarBazEnum.ADAPTER.decode(reader));
           } catch (ProtoAdapter.EnumConstantNotFoundException e) {
             builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
           }
           break;
         }
       case 102:
         {
           try {
             builder.rep.add(FooBarBazEnum.ADAPTER.decode(reader));
           } catch (ProtoAdapter.EnumConstantNotFoundException e) {
             builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
           }
           break;
         }
       default:
         {
           FieldEncoding fieldEncoding = reader.peekFieldEncoding();
           Object value = fieldEncoding.rawProtoAdapter().decode(reader);
           builder.addUnknownField(tag, fieldEncoding, value);
         }
     }
   }
   reader.endMessage(token);
   return builder.build();
 }
Exemple #30
0
 @Override
 public FieldDescriptorProto decode(ProtoReader reader) throws IOException {
   Builder builder = new Builder();
   long token = reader.beginMessage();
   for (int tag; (tag = reader.nextTag()) != -1; ) {
     switch (tag) {
       case 1:
         builder.name(ProtoAdapter.STRING.decode(reader));
         break;
       case 9:
         builder.doc(ProtoAdapter.STRING.decode(reader));
         break;
       case 3:
         builder.number(ProtoAdapter.INT32.decode(reader));
         break;
       case 4:
         {
           try {
             builder.label(Label.ADAPTER.decode(reader));
           } catch (ProtoAdapter.EnumConstantNotFoundException e) {
             builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
           }
           break;
         }
       case 5:
         {
           try {
             builder.type(Type.ADAPTER.decode(reader));
           } catch (ProtoAdapter.EnumConstantNotFoundException e) {
             builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
           }
           break;
         }
       case 6:
         builder.type_name(ProtoAdapter.STRING.decode(reader));
         break;
       case 2:
         builder.extendee(ProtoAdapter.STRING.decode(reader));
         break;
       case 7:
         builder.default_value(ProtoAdapter.STRING.decode(reader));
         break;
       case 8:
         builder.options(FieldOptions.ADAPTER.decode(reader));
         break;
       default:
         {
           FieldEncoding fieldEncoding = reader.peekFieldEncoding();
           Object value = fieldEncoding.rawProtoAdapter().decode(reader);
           builder.addUnknownField(tag, fieldEncoding, value);
         }
     }
   }
   reader.endMessage(token);
   return builder.build();
 }