public static ShardOperationFailedException[] groupBy(ShardOperationFailedException[] failures){
  List<ShardOperationFailedException> uniqueFailures=new ArrayList<>();
  Set<GroupBy> reasons=new HashSet<>();
  for (  ShardOperationFailedException failure : failures) {
    GroupBy reason=new GroupBy(failure.getCause());
    if (reasons.contains(reason) == false) {
      reasons.add(reason);
      uniqueFailures.add(failure);
    }
  }
  return uniqueFailures.toArray(new ShardOperationFailedException[0]);
}

public static ShardOperationFailedException [ ] groupBy ( ShardOperationFailedException [ ] failures ) { List < ShardOperationFailedException > uniqueFailures = new ArrayList < > ( ) ; Set < GroupBy > reasons = new HashSet < > ( ) ; for ( ShardOperationFailedException failure : failures ) { GroupBy reason = new GroupBy ( failure . getCause ( ) ) ; if ( reasons . contains ( reason ) == false ) { reasons . add ( reason ) ; uniqueFailures . add ( failure ) ; } } return uniqueFailures . toArray ( new ShardOperationFailedException [ 0 ] ) ; }
deduplicate the failures by exception message and index .
