1

I have two BinaryObjects:

BinaryObject bo1;
BinaryObject bo2;

Is there a way to compose this two binary objects. I mean to add all fields from bo1 to bo2 which does not exist in bo2? I tried

bo1.toBuilder();
bo2.toBuilder();

But I didn't find a way to compose these builders into one I need. The thing is I don't know fields in these objects.

Actually I have cache with BinaryObjects as values. I'm writing StreamReceiver to update its values the way I specified above. That way I have to implement the following method:

@Override
public void receive(IgniteCache<String, BinaryObject> cache, Collection<Map.Entry<String, BinaryObject>> entries) throws IgniteException {
    BinaryObject objOld = cache.get(entry.getKey());      
    BinaryObjectBuilder previous = objOld.toBuilder();
    BinaryObject objNew = entry.getValue();
    BinaryObjectBuilder current = objNew.toBuilder();
    //...
}
St.Antario
  • 26,175
  • 41
  • 130
  • 318

1 Answers1

2

There is no one-liner for this. But you can create a builder from the object you're merging to, and use BinaryObject.type().fieldNames() on the second object to get list of fields it contains. Then iterate through these fields and append values to builder.

Valentin Kulichenko
  • 8,365
  • 1
  • 16
  • 12