<commit_before>/*****************************************************************************
 *  Limpet - the Lightweight InforMation ProcEssing Toolkit
 *  http://limpet.info
 *
 *  (C) 2015-2016, Deep Blue C Technologies Ltd
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the Eclipse Public License v1.0
 *  (http://www.eclipse.org/legal/epl-v10.html)
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *****************************************************************************/
package info.limpet.rcp.data_provider.data;

import info.limpet.ICollection;
import info.limpet.ICommand;
import info.limpet.IStore.IStoreItem;
import info.limpet.data.store.InMemoryStore;
import info.limpet.data.store.InMemoryStore.StoreGroup;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

/**
 * make the Limpet data store suitable for displaying in a tree control
 * 
 * @author ian
 * 
 */
public class DataModel implements ITreeContentProvider
{
  public static final String DEPENDENTS = "Dependents";
  public static final String PRECEDENTS = "Precedents";

  private void addCollectionItems(final List<Object> res,
      final CollectionWrapper cw)
  {
    final IStoreItem item = cw.getCollection();

    if (item instanceof ICollection)
    {
      ICollection coll = (ICollection) item;
      final ICommand<?> prec = coll.getPrecedent();
      if (prec != null)
      {
        final NamedList dList = new NamedList(cw, PRECEDENTS);
        dList.add(new CommandWrapper(dList, prec));
        res.add(dList);
      }

      final List<ICommand<?>> dep = coll.getDependents();
      if (dep != null)
      {
        final NamedList dList = new NamedList(cw, DEPENDENTS);
        final Iterator<ICommand<?>> dIter = dep.iterator();
        while (dIter.hasNext())
        {
          final ICommand<?> thisI = dIter.next();
          dList.add(new CommandWrapper(dList, thisI));
        }

        // did we find any?
        if (dList.size() > 0)
        {
          res.add(dList);
        }
      }
    }
    else if (item instanceof StoreGroup)
    {
      StoreGroup group = (StoreGroup) item;
      final NamedList dList = new NamedList(cw, group.getName());
      final Iterator<IStoreItem> dIter = group.iterator();
      while (dIter.hasNext())
      {
        final IStoreItem thisI = dIter.next();
        if (thisI instanceof CommandWrapper)
        {
          dList.add(new CommandWrapper(dList, (ICommand<?>) thisI));

        }
        else if (thisI instanceof CollectionWrapper)
        {
          dList.add(new CollectionWrapper(dList, (ICollection) thisI));
        }
      }

      // did we find any?
      if (dList.size() > 0)
      {
        res.add(dList);
      }
    }
  }

  private void addCommandItems(final List<Object> res, final CommandWrapper cw)
  {
    final ICommand<?> coll = cw.getCommand();

    final List<? extends IStoreItem> inp = coll.getInputs();
    if (inp != null)
    {
      final NamedList dList = new NamedList(cw, "Inputs");
      final Iterator<? extends IStoreItem> dIter = inp.iterator();
      while (dIter.hasNext())
      {
        final IStoreItem thisI = dIter.next();
        if (thisI instanceof ICollection)
        {
          dList.add(new CollectionWrapper(dList, (ICollection) thisI));
        }
        else if (thisI instanceof StoreGroup)
        {
          dList.add(new GroupWrapper(dList, (StoreGroup) thisI));
        }

      }
      // did we find any?
      if (dList.size() > 0)
      {
        res.add(dList);
      }
    }

    final List<? extends IStoreItem> outp = coll.getOutputs();
    if (outp != null)
    {
      final NamedList dList = new NamedList(cw, "Outputs");
      final Iterator<? extends IStoreItem> dIter = outp.iterator();
      while (dIter.hasNext())
      {
        final IStoreItem thisI = dIter.next();
        if (thisI instanceof ICollection)
        {
          dList.add(new CollectionWrapper(dList, (ICollection) thisI));
        }
        else if (thisI instanceof StoreGroup)
        {
          dList.add(new GroupWrapper(dList, (StoreGroup) thisI));
        }
      }
      // did we find any?
      if (dList.size() > 0)
      {
        res.add(dList);
      }
    }
  }

  private void addGroupItems(final List<Object> res, final GroupWrapper cw)
  {
    final StoreGroup coll = cw.getGroup();

    // final NamedList dList = new NamedList(cw, coll.getName());
    final Iterator<IStoreItem> dIter = coll.iterator();
    while (dIter.hasNext())
    {
      final IStoreItem thisI = dIter.next();
      if (thisI instanceof ICollection)
      {
        res.add(new CollectionWrapper(cw, (ICollection) thisI));
      }
      else if (thisI instanceof StoreGroup)
      {
        res.add(new GroupWrapper(cw, (StoreGroup) thisI));
      }
    }
    // did we find any?
    // if (dList.size() > 0)
    // {
    // res.add(dList);
    // }
  }

  /**<commit_msg>remove unnecessary logic<commit_after>/*****************************************************************************
 *  Limpet - the Lightweight InforMation ProcEssing Toolkit
 *  http://limpet.info
 *
 *  (C) 2015-2016, Deep Blue C Technologies Ltd
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the Eclipse Public License v1.0
 *  (http://www.eclipse.org/legal/epl-v10.html)
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *****************************************************************************/
package info.limpet.rcp.data_provider.data;

import info.limpet.ICollection;
import info.limpet.ICommand;
import info.limpet.IStore.IStoreItem;
import info.limpet.data.store.InMemoryStore;
import info.limpet.data.store.InMemoryStore.StoreGroup;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

/**
 * make the Limpet data store suitable for displaying in a tree control
 * 
 * @author ian
 * 
 */
public class DataModel implements ITreeContentProvider
{
  public static final String DEPENDENTS = "Dependents";
  public static final String PRECEDENTS = "Precedents";

  private void addCollectionItems(final List<Object> res,
      final CollectionWrapper cw)
  {
    final ICollection item = cw.getCollection();

    final ICommand<?> prec = item.getPrecedent();
    if (prec != null)
    {
      final NamedList dList = new NamedList(cw, PRECEDENTS);
      dList.add(new CommandWrapper(dList, prec));
      res.add(dList);
    }

    final List<ICommand<?>> dep = item.getDependents();
    if (dep != null)
    {
      final NamedList dList = new NamedList(cw, DEPENDENTS);
      final Iterator<ICommand<?>> dIter = dep.iterator();
      while (dIter.hasNext())
      {
        final ICommand<?> thisI = dIter.next();
        dList.add(new CommandWrapper(dList, thisI));
      }

      // did we find any?
      if (dList.size() > 0)
      {
        res.add(dList);
      }
    }
  }

  private void addCommandItems(final List<Object> res, final CommandWrapper cw)
  {
    final ICommand<?> coll = cw.getCommand();

    final List<? extends IStoreItem> inp = coll.getInputs();
    if (inp != null)
    {
      final NamedList dList = new NamedList(cw, "Inputs");
      final Iterator<? extends IStoreItem> dIter = inp.iterator();
      while (dIter.hasNext())
      {
        final IStoreItem thisI = dIter.next();
        if (thisI instanceof ICollection)
        {
          dList.add(new CollectionWrapper(dList, (ICollection) thisI));
        }
        else if (thisI instanceof StoreGroup)
        {
          dList.add(new GroupWrapper(dList, (StoreGroup) thisI));
        }

      }
      // did we find any?
      if (dList.size() > 0)
      {
        res.add(dList);
      }
    }

    final List<? extends IStoreItem> outp = coll.getOutputs();
    if (outp != null)
    {
      final NamedList dList = new NamedList(cw, "Outputs");
      final Iterator<? extends IStoreItem> dIter = outp.iterator();
      while (dIter.hasNext())
      {
        final IStoreItem thisI = dIter.next();
        if (thisI instanceof ICollection)
        {
          dList.add(new CollectionWrapper(dList, (ICollection) thisI));
        }
        else if (thisI instanceof StoreGroup)
        {
          dList.add(new GroupWrapper(dList, (StoreGroup) thisI));
        }
      }
      // did we find any?
      if (dList.size() > 0)
      {
        res.add(dList);
      }
    }
  }

  private void addGroupItems(final List<Object> res, final GroupWrapper cw)
  {
    final StoreGroup coll = cw.getGroup();

    // final NamedList dList = new NamedList(cw, coll.getName());
    final Iterator<IStoreItem> dIter = coll.iterator();
    while (dIter.hasNext())
    {
      final IStoreItem thisI = dIter.next();
      if (thisI instanceof ICollection)
      {
        res.add(new CollectionWrapper(cw, (ICollection) thisI));
      }
      else if (thisI instanceof StoreGroup)
      {
        res.add(new GroupWrapper(cw, (StoreGroup) thisI));
      }
    }
  }

  /**
{'fraction_non_alphanumeric': 0.14216512215669755, 'fraction_numerical': 0.003369839932603201, 'mean_word_length': 2.611026615969582, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '139791', 'n_tokens_mistral': 2949, 'n_tokens_neox': 2896, 'n_words': 754}