@Override public List<IGroup> getGroupList() { listChildren(); ArrayList<IGroup> list = new ArrayList<IGroup>(); for (IContainer container : mChildren) { if (container.getModelType() == ModelType.Group) { list.add((IGroup) container); } } return list; }
@Override public List<IDataItem> getDataItemList() { listChildren(); ArrayList<IDataItem> list = new ArrayList<IDataItem>(); for (IContainer container : mChildren) { if (container.getModelType() == ModelType.DataItem) { list.add((IDataItem) container); } } return list; }
@Override public IDataItem findDataItemWithAttribute(IKey key, String name, String attribute) throws NoResultException { List<IContainer> list = findAllContainers(key); IDataItem result = null; for (IContainer item : list) { if (item.getModelType() == ModelType.DataItem && item.hasAttribute(name, attribute)) { result = (IDataItem) item; break; } } return result; }
@Override public List<IContainer> findAllContainerByPath(String path) throws NoResultException { List<IContainer> list = new ArrayList<IContainer>(); List<IContainer> tmp = null; String tmpName; // Store in a map all different containers from all m_groups Map<String, ArrayList<IContainer>> items = new HashMap<String, ArrayList<IContainer>>(); for (IGroup group : mGroups) { try { tmp = group.findAllContainerByPath(path); for (IContainer item : tmp) { tmpName = item.getShortName(); if (items.containsKey(tmpName)) { items.get(tmpName).add(item); } else { ArrayList<IContainer> tmpList = new ArrayList<IContainer>(); tmpList.add(item); items.put(tmpName, tmpList); } } } catch (NoResultException e) { // Nothing to do } } // Construct that were found for (Entry<String, ArrayList<IContainer>> entry : items.entrySet()) { tmp = entry.getValue(); // If a Group list then construct a new Group folder if (tmp.get(0).getModelType() == ModelType.Group) { list.add(new NxsGroup(tmp.toArray(new IGroup[tmp.size()]), this, mDataset)); } // If a IDataItem list then construct a new compound NxsDataItem else { ArrayList<NexusDataItem> dataItems = new ArrayList<NexusDataItem>(); for (IContainer item : tmp) { if (item.getModelType() == ModelType.DataItem) { dataItems.add((NexusDataItem) item); } } NexusDataItem[] array = new NexusDataItem[dataItems.size()]; dataItems.toArray(array); list.add(new NxsDataItem(array, this, mDataset)); } } return list; }
private List<IContainer> listChildrenMultiGroup() { if (!mIsChildUpdate) { List<IContainer> tmp = null; mChildren = new ArrayList<IContainer>(); String tmpName; // Store in a map all different containers from all m_groups Map<String, ArrayList<IContainer>> items = new HashMap<String, ArrayList<IContainer>>(); for (IGroup group : mGroups) { tmp = new ArrayList<IContainer>(); tmp.addAll(group.getDataItemList()); tmp.addAll(group.getGroupList()); for (IContainer item : tmp) { tmpName = item.getShortName(); if (items.containsKey(tmpName)) { items.get(tmpName).add(item); } else { ArrayList<IContainer> tmpList = new ArrayList<IContainer>(); tmpList.add(item); items.put(tmpName, tmpList); } } } // Construct what were found for (Entry<String, ArrayList<IContainer>> entry : items.entrySet()) { tmp = entry.getValue(); // If a Group list then construct a new Group folder if (tmp.get(0).getModelType() == ModelType.Group) { mChildren.add(new NxsGroup(tmp.toArray(new IGroup[tmp.size()]), this, mDataset)); } // If a IDataItem list then construct a new compound NxsDataItem else { ArrayList<NexusDataItem> nxsDataItems = new ArrayList<NexusDataItem>(); for (IContainer item : tmp) { if (item.getModelType() == ModelType.DataItem) { nxsDataItems.add((NexusDataItem) item); } } NexusDataItem[] array = new NexusDataItem[nxsDataItems.size()]; nxsDataItems.toArray(array); mChildren.add(new NxsDataItem(array, this, mDataset)); } } mIsChildUpdate = true; } return mChildren; }
public NxsGroup(IGroup parent, PathNexus path, NxsDataset dataset) { try { List<IContainer> list = dataset.getRootGroup().findAllContainerByPath(path.getValue()); List<IGroup> groups = new ArrayList<IGroup>(); for (IContainer container : list) { if (container.getModelType() == ModelType.Group) { groups.add((IGroup) container); } } IGroup[] array = new IGroup[groups.size()]; mGroups = groups.toArray(array); } catch (NoResultException e) { } mParent = parent; mDataset = dataset; mChildren = null; mIsChildUpdate = false; }
@Override public IGroup findGroup(IKey key) { IGroup item = null; List<IContainer> list = new ArrayList<IContainer>(); try { list = findAllOccurrences(key); } catch (NoResultException e) { } for (IContainer object : list) { if (object.getModelType().equals(ModelType.Group)) { item = (IGroup) object; break; } } return item; }
@Override public IGroup findGroupWithAttribute(IKey key, String name, String value) { List<IContainer> list; try { list = findAllContainers(key); } catch (NoResultException e) { list = new ArrayList<IContainer>(); } IGroup result = null; for (IContainer item : list) { if (item.getModelType() == ModelType.Group && item.hasAttribute(name, value)) { result = (IGroup) item; break; } } return result; }