Beispiel #1
0
 @Override
 @SuppressWarnings("unchecked")
 public Builder addTo(int key, Object value) {
   CField field = descriptor.getField(key);
   if (field == null) {
     return this; // soft ignoring unsupported fields.
   }
   if (this.unionField != field || this.currentValue == null) {
     this.unionField = field;
     switch (field.getType()) {
       case LIST:
         {
           PList lType = (PList) field.getDescriptor();
           this.currentValue = lType.builder();
           break;
         }
       case SET:
         {
           PSet lType = (PSet) field.getDescriptor();
           this.currentValue = lType.builder();
           break;
         }
       default:
         {
           throw new IllegalArgumentException(
               "Unable to accept addTo on non-list unionField " + field.getName());
         }
     }
   }
   if (value == null) {
     throw new IllegalArgumentException("Adding null item to collection " + field.getName());
   }
   switch (field.getType()) {
     case LIST:
       {
         ((PList.Builder) this.currentValue).add(value);
         break;
       }
     case SET:
       {
         ((PList.Builder) this.currentValue).add(value);
         break;
       }
   }
   return this;
 }