/*-------------------------------------------------------------------------
Grouping:
-------------------------------------------------------------------------
762668
public function groupRecords($records)
    {
        if (!is_array($records) || empty($records)) {
            return;
        }

        $groups = array('year' => array());

        foreach ($records as $r) {
            $data = $r->getData($this->get('id'));

            $timestamp = DateTimeObj::get('U', $data['value']);
            $info = getdate($timestamp);

            $year = $info['year'];
            $month = ($info['mon'] < 10 ? '0' . $info['mon'] : $info['mon']);

            if (!isset($groups['year'][$year])) {
                $groups['year'][$year] = array(
                    'attr' => array('value' => $year),
                    'records' => array(),
                    'groups' => array()
                );
            }

            if (!isset($groups['year'][$year]['groups']['month'])) {
                $groups['year'][$year]['groups']['month'] = array();
            }

            if (!isset($groups['year'][$year]['groups']['month'][$month])) {
                $groups['year'][$year]['groups']['month'][$month] = array(
                    'attr' => array('value' => $month),
                    'records' => array(),
                    'groups' => array()
                );
            }

            $groups['year'][$year]['groups']['month'][$month]['records'][] = $r;
        }

        return $groups;
    }
1055848
public void setThingGroups(java.util.Collection<ThingGroupDocument> thingGroups) {
        if (thingGroups == null) {
            this.thingGroups = null;
            return;
        }

        this.thingGroups = new java.util.ArrayList<ThingGroupDocument>(thingGroups);
    }
155940
private void selectGroup(final Object key, final Handler<AsyncResult<String>> doneHandler) {
    context.execute(new Action<String>() {
      @Override
      public String perform() {
        String address = groupSelectors.get(key);
        if (address != null) {
          return address;
        }
        Set<String> groups = DefaultClusterManager.this.groups.keySet();
        int index = new Random().nextInt(groups.size());
        int i = 0;
        for (String group : groups) {
          if (i == index) {
            groupSelectors.put(key, group);
            return group;
          }
          i++;
        }
        return null;
      }
    }, doneHandler);
  }
787420
public void removeGroup(String group) {
        if (worldGroupExist(group)) {
            Common.getInstance().getStorageHandler().getStorageEngine().removeWorldGroup(group);
            list.remove(group);
        }
    }
683545
public void setGroupList(java.util.Collection<Group> groupList) {
        if (groupList == null) {
            this.groupList = null;
            return;
        }

        this.groupList = new java.util.ArrayList<Group>(groupList);
    }
82379
private void handleFragmentGrouping(IReaction rxn, CxSmilesState cxstate) {
        // repartition/merge fragments
        if (cxstate.fragGroups != null) {

            final int reactant = 1;
            final int agent    = 2;
            final int product  = 3;

            // note we don't use a list for fragmap as the indexes need to stay consistent
            Map<Integer,IAtomContainer> fragMap = new LinkedHashMap<>();
            Map<IAtomContainer,Integer> roleMap = new HashMap<>();

            for (IAtomContainer mol : rxn.getReactants().atomContainers()) {
                fragMap.put(fragMap.size(), mol);
                roleMap.put(mol, reactant);
            }
            for (IAtomContainer mol : rxn.getAgents().atomContainers()) {
                fragMap.put(fragMap.size(), mol);
                roleMap.put(mol, agent);
            }
            for (IAtomContainer mol : rxn.getProducts().atomContainers()) {
                fragMap.put(fragMap.size(), mol);
                roleMap.put(mol, product);
            }

            // check validity of group
            boolean invalid = false;
            Set<Integer> visit = new HashSet<>();

            for (List<Integer> grouping : cxstate.fragGroups) {
                IAtomContainer dest = fragMap.get(grouping.get(0));
                if (dest == null)
                    continue;
                if (!visit.add(grouping.get(0)))
                    invalid = true;
                for (int i = 1; i < grouping.size(); i++) {
                    if (!visit.add(grouping.get(i)))
                        invalid = true;
                    IAtomContainer src = fragMap.get(grouping.get(i));
                    if (src != null) {
                        dest.add(src);
                        roleMap.put(src, 0); // no-role
                    }
                }
            }

            if (!invalid) {
                rxn.getReactants().removeAllAtomContainers();
                rxn.getAgents().removeAllAtomContainers();
                rxn.getProducts().removeAllAtomContainers();
                for (IAtomContainer mol : fragMap.values()) {
                    switch (roleMap.get(mol)) {
                        case reactant:
                            rxn.getReactants().addAtomContainer(mol);
                            break;
                        case product:
                            rxn.getProducts().addAtomContainer(mol);
                            break;
                        case agent:
                            rxn.getAgents().addAtomContainer(mol);
                            break;
                    }
                }
            }
        }
    }
632677
public function addGrouping(array $grouping)
	{
		foreach ($grouping as $name => $value)
		{
			$this->groupBy($name, $value);
		}

		return $this;
	}
281852
public void setGroups(java.util.Collection<Group> groups) {
        if (groups == null) {
            this.groups = null;
            return;
        }

        this.groups = new java.util.ArrayList<Group>(groups);
    }
293601
private void doGroupCheck() {
        if (!hasTabs()) return;

        for (String groupName : getGroupNames()) {
            String tabName = getGroupedAttribtes(groupName).get(0).getTabName();
            for (PropertyBinding propBinding : getGroupedAttribtes(groupName)) {
                if (!tabName.equals(propBinding.getTabName())) {
                    throw new RuntimeException("FormItem " + propBinding.getJavaName() + " must be on the same tab with all members of its subgroup.");
                }
            }
        }
    }
310874
function addGroupToList(group, list) {
    if (!group) {
      return list;
    }

    if (group.length > 1) {
      list.push(group);
    } else {
      list = list.concat(group);
    }

    return list;
  }
238010
function _groupBy (identifiers, groupByFields) {
  /* don't modify the input array */
  groupByFields = groupByFields.slice(0)

  groupByFields.forEach(function (group) {
    var groupValues = identifiers
      .filter(function (identifier) {
        /* exclude constructors from grouping.. re-implement to work off a `null` group value */
        return identifier.kind !== 'constructor'
      })
      .map(function (i) { return i[group] })
      .reduce(unique, [])
    if (groupValues.length <= 1) groupByFields = groupByFields.reduce(without(group), [])
  })
  identifiers = _addGroup(identifiers, groupByFields)

  var inserts = []
  var prevGroup = []
  var level = 0
  identifiers.forEach(function (identifier, index) {
    if (!deepEqual(identifier._group, prevGroup)) {
      var common = commonSequence(identifier._group, prevGroup)
      level = common.length
      identifier._group.forEach(function (group, i) {
        if (group !== common[i] && group !== null) {
          inserts.push({
            index: index,
            _title: group,
            level: level++
          })
        }
      })
    }
    identifier.level = level
    prevGroup = identifier._group
    delete identifier._group
  })

  /* insert title items */
  inserts.reverse().forEach(function (insert) {
    identifiers.splice(insert.index, 0, { _title: insert._title, level: insert.level })
  })
  return identifiers
}
452693
private function formatByCharGrouping($value, $groupingLength)
    {
        if ('' === $value) {
            return '-';
        }

        return \ucfirst(Utf8::substr($value, 0, $groupingLength ?: null));
    }
1313335
@Override
   public void groupingValue(String collateName) {
      // collationName is ignored for now
      if (groupBy == null) {
         groupBy = new ArrayList<>(ARRAY_INITIAL_LENGTH);
      }
      groupBy.add(resolveAlias(propertyPath));
   }
1261744
void doGroupStart(String group, String name, Object args, String parent) {
    checkOpen();
    JsonObject message = createMessage(args)
        .putString("group", group)
        .putString("name", name)
        .putString("parent", parent)
        .putString("action", "startGroup");
    if (open && !paused) {
      if (log.isDebugEnabled()) {
        if (parent != null) {
          log.debug(String.format("%s - Group start: Group[name=%s, group=%s, parent=%s, args=%s]", this, name, group, parent, args));
        } else {
          log.debug(String.format("%s - Group start: Group[name=%s, group=%s, args=%s]", this, name, group, args));
        }
      }
      eventBus.send(inAddress, message);
    }
    checkFull();
  }
393940
private void markUngroupedEnclosedNodes(InstructionGroup group) {
        while_:
        while (true) {
            for (int i = getIndexOfFirstInsn(group), max = getIndexOfLastInsn(group); i < max; i++) {
                InstructionGraphNode node = method.getGraphNodes().get(i);
                if (node.getGroup() == null) {
                    markGroup(node, group);
                    sort(group);
                    continue while_;
                }
            }
            break;
        }
    }
715802
private void compactGroups() {
    for (int i = 0; i < groups.size(); i++) {
      List<Segment> group = groups.get(i);
      List<OffsetPredicate> groupPredicates = predicates.get(i);
      Segment segment = compactGroup(group, groupPredicates);
      mergeReleased(group, groupPredicates, segment);
      deleteGroup(group);
    }
  }
906171
private void doGroupEnd(final JsonObject message) {
    String groupID = message.getString("group");
    DefaultConnectionInputGroup group = groups.remove(groupID);
    if (group != null) {
      Object args = deserializer.deserialize(message);
      if (log.isDebugEnabled()) {
        log.debug(String.format("%s - Group ended: Group[group=%s, args=%s]", this, group.id(), args));
      }
      group.handleEnd(args);
    }
  }