public void move()

in impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java [458:779]


  public void move(int toIndex, int fromIndex)
  {
    for (Iterator iterator = delegateProperties.iterator(); iterator.hasNext() ;)
    {
      Property property = (Property)iterator.next();
      if (dataObject.isSet(property))
        if (isSequenceProperty(property))
        {
          Sequence sequence = (Sequence)dataObject.get(property);
          int size = sequence.size();
          if (toIndex < size)
          {
            if (fromIndex < size)
            {
              sequence.move(toIndex, fromIndex);
              return;
            }
            while (iterator.hasNext())
            {
              property = (Property)iterator.next();
              if (!dataObject.isSet(property))
                continue;
              fromIndex -= size;
              if (isSequenceProperty(property))
              {
                Sequence fromSequence = (Sequence)dataObject.get(property);
                size = fromSequence.size();
                if (fromIndex >= size)
                  continue;
                move(fromSequence, fromIndex, sequence, toIndex);
                return;
              }
              if (property.isMany())
              {
                List list = dataObject.getList(property);
                size = list.size();
                if (fromIndex >= size)
                  continue;
                sequence.add(toIndex, property, list.remove(fromIndex)); // removes containment
                return;
              }
              if (fromIndex == 0)
              {
                sequence.add(toIndex, property, dataObject.get(property)); // removes containment
                dataObject.unset(property);
                return;
              }
              size = 1;
            } // iterator.hasNext()
            break;
          } // toIndex < size
          if (fromIndex < size)
          {
            while (iterator.hasNext())
            {
              property = (Property)iterator.next();
              if (!dataObject.isSet(property))
                continue;
              toIndex -= size;
              if (isSequenceProperty(property))
              {
                Sequence toSequence = (Sequence)dataObject.get(property);
                size = toSequence.size();
                if (toIndex >= size)
                  continue;
                if (++toIndex == size)
                  toSequence.add(sequence.getProperty(fromIndex), remove(sequence, fromIndex)); // Java pushes stack from left to right
                    // removes containment
                else
                  move(sequence, fromIndex, toSequence, toIndex);
                return;
              }
              if (property.isMany())
              {
                List list = dataObject.getList(property);
                size = list.size();
                if (toIndex >= size)
                  continue;
                if (sequence.getProperty(fromIndex) != property)
                  throw new IllegalArgumentException();
                add(remove(sequence, fromIndex), list, toIndex, size);
                return;
              }
              if (toIndex == 0)
              {
                while (iterator.hasNext())
                {
                  Property p = sequence.getProperty(fromIndex);
                  property = (Property)iterator.next();
                  EStructuralFeature feature = (EStructuralFeature)property;
                  if (dataObject.isSet(property))
                  {
                    if (FeatureMapUtil.isFeatureMap(feature))
                    {
                      /*if (!validate(feature, p))
                        throw new IllegalArgumentException(); */
                      move(sequence, fromIndex, (Sequence)dataObject.get(property), 0, p);
                      return;
                    }
                    if (property != p || !property.isMany())
                      throw new IllegalArgumentException();
                    insert(property, remove(sequence, fromIndex)); // removes containment
                    return;
                  }
                  if (FeatureMapUtil.isFeatureMap(feature))
                  {
                    if (validate(feature, p))
                    {
                      append(property, p, remove(sequence, fromIndex)); // removes containment
                      return;
                    }
                  }
                  else if (property == p)
                  {
                    set(property, remove(sequence, fromIndex));
                    return;
                  }
                } // iterator.hasNext()
                break;
              }
              size = 1;
            } // iterator.hasNext()
            break;
          } // fromIndex < size
          toIndex -= size;
          fromIndex -= size;
        } // sequence(property)
        else if (property.isMany())
        {
          List list = dataObject.getList(property);
          int size = list.size();
          if (toIndex < size)
          {
            if (fromIndex < size)
            {
              ((EList)list).move(toIndex, fromIndex);
              return;
            }
            while (iterator.hasNext())
            {
              Property p = (Property)iterator.next();
              if (!dataObject.isSet(p))
                continue;
              fromIndex -= size;
              if (isSequenceProperty(p))
              {
                Sequence fromSequence = (Sequence)dataObject.get(p);
                size = fromSequence.size();
                if (fromIndex >= size)
                  continue;
                if (fromSequence.getProperty(fromIndex) != property)
                  throw new IllegalArgumentException();
                list.add(toIndex, remove(fromSequence, fromIndex)); // removes containment
                return;
              }
              if (p.isMany())
              {
                List l = dataObject.getList(p);
                size = l.size();
                if (fromIndex >= size)
                  continue;
                /*if (p != property)
                  throw new IllegalArgumentException(); */
                list.add(toIndex, l.remove(fromIndex)); // removes containment
                return;
              }
              if (fromIndex == 0)
              {
                /*if (p != property)
                throw new IllegalArgumentException(); */
                list.add(toIndex, dataObject.get(p)); // removes containment
                dataObject.unset(p);
                return;
              }
              size = 1;
            } // iterator.hasNext()
            break;
          } // toIndex < size
          if (fromIndex < size)
          {
            while (iterator.hasNext())
            {
              Property p = (Property)iterator.next();
              if (!dataObject.isSet(p))
                continue;
              toIndex -= size;
              if (isSequenceProperty(p))
              {
                Sequence toSequence = (Sequence)dataObject.get(p);
                size = toSequence.size();
                if (toIndex >= size)
                  continue;
                add(property, list.remove(fromIndex), toSequence, toIndex, size);
                return;
              }
              if (p.isMany())
              {
                List l = dataObject.getList(p);
                size = l.size();
                if (toIndex >= size)
                  continue;
                /*if (property != p)
                  throw new IllegalArgumentException(); */
                add(list.remove(fromIndex), l, toIndex, size);
                return;
              }
              if (toIndex == 0)
              {
                while (iterator.hasNext())
                {
                  p = (Property)iterator.next();
                  EStructuralFeature feature = (EStructuralFeature)p;
                  if (dataObject.isSet(p))
                  {
                    if (FeatureMapUtil.isFeatureMap(feature))
                    {
                      /*if (!validate(feature, property))
                        throw new IllegalArgumentException(); */
                      insert(p, property, list.remove(fromIndex));
                      return;
                    }
                    if (/*p != property || */!p.isMany())
                      throw new IllegalArgumentException();
                    insert(p, list.remove(fromIndex)); // removes containment
                    return;
                  }
                  if (FeatureMapUtil.isFeatureMap(feature))
                  {
                    if (!validate(feature, property))
                      continue;
                    append(p, property, list.remove(fromIndex)); // removes containment
                    return;
                  }
                  else if (p == property)
                  {
                    set(p, list.remove(fromIndex));
                    return;
                  }
                } // iterator.hasNext()
                break;
              } // toIndex == 0
              size = 1;
            } // iterator.hasNext()
            break;
          } // fromIndex < size
          toIndex -= size;
          fromIndex -= size;
        } // property.isMany()
        else if (toIndex == 0)
          throw new IllegalArgumentException();
        else if (fromIndex == 0)
        {
          for (int size = 1; iterator.hasNext() ;)
          {
            Property p = (Property)iterator.next();
            if (!dataObject.isSet(p))
              continue;
            toIndex -= size;
            if (isSequenceProperty(p))
            {
              Sequence toSequence = (Sequence)dataObject.get(p);
              size = toSequence.size();
              if (toIndex >= size)
                continue;
              add(property, dataObject.get(property), toSequence, toIndex, size);
              dataObject.unset(property);
              return;
            }
            if (p.isMany())
            {
              List l = dataObject.getList(p);
              size = l.size();
              if (toIndex >= size)
                continue;
              /*if (property != p)
                throw new IllegalArgumentException(); */
              add(dataObject.get(property), l, toIndex, size);
              dataObject.unset(property);
              return;
            }
            if (toIndex == 0)
            {
              while (iterator.hasNext())
              {
                p = (Property)iterator.next();
                EStructuralFeature feature = (EStructuralFeature)p;
                if (dataObject.isSet(p))
                  if (FeatureMapUtil.isFeatureMap(feature))
                    /*if (!validate(feature, property))
                      throw new IllegalArgumentException(); */
                    insert(p, property, dataObject.get(property));
                  else if (/*p == property && */p.isMany())
                    insert(p, dataObject.get(property)); // removes containment
                  else
                    throw new IllegalArgumentException();
                else if (FeatureMapUtil.isFeatureMap(feature))
                {
                  if (!validate(feature, property))
                    continue;
                  append(p, property, dataObject.get(property)); // removes containment
                }
                else if (p == property)
                  set(p, dataObject.get(property));
                else
                  continue;
                dataObject.unset(property);
                return;
              } // iterator.hasNext()
              break;
            } // toIndex == 0
            size = 1;
          } // iterator.hasNext()
          break;
        } // fromIndex == 0
        else
        {
          --toIndex;
          --fromIndex;
        }
    }
    throw new IndexOutOfBoundsException();
  }