org.apache.ignite.internal.portable.api

## Interface PortableBuilder

All Known Implementing Classes:
  PortableBuilderImpl

    public interface PortableBuilder

Portable object builder. Provides ability to build portable objects dynamically without having class definitions.

Here is an example of how a portable object can be built dynamically:

     PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");

     builder.setField("fieldA", "A");
     builder.setField("fieldB", "B");

     PortableObject portableObj = builder.build();

Also builder can be initialized by existing portable object. This allows changing some fields without affecting other fields.

     PortableBuilder builder = Ignition.ignite().portables().builder(person);

     builder.setField("name", "John");

     person = builder.build();

If you need to modify nested portable object you can get builder for nested object using `getField(String)`, changes made on nested builder will affect parent object, for example:

     PortableBuilder personBuilder = grid.portables().createBuilder(personPortableObj);
     PortableBuilder addressBuilder = personBuilder.setField("address");

     addressBuilder.setField("city", "New York");

     personPortableObj = personBuilder.build();

     // Should be "New York".
     String city = personPortableObj.getField("address").getField("city");

See Also:
  `IgnitePortables.builder(int)`, `IgnitePortables.builder(String)`, `IgnitePortables.builder(PortableObject)`

### Method Summary

Methods
`PortableObject` `build()` Builds portable object.
`<T> T` `getField(String name)` Returns value assigned to the specified field.
`PortableBuilder` `hashCode(int hashCode)` Sets hash code for resulting portable object returned by `build()` method.
`PortableBuilder` `removeField(String fieldName)` Removes field from this builder.
`PortableBuilder` `setField(String name, Object val)` Sets field value.
`PortableBuilder` `setField(String name, PortableBuilder builder)` Sets field value.
`<T> PortableBuilder` `setField(String name, T val, Class<? super T> type)` Sets field value with value type specification.

### Method Detail

#### getField

    <T> T getField(String name)

Returns value assigned to the specified field. If the value is a portable object instance of `GridPortableBuilder` will be returned, which can be modified.

Collections and maps returned from this method are modifiable.

Parameters:
  `name` - Field name.
Returns:
  Filed value.

#### setField

    PortableBuilder setField(String name,
                           Object val)

Sets field value.

Parameters:
  `name` - Field name.
  `val` - Field value (cannot be `null`).
See Also:
  `PortableObject.metaData()`

#### setField

    <T> PortableBuilder setField(String name,
                               @Nullable
                               T val,
                               Class<? super T> type)

Sets field value with value type specification.

Field type is needed for proper metadata update.

Parameters:
  `name` - Field name.
  `val` - Field value.
  `type` - Field type.
See Also:
  `PortableObject.metaData()`

#### setField

    PortableBuilder setField(String name,
                           @Nullable
                           PortableBuilder builder)

Sets field value.

This method should be used if field is portable object.

Parameters:
  `name` - Field name.
  `builder` - Builder for object field.

#### removeField

    PortableBuilder removeField(String fieldName)

Removes field from this builder.

Parameters:
  `fieldName` - Field name.
Returns:
  `this` instance for chaining.

#### hashCode

    PortableBuilder hashCode(int hashCode)

Sets hash code for resulting portable object returned by `build()` method.

If not set `0` is used.

Parameters:
  `hashCode` - Hash code.
Returns:
  `this` instance for chaining.

#### build

    PortableObject build()
                         throws PortableException

Builds portable object.

Returns:
  Portable object.
Throws:
  `PortableException` - In case of error.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.4.0
Release Date | : September 24 2015