Exemplo n.º 1
0
 protected <T extends AbstractNode> void sortEList(@NonNull EList<T> nodes) {
   List<T> sortedList = new ArrayList<T>(nodes);
   Collections.sort(sortedList, labelComparator);
   for (int i = 0; i < sortedList.size(); i++) {
     nodes.move(i, sortedList.get(i));
   }
 }
Exemplo n.º 2
0
  /*
   * Bugzilla: 133907
   */
  public void testMoveIntObject() throws Exception {
    EList<Object> originalList = new BasicEList<Object>();
    originalList.add("pos0");
    originalList.add("pos1");
    originalList.add(2);
    originalList.add("pos3");

    EList<Object> eList = new BasicEList<Object>(originalList);
    List<Object> list = new ArrayList<Object>(originalList);

    int target = 2;
    Object object = originalList.get(3);
    originalList.move(target, object);
    ECollections.move(eList, target, object);
    assertTrue(TestUtil.areEqual(originalList, eList));
    ECollections.move(list, target, object);
    assertTrue(TestUtil.areEqual(originalList, list));

    target = 2;
    object = originalList.get(0);
    originalList.move(target, object);
    ECollections.move(eList, target, object);
    assertTrue(TestUtil.areEqual(originalList, eList));
    ECollections.move(list, target, object);
    assertTrue(TestUtil.areEqual(originalList, list));

    target = 1;
    object = originalList.get(1);
    originalList.move(target, object);
    ECollections.move(eList, target, object);
    assertTrue(TestUtil.areEqual(originalList, eList));
    ECollections.move(list, target, object);
    assertTrue(TestUtil.areEqual(originalList, list));

    target = 0;
    object = originalList.get(3);
    originalList.move(target, object);
    ECollections.move(eList, target, object);
    assertTrue(TestUtil.areEqual(originalList, eList));
    ECollections.move(list, target, object);
    assertTrue(TestUtil.areEqual(originalList, list));
  }
Exemplo n.º 3
0
  /*
   * Bugzilla: 133907
   */
  public void testMoveIntInt() throws Exception {
    EList<Object> originalList = new BasicEList<Object>();
    originalList.add("pos0");
    originalList.add("pos1");
    originalList.add(2);
    originalList.add("pos3");

    EList<Object> eList = new BasicEList<Object>(originalList);
    List<Object> list = new ArrayList<Object>(originalList);

    int target = 2, source = 3;
    originalList.move(target, source);
    ECollections.move(eList, target, source);
    assertTrue(TestUtil.areEqual(originalList, eList));
    ECollections.move(list, target, source);
    assertTrue(TestUtil.areEqual(originalList, list));

    target = 2;
    source = 0;
    originalList.move(target, source);
    ECollections.move(eList, target, source);
    assertTrue(TestUtil.areEqual(originalList, eList));
    ECollections.move(list, target, source);
    assertTrue(TestUtil.areEqual(originalList, list));

    target = 1;
    source = 1;
    originalList.move(target, source);
    ECollections.move(eList, target, source);
    assertTrue(TestUtil.areEqual(originalList, eList));
    ECollections.move(list, target, source);
    assertTrue(TestUtil.areEqual(originalList, list));

    target = 0;
    source = 3;
    originalList.move(target, source);
    ECollections.move(eList, target, source);
    assertTrue(TestUtil.areEqual(originalList, eList));
    ECollections.move(list, target, source);
    assertTrue(TestUtil.areEqual(originalList, list));
  }
 /**
  * TODO does not work yet, because HiddenTokenSequencer always searches in one direction, but the
  * order of the elements has changed here.
  */
 @Test
 @Ignore
 public void testMoveElement() {
   try {
     StringConcatenation _builder = new StringConcatenation();
     _builder.append("entities");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("Foo \"Bar\"");
     _builder.newLine();
     _builder.newLine();
     _builder.append("\t");
     _builder.append("//comment between elements");
     _builder.newLine();
     _builder.append("\t");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("Baz \"Fizzle\"");
     _builder.newLine();
     _builder.append("end");
     _builder.newLine();
     final Model model = this._parseHelper.parse(_builder);
     DomainModel _domainModel = model.getDomainModel();
     EList<Entity> _entities = _domainModel.getEntities();
     final Entity head = IterableExtensions.<Entity>head(_entities);
     DomainModel _domainModel_1 = model.getDomainModel();
     EList<Entity> _entities_1 = _domainModel_1.getEntities();
     _entities_1.move(1, head);
     StringConcatenation _builder_1 = new StringConcatenation();
     _builder_1.append("entities");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("Baz \"Fizzle\"");
     _builder_1.newLine();
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("//comment between elements");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("Foo \"Bar\"");
     _builder_1.newLine();
     _builder_1.append("end");
     _builder_1.newLine();
     this.assertSerializesTo(model, _builder_1);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
Exemplo n.º 5
0
  /**
   * Tests that the MSLUtil::addObject() method does the correct thing when adding an object that is
   * already in the list. It formerly attempted to move the object, but moved the wrong one.
   */
  public void test_MSLUtil_addObject_113261() {
    EList list = new BasicEList();

    list.add("a"); // $NON-NLS-1$
    list.add("b"); // $NON-NLS-1$
    list.add("c"); // $NON-NLS-1$
    list.add("d"); // $NON-NLS-1$

    Object object = list.get(3);

    // on a copy of this list, do the correct change
    EList expected = new BasicEList(list);
    expected.move(0, 3);

    MSLUtil.addObject(list, object, 0);

    // check that MSLUtil made the correct change
    assertEquals(expected, list);
  }
 /** This method should be called with write Transaction. */
 protected void safelyChangeOrder() {
   EList<InteractionFragment> orderingFragments = getOrderingFragments();
   synchronized (orderingFragments) {
     computeNewIndexes();
     for (InteractionFragment fragment : new ArrayList<InteractionFragment>(orderingFragments)) {
       int oldPos = orderingFragments.indexOf(fragment);
       if (oldPos == -1) {
         continue;
       }
       Integer newPos = fragmentIndexes.get(fragment);
       if (newPos == null
           || oldPos == newPos.intValue()
           || newPos.intValue() < 0
           || newPos.intValue() >= orderingFragments.size()) {
         continue;
       }
       orderingFragments.move(newPos.intValue(), oldPos);
     }
   }
 }
Exemplo n.º 7
0
 public void repair() {
   final EObject eObjectOwner = objectMapping.get(owner.getTarget());
   final ModelObject<?> modelObjectOwner = ModelResolver.getInstance().getModelObject(owner);
   final Object listObject = modelObjectOwner.eGet(eReference);
   if (!(listObject instanceof List<?>)) {
     // no order maintained anyway
     return;
   }
   final EList<?> eList = (EList<?>) eObjectOwner.eGet(eReference);
   final List<?> list = (List<?>) listObject;
   int currentIndex = 0;
   for (Object objectElement : list) {
     final EObject eObjectElement = objectMapping.get(objectElement);
     final int newIndex = eList.indexOf(eObjectElement);
     if (newIndex != currentIndex) {
       eList.move(currentIndex, newIndex);
     }
     currentIndex++;
   }
 }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.eclipse.emf.emfstore.server.model.versioning.operations.AbstractOperation#apply(org.eclipse.emf.emfstore.common.model.Project)
   */
  public void apply(IdEObjectCollection project) {
    EObject modelElement = project.getModelElement(getModelElementId());
    if (modelElement == null) {
      return;
    }

    if (getNewIndex() < 0 || getOldIndex() < 0) {
      return;
    }

    EAttribute feature;
    try {
      feature = (EAttribute) getFeature(modelElement);
      @SuppressWarnings("unchecked")
      EList<Object> list = (EList<Object>) modelElement.eGet(feature);
      if (list.size() > getOldIndex() && list.size() > getNewIndex()) {
        list.move(getNewIndex(), getOldIndex());
      }

    } catch (UnkownFeatureException e) {
      // we ignore any non applicable o
    }
  }
Exemplo n.º 9
0
 public E move(int newPosition, int oldPosition) {
   copy.move(newPosition, oldPosition);
   return original.move(newPosition, oldPosition);
 }
Exemplo n.º 10
0
 public void move(int newPosition, E object) {
   original.move(newPosition, object);
   copy.move(newPosition, object);
 }