public Builder removeTimestamps ( final Builder builder ) { final Descriptors . Descriptor descriptorForType = builder . getDescriptorForType ( ) ; for ( final Descriptors . FieldDescriptor field : descriptorForType . getFields ( ) ) { // if the field is not repeated, a message and a timestamp it is cleared if ( ! field . isRepeated ( ) && field . getType ( ) == Descriptors . FieldDescriptor . Type . MESSAGE ) { //=============================================================== //TODO: This is just a hack since states in units now contain action descriptions, // This line prevents resource allocations to be checked because they contain required fields // and thus if they are checked calling build on the builder afterwards fails. // can be removed after switching to protobuf 3 or replacing the resource allocation type if ( field . getName ( ) . equals ( RESOURCE_ALLOCATION_FIELD ) ) { continue ; } //=============================================================== if ( field . getMessageType ( ) . getName ( ) . equals ( TIMESTAMP_MESSAGE_NAME ) ) { builder . clearField ( field ) ; } else { // skip checking recursively if the field is not even initialized if ( builder . hasField ( field ) ) { removeTimestamps ( builder . getFieldBuilder ( field ) ) ; } } } } return builder ; }
Recursively clear timestamp messages from a builder . For efficiency repeated fields are ignored .