示例#1
0
  protected void assertSetEList(List<?> prototypeList) {
    EList<Object> eList = new BasicEList<Object>();
    ECollections.setEList(eList, prototypeList);
    assertTrue("Empty list test", TestUtil.areEqual(prototypeList, eList));

    eList = new BasicEList<Object>();
    eList.add(0, "String");
    eList.add(Boolean.FALSE);
    ECollections.setEList(eList, prototypeList);
    assertTrue("Smaller list test", TestUtil.areEqual(prototypeList, eList));

    eList = (EList<Object>) populateList(new BasicEList<Object>());
    ECollections.setEList(eList, prototypeList);
    assertTrue("Same list test", TestUtil.areEqual(prototypeList, eList));

    eList.remove(2);
    eList.add(3, this);
    ECollections.setEList(eList, prototypeList);
    assertTrue("Equal size list test", TestUtil.areEqual(prototypeList, eList));

    eList.add(0, "String");
    eList.add(2, Boolean.FALSE);
    eList.add(Boolean.FALSE);
    eList.add(this);
    ECollections.setEList(eList, prototypeList);
    assertTrue("Bigger list test", TestUtil.areEqual(prototypeList, eList));
  }
示例#2
0
  public void testSortEList() {
    Comparator<String> comparator =
        new Comparator<String>() {
          public int compare(String c1, String c2) {
            return -1 * c1.compareTo(c2);
          }

          @Override
          public boolean equals(Object obj) {
            return obj == this;
          }
        };

    List<String> initialList = new ArrayList<String>();
    initialList.add("k");
    initialList.add("a");
    initialList.add("f");
    initialList.add("b");
    initialList.add("z");
    initialList.add("a");
    initialList.add("b");
    List<String> sortedList = new ArrayList<String>(initialList);
    Collections.sort(sortedList);

    EList<String> eList = new BasicEList<String>(initialList);
    assertTrue(TestUtil.areEqual(initialList, eList));
    ECollections.sort(eList);
    assertTrue(TestUtil.areEqual(sortedList, eList));

    sortedList = new ArrayList<String>(initialList);
    Collections.sort(sortedList, comparator);

    eList = new BasicEList<String>(initialList);
    assertTrue(TestUtil.areEqual(initialList, eList));
    ECollections.sort(eList, comparator);
    assertTrue(TestUtil.areEqual(sortedList, eList));

    initialList = new ArrayList<String>();
    initialList.add("k");
    initialList.add("f");
    initialList.add("b");
    initialList.add("z");
    initialList.add("a");
    sortedList = new ArrayList<String>(initialList);
    Collections.sort(sortedList);

    eList = new UniqueEList<String>(initialList);
    assertTrue(TestUtil.areEqual(initialList, eList));
    ECollections.sort(eList);
    assertTrue(TestUtil.areEqual(sortedList, eList));

    sortedList = new ArrayList<String>(initialList);
    Collections.sort(sortedList, comparator);

    eList = new BasicEList<String>(initialList);
    assertTrue(TestUtil.areEqual(initialList, eList));
    ECollections.sort(eList, comparator);
    assertTrue(TestUtil.areEqual(sortedList, eList));
  }
 @Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   Command command = event.getCommand();
   ISelection selection = HandlerUtil.getCurrentSelection(event);
   EList<EPlanElement> elements = getSelectedTemporalElements(selection);
   boolean isChecked = getCommandState(command);
   IUndoContext undoContext = getUndoContext();
   CompositeOperation op = new CompositeOperation(getEarliestOrLatestName());
   if (isChecked) {
     for (EPlanElement element : elements) {
       ConstraintsMember member = element.getMember(ConstraintsMember.class, true);
       Set<PeriodicTemporalConstraint> constraints = getRelevantConstraints(member);
       for (PeriodicTemporalConstraint constraint : constraints) {
         op.add(new DeleteTemporalBoundOperation(constraint));
       }
     }
   } else {
     Object data = showDialog();
     if (data instanceof Amount) {
       Amount<Duration> offset = (Amount<Duration>) data;
       if (!elements.isEmpty()) {
         ECollections.sort(elements, TemporalChainUtils.CHAIN_ORDER);
         for (EPlanElement planElement : elements) {
           op.add(createPeriodicTemporalConstraintOperation(planElement, offset, undoContext));
         }
       }
     }
   }
   CommonUtils.execute(op, undoContext);
   setCommandState(command, !isChecked);
   return null;
 }
示例#4
0
  @Override
  public EList<Office> getOffices() {

    List<Office> prototypeList = Activator.getDefault().getOffices();
    EList<Office> eList = new BasicEList<Office>(prototypeList.size());
    ECollections.setEList(eList, prototypeList);

    return eList;
  }
 @Override
 public EList<MindRootSrc> getAllsrc() {
   if (_allsrc == null) {
     _allsrc =
         new EObjectEList<MindRootSrc>(
             MindRootSrc.class, this, MindidePackage.MIND_PROJECT__ALLSRC);
     computeAllSrc(_allsrc);
   }
   return ECollections.unmodifiableEList(_allsrc);
 }
  @Override
  public void reorderChilds(Iterable<CreatedOutput> outDesc) {
    final Multiset<TreeItemMapping> subMappings = LinkedHashMultiset.create();
    final Map<EObject, CreatedOutput> outputToItem = Maps.newHashMap();
    for (CreatedOutput createdOutput : outDesc) {
      EObject createdElement = createdOutput.getCreatedElement();
      outputToItem.put(createdElement, createdOutput);
      if (createdElement instanceof DTreeItem) {
        DTreeItem createdDTreeItem = (DTreeItem) createdElement;
        TreeItemMapping actualMapping = createdDTreeItem.getActualMapping();
        subMappings.add(actualMapping);
      }
    }

    // Counts subMappings to correctly sort tree items regarding mapping
    // order (items have been created regarding the semantic candidates
    // order)
    int startIndex = 0;
    final Map<TreeItemMapping, Integer> startIndexes = Maps.newHashMap();
    for (TreeItemMapping itemMapping : subMappings) {
      startIndexes.put(itemMapping, startIndex);
      startIndex += subMappings.count(itemMapping);
    }

    // Pre-compute the new indices
    final Map<DTreeItem, Integer> newIndices = Maps.newHashMap();
    for (DTreeItem treeItem : container.getOwnedTreeItems()) {
      // init with element count : elements with unknown mapping
      // will be placed at the end.
      int index = outputToItem.size();
      TreeItemMapping itemMapping = treeItem.getActualMapping();
      if (itemMapping != null && startIndexes.containsKey(itemMapping)) {
        index = startIndexes.get(itemMapping);
      }

      CreatedOutput createdOutput = outputToItem.get(treeItem);
      if (createdOutput != null) {
        index = index + createdOutput.getNewIndex();
      } else {
        index = -1;
      }

      newIndices.put(treeItem, index);
    }

    ECollections.sort(
        container.getOwnedTreeItems(),
        new Comparator<DTreeItem>() {
          @Override
          public int compare(DTreeItem o1, DTreeItem o2) {
            return newIndices.get(o1).compareTo(newIndices.get(o2));
          }
        });
  }
示例#7
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));
  }
示例#8
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));
  }
示例#9
0
  @Override
  public EList<Office> loadOffices() {

    List<FCICredentials> creds = new ArrayList<FCICredentials>();

    // Get the preference store
    IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
    int accountsnum = preferenceStore.getInt("AccountNums");

    for (int i = 0; i < accountsnum; i++) {

      FCICredentials cred =
          FederationOffice.fcielements.FcielementsFactory.eINSTANCE.createFCICredentials();
      EMap<String, String> opts = cred.getCredoptions();

      opts.put(SFAUtils.REGISTRY_URL, preferenceStore.getString("REGISTRYURL_" + i));
      opts.put(SFAUtils.AM_URL, preferenceStore.getString("AGGREGATEURL_" + i));
      opts.put(SFAUtils.SM_URL, preferenceStore.getString("SLICEMGRURL_" + i));
      opts.put(SFAUtils.KEYSTORE_FILEPATH, preferenceStore.getString("KEYSTORE_" + i));
      opts.put(SFAUtils.KEYSTORE_PASSWORD, preferenceStore.getString("KEYSTOREPASSWORD_" + i));
      opts.put(SFAUtils.TRUSTSTORE_FILEPATH, preferenceStore.getString("TRUSTSTORE_" + i));
      opts.put(SFAUtils.TRUSTSTORE_PASSWORD, preferenceStore.getString("TRUSTSTOREPASSWORD_" + i));
      opts.put(SFAUtils.AUTHORITY, preferenceStore.getString("AUTHORITY_" + i));
      opts.put(SFAUtils.USERNAME, preferenceStore.getString("USERNAME_" + i));
      opts.put(
          SFAUtils.SELF_CERTIFICATE_FILEPATH,
          preferenceStore.getString("CERTIFICATEFILENAME_" + i));
      opts.put(SFAUtils.SFA_VERSION, preferenceStore.getString("SFAVERSION_" + i));
      opts.put(SFAUtils.SFA_TYPE, preferenceStore.getString("SFATYPE_" + i));
      opts.put(SFAUtils.ENABLED_ACCOUND, preferenceStore.getString("ENABLEDACCOUNT_" + i));
      opts.put(SFAUtils.CACHE_MODEL, preferenceStore.getString("CACHEMODEL_" + i));

      if (preferenceStore.getBoolean(
          "ENABLEDACCOUNT_" + i)) // only if the account is enabled then load it
      creds.add(cred);
    }

    List<Office> prototypeList = Activator.getDefault().loadSFAOfficesDescriptions(creds);
    EList<Office> eList = new BasicEList<Office>(prototypeList.size());
    ECollections.setEList(eList, prototypeList);

    return eList;
  }
    @Override
    protected Iterator<? extends Widget> getComponentChildren(Master master) {
      Overrides overrides = master.getOverrides();
      if (overrides != null) {
        List<Widget> children = new BasicEList<Widget>();

        if (overrides.eIsSet(OverridesPackage.Literals.OVERRIDES__WIDGETS)) {
          EList<WidgetOverrides> widgets = overrides.getWidgets();
          for (int j = 0, jSz = widgets.size(); j < jSz; j++) {
            WidgetContainerOverrides widgetOverrides = widgets.get(j);
            collectInsertedWidgets(widgetOverrides, children);
          }
        }
        collectInsertedWidgets(overrides, children);

        if (!children.isEmpty()) return children.iterator();
      }

      return ECollections.<Widget>emptyEList().iterator();
    }
  @Test
  public void testCreateLabel() throws NoLabelFoundException {
    /* setup */
    final VControl control1 = mock(VControl.class);
    final VFeaturePathDomainModelReference dmr1 = mock(VFeaturePathDomainModelReference.class);
    when(control1.getDomainModelReference()).thenReturn(dmr1);

    final VControl control2 = mock(VControl.class);
    final VFeaturePathDomainModelReference dmr2 = mock(VFeaturePathDomainModelReference.class);
    when(control2.getDomainModelReference()).thenReturn(dmr2);

    when(compoundControl.getControls()).thenReturn(ECollections.asEList(control1, control2));

    final EObject domainModel = mock(EObject.class);
    when(viewModelContext.getDomainModel()).thenReturn(domainModel);

    when(emfFormsLabelProvider.getDisplayName(dmr1, domainModel))
        .thenReturn(Observables.constantObservableValue(LABEL1, String.class));

    when(emfFormsLabelProvider.getDisplayName(dmr2, domainModel))
        .thenReturn(Observables.constantObservableValue(LABEL2, String.class));

    final CompoundControlSWTRenderer renderer = createRenderer();

    /* act */
    final Control label = renderer.createLabel(shell);

    /* assert */
    assertTrue(Composite.class.isInstance(label));
    final Composite labelComposite = Composite.class.cast(label);
    assertEquals(3, labelComposite.getChildren().length);
    for (final Control control : labelComposite.getChildren()) {
      assertTrue(Label.class.isInstance(control));
    }
    assertEquals(LABEL1, Label.class.cast(labelComposite.getChildren()[0]).getText());
    assertEquals("/", Label.class.cast(labelComposite.getChildren()[1]).getText()); // $NON-NLS-1$
    assertEquals(LABEL2, Label.class.cast(labelComposite.getChildren()[2]).getText());
  }
示例#12
0
  protected void assertIndexOf(List<?> list) {
    assertEquals(0, ECollections.indexOf(list, null, 0));
    assertEquals(4, ECollections.indexOf(list, null, 1));
    assertEquals(4, ECollections.indexOf(list, null, 4));

    assertEquals(1, ECollections.indexOf(list, Boolean.FALSE, 1));
    assertEquals(8, ECollections.indexOf(list, Boolean.FALSE, 2));
    assertEquals(-1, ECollections.indexOf(list, Boolean.FALSE, 9));
    assertEquals(1, ECollections.indexOf(list, Boolean.FALSE, -2));

    assertEquals(2, ECollections.indexOf(list, 1, 0));
    assertEquals(2, ECollections.indexOf(list, 1, 2));
    assertEquals(6, ECollections.indexOf(list, 1, 3));

    assertEquals(5, ECollections.indexOf(list, "String", 3));

    assertEquals(-1, ECollections.indexOf(list, null, 1000));
    assertEquals(-1, ECollections.indexOf(list, "String", 1000));
  }
示例#13
0
  public WPSCapabilitiesType run(GetCapabilitiesType request) throws WPSException {
    // do the version negotiation dance
    List<String> provided = Collections.singletonList("1.0.0");
    List<String> accepted = null;
    if (request.getAcceptVersions() != null) accepted = request.getAcceptVersions().getVersion();
    String version = RequestUtils.getVersionOws11(provided, accepted);

    if (!"1.0.0".equals(version)) {
      throw new WPSException("Could not understand version:" + version);
    }

    // TODO: add update sequence negotiation

    // encode the response
    Wps10Factory wpsf = Wps10Factory.eINSTANCE;
    Ows11Factory owsf = Ows11Factory.eINSTANCE;

    WPSCapabilitiesType caps = wpsf.createWPSCapabilitiesType();
    caps.setVersion("1.0.0");

    // TODO: make configurable
    caps.setLang("en");

    // ServiceIdentification
    ServiceIdentificationType si = owsf.createServiceIdentificationType();
    caps.setServiceIdentification(si);

    si.getTitle().add(Ows11Util.languageString(wps.getTitle()));
    si.getAbstract().add(Ows11Util.languageString(wps.getAbstract()));

    KeywordsType kw = Ows11Util.keywords(wps.keywordValues());
    ;
    if (kw != null) {
      si.getKeywords().add(kw);
    }

    si.setServiceType(Ows11Util.code("WPS"));
    si.getServiceTypeVersion().add("1.0.0");
    si.setFees(wps.getFees());

    if (wps.getAccessConstraints() != null) {
      si.getAccessConstraints().add(wps.getAccessConstraints());
    }

    // ServiceProvider
    ServiceProviderType sp = owsf.createServiceProviderType();
    caps.setServiceProvider(sp);

    // TODO: set provder name from context
    GeoServerInfo geoServer = wps.getGeoServer().getGlobal();
    if (geoServer.getContact().getContactOrganization() != null) {
      sp.setProviderName(geoServer.getContact().getContactOrganization());
    } else {
      sp.setProviderName("GeoServer");
    }

    sp.setProviderSite(owsf.createOnlineResourceType());
    sp.getProviderSite().setHref(geoServer.getOnlineResource());
    sp.setServiceContact(responsibleParty(geoServer, owsf));

    // OperationsMetadata
    OperationsMetadataType om = owsf.createOperationsMetadataType();
    caps.setOperationsMetadata(om);

    OperationType gco = owsf.createOperationType();
    gco.setName("GetCapabilities");
    gco.getDCP().add(Ows11Util.dcp("wps", request));
    om.getOperation().add(gco);

    OperationType dpo = owsf.createOperationType();
    dpo.setName("DescribeProcess");
    dpo.getDCP().add(Ows11Util.dcp("wps", request));
    om.getOperation().add(dpo);

    OperationType eo = owsf.createOperationType();
    eo.setName("Execute");
    eo.getDCP().add(Ows11Util.dcp("wps", request));
    om.getOperation().add(eo);

    ProcessOfferingsType po = wpsf.createProcessOfferingsType();
    caps.setProcessOfferings(po);

    // gather the process list
    for (ProcessFactory pf : Processors.getProcessFactories()) {
      for (Name name : pf.getNames()) {
        if (!getProcessBlacklist().contains(name)) {
          ProcessBriefType p = wpsf.createProcessBriefType();
          p.setProcessVersion(pf.getVersion(name));
          po.getProcess().add(p);

          p.setIdentifier(Ows11Util.code(name));
          p.setTitle(Ows11Util.languageString(pf.getTitle(name)));
          p.setAbstract(Ows11Util.languageString(pf.getDescription(name)));
        }
      }
    }
    // sort it
    ECollections.sort(
        po.getProcess(),
        new Comparator() {

          public int compare(Object o1, Object o2) {
            ProcessBriefType pb1 = (ProcessBriefType) o1;
            ProcessBriefType pb2 = (ProcessBriefType) o2;

            final String id1 = pb1.getIdentifier().getValue();
            final String id2 = pb2.getIdentifier().getValue();
            return id1.compareTo(id2);
          }
        });

    LanguagesType1 languages = wpsf.createLanguagesType1();
    caps.setLanguages(languages);

    DefaultType2 defaultLanguage = wpsf.createDefaultType2();
    languages.setDefault(defaultLanguage);
    defaultLanguage.setLanguage("en-US");

    LanguagesType supportedLanguages = wpsf.createLanguagesType();
    languages.setSupported(supportedLanguages);
    supportedLanguages.getLanguage().add("en-US");

    return caps;
    // Version detection and alternative invocation if being implemented.
  }
示例#14
0
  /**
   *
   * <!-- begin-user-doc -->
   * Return all of the Node Labels in the graph that have a particular type URI.
   * <!-- end-user-doc -->
   *
   * @generated NOT
   */
  public EList<NodeLabel> getNodeLabelsByTypeURI(URI typeURI) {
    // We could perform this function in a number of ways. We could, for
    // instance, create a Map between the type URI's and the instances,
    // however if we do that then we do two things: 1) make management of
    // the collection of instances more complicated (we have to add them to
    // two maps), and, 2) we "bloat" the serialization as we now basically
    // double the size of the serialized collection(s).
    // Given that this method is called infrequently it's probably better to
    // just do a "dumb" sequential scan of the instances and match them.
    // We can always change out minds later.

    final EList<NodeLabel> retValue = new BasicEList<NodeLabel>();

    for (final Iterator<NodeLabel> nodeLabelIter = getNodeLabels().values().iterator();
        nodeLabelIter.hasNext(); ) {
      final NodeLabel nodeLabel = nodeLabelIter.next();
      // Does this one the type we're looking for?
      if (nodeLabel.getTypeURI().equals(typeURI)) {
        // Yes
        retValue.add(nodeLabel);
      }
    } // for each nodeLabel

    // Stefan 7/23/09. If need to guarantee the order of objects this list
    // being the same for each call since the list is used to partition
    // the work up among multiple worker threads. Luckily this call
    // is only made once for every decorator in the beginning of a simulation
    // so sorting is not expensive.

    ECollections.sort(
        retValue,
        new Comparator<NodeLabel>() {

          public int compare(NodeLabel arg0, NodeLabel arg1) {
            Node n1 = arg0.getNode();
            Node n2 = arg1.getNode();
            if (n1 == null) {
              CorePlugin.logError(
                  "Label "
                      + arg0.getClass()
                      + " "
                      + arg0
                      + " uri:"
                      + arg0.getURI()
                      + " node is null",
                  new Exception());
              return 0;
            }
            if (n2 == null) {
              CorePlugin.logError(
                  "Label "
                      + arg1.getClass()
                      + " "
                      + arg1
                      + " uri:"
                      + arg1.getURI()
                      + " node is null",
                  new Exception());
              return 0;
            }
            URI u1 = n1.getURI();
            URI u2 = n2.getURI();
            if (u1 == null) {
              CorePlugin.logError("Node " + n1 + " missing URI", new Exception());
              return 0;
            }
            if (u2 == null) {
              CorePlugin.logError("Node " + n2 + " missing URI", new Exception());
              return 0;
            }

            return u1.toString().compareTo(u2.toString());
          }
        });

    return retValue;
  } // getNodeLabelsByTypeURI
 @Override
 public EList<XExpression> getActualArguments() {
   return getActualArguments(getOperand(), ECollections.<XExpression>emptyEList());
 }
示例#16
0
  public void testAsEMap() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    EMap<String, String> eMap = ECollections.asEMap(map);

    Map.Entry<String, String> entry = ECollections.singletonEMap("x", "y").get(0);

    map.put("aKey", "aValue");
    assertEquivalent(map, eMap);

    eMap.put("bKey", "bValue");
    assertEquivalent(map, eMap);

    try {
      eMap.move(1, 0);
      fail("move(int, int) should throw UnsupportedOperationException)");
    } catch (UnsupportedOperationException exception) {
      // We expect to get here.
    }

    try {
      eMap.move(1, eMap.get(0));
      fail("move(int, Object) should throw UnsupportedOperationException)");
    } catch (UnsupportedOperationException exception) {
      // We expect to get here.
    }

    try {
      eMap.add(0, entry);
      fail("add(int, Object) should throw UnsupportedOperationException)");
    } catch (UnsupportedOperationException exception) {
      // We expect to get here.
    }

    try {
      eMap.addAll(0, Collections.singleton(entry));
      fail("addAll(int, Collection) should throw UnsupportedOperationException)");
    } catch (UnsupportedOperationException exception) {
      // We expect to get here.
    }

    eMap.add(entry);
    assertEquivalent(map, eMap);

    eMap.remove(entry);
    assertEquivalent(map, eMap);

    map.put("aKey", "aValue2");
    assertEquivalent(map, eMap);

    eMap.put("bKey", "bValue2");
    assertEquivalent(map, eMap);

    map.remove("aKey");
    assertEquivalent(map, eMap);

    eMap.remove("bKey");
    assertEquivalent(map, eMap);

    Map<String, String> otherMap = new HashMap<String, String>();
    otherMap.put("aKey", "aValue");
    otherMap.put("bKey", "bValue");

    map.putAll(otherMap);
    assertEquivalent(map, eMap);

    map.clear();
    assertEquivalent(map, eMap);

    EMap<String, String> otherEMap = ECollections.asEMap(map);
    otherEMap.put("aKey", "aValue");
    otherEMap.put("bKey", "bValue");

    eMap.putAll(otherEMap);
    assertEquivalent(map, eMap);

    eMap.clear();
    assertEquivalent(map, eMap);
  }
示例#17
0
  @Override
  protected void setUp() {
    super.setUp();

    pkg = umlf.createPackage();
    pkg.setName("pkg");

    valueType = pkg.createOwnedPrimitiveType("Value");
    valueType
        .createOwnedOperation(
            "<",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            "<=",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            ">",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            ">=",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);

    thingType = pkg.createOwnedClass("Thing", false);

    values = thingType.createOwnedAttribute("values", valueType);
    values.setUpper(LiteralUnlimitedNatural.UNLIMITED);
    values.setIsOrdered(true);
    values.setIsUnique(true);

    bdValue = thingType.createOwnedAttribute("bdValue", getEcoreBigDecimal());
    biValue = thingType.createOwnedAttribute("biValue", getEcoreBigInteger());

    numeroType = pkg.createOwnedClass("Numero", false);

    numeroType
        .createOwnedOperation(
            "+",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "-",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "*",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "/",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);

    numeroType
        .createOwnedOperation(
            "-", ECollections.<String>emptyEList(), ECollections.<Type>emptyEList(), numeroType)
        .setIsQuery(true);

    numeroType
        .createOwnedOperation(
            "<",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "<=",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            ">",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            ">=",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "asLong",
            ECollections.<String>emptyEList(),
            ECollections.<Type>emptyEList(),
            getEcoreLong())
        .setIsQuery(true);

    numeros = thingType.createOwnedAttribute("numeros", numeroType);
    numeros.setUpper(LiteralUnlimitedNatural.UNLIMITED);
    numeros.setIsOrdered(true);
    numeros.setIsUnique(true);

    comparable = pkg.createOwnedClass("Comparable", true);
    comparable
        .createOwnedOperation(
            "compareTo",
            new BasicEList<String>(Collections.singleton("c")),
            new BasicEList<Type>(Collections.singleton(comparable)),
            getUMLInteger())
        .setIsQuery(true);

    // the Ecore counterpart

    epkg = UMLUtil.convertToEcore(pkg, null).iterator().next();

    ethingType = (EClass) epkg.getEClassifier(thingType.getName());
    enumeros = (EReference) ethingType.getEStructuralFeature(numeros.getName());
    evalues = (EAttribute) ethingType.getEStructuralFeature(values.getName());
    ebdValue = (EAttribute) ethingType.getEStructuralFeature(bdValue.getName());
    ebiValue = (EAttribute) ethingType.getEStructuralFeature(biValue.getName());

    enumeroType = (EClass) epkg.getEClassifier(numeroType.getName());
    enumeroType.setInstanceClass(Numero.class);

    evalueType = (EDataType) epkg.getEClassifier(valueType.getName());
    evalueType.setInstanceClass(Value.class);

    efactory = epkg.getEFactoryInstance();
    thing = efactory.create(ethingType);

    EPackage.Registry.INSTANCE.put(epkg.getNsURI(), epkg);

    @SuppressWarnings("unchecked")
    EList<Numero> list = (EList<Numero>) thing.eGet(enumeros);
    list.add(new Numero(6));
    list.add(new Numero(2));
  }
 private void fixZOrder(BPMNDiagram bpmnDiagram) {
   EList<DiagramElement> elements =
       (EList<DiagramElement>) bpmnDiagram.getPlane().getPlaneElement();
   ECollections.sort(elements, new DIZorderComparator());
 }
示例#19
0
  public void testIndexOf1() {
    EList<String> eList = new BasicEList<String>();
    eList.add("k");
    eList.add("a");
    eList.add("f");
    eList.add("k");
    eList.add("b");
    eList.add("z");
    eList.add("a");
    eList.add("b");

    assertEquals(0, ECollections.indexOf(eList, "k", -1));
    assertEquals(-1, ECollections.indexOf(eList, "k", 10));
    assertEquals(0, ECollections.indexOf(eList, "k", 0));
    assertEquals(1, ECollections.indexOf(eList, "a", 0));
    assertEquals(2, ECollections.indexOf(eList, "f", 0));
    assertEquals(3, ECollections.indexOf(eList, "k", 1));
    assertEquals(3, ECollections.indexOf(eList, "k", 3));
    assertEquals(4, ECollections.indexOf(eList, "b", 0));
    assertEquals(5, ECollections.indexOf(eList, "z", 0));
    assertEquals(6, ECollections.indexOf(eList, "a", 3));
    assertEquals(7, ECollections.indexOf(eList, "b", 5));

    eList = new UniqueEList<String>();
    eList.add("k");
    eList.add("a");
    eList.add("f");
    eList.add("k");
    eList.add("b");
    eList.add("z");
    eList.add("a");
    eList.add("b");

    assertEquals(0, ECollections.indexOf(eList, "k", -1));
    assertEquals(-1, ECollections.indexOf(eList, "k", 10));
    assertEquals(0, ECollections.indexOf(eList, "k", 0));
    assertEquals(1, ECollections.indexOf(eList, "a", 0));
    assertEquals(2, ECollections.indexOf(eList, "f", 0));
    assertEquals(-1, ECollections.indexOf(eList, "k", 1));
    assertEquals(-1, ECollections.indexOf(eList, "k", 3));
    assertEquals(3, ECollections.indexOf(eList, "b", 0));
    assertEquals(4, ECollections.indexOf(eList, "z", 0));
    assertEquals(-1, ECollections.indexOf(eList, "a", 3));
    assertEquals(-1, ECollections.indexOf(eList, "b", 5));
  }
  @Test
  public void testCreateControls() throws EMFFormsNoRendererException {
    /* setup */
    final VControl control1 = mock(VControl.class);
    final VFeaturePathDomainModelReference dmr1 = mock(VFeaturePathDomainModelReference.class);
    when(control1.getDomainModelReference()).thenReturn(dmr1);

    final VControl control2 = mock(VControl.class);
    final VFeaturePathDomainModelReference dmr2 = mock(VFeaturePathDomainModelReference.class);
    when(control2.getDomainModelReference()).thenReturn(dmr2);

    when(compoundControl.getControls()).thenReturn(ECollections.asEList(control1, control2));

    final EObject domainModel = mock(EObject.class);
    when(viewModelContext.getDomainModel()).thenReturn(domainModel);

    final DummyRenderer dummyRenderer1 = createDummyRenderer(control1);
    final DummyRenderer dummyRenderer2 = createDummyRenderer(control2);

    when(emfFormsRendererFactory.getRendererInstance(control1, viewModelContext))
        .thenReturn(dummyRenderer1);

    when(emfFormsRendererFactory.getRendererInstance(control2, viewModelContext))
        .thenReturn(dummyRenderer2);

    final CompoundControlSWTRenderer renderer = spy(createRenderer());

    doReturn(GridLayoutFactory.fillDefaults().create())
        .when(renderer)
        .getColumnLayout(any(Integer.class), any(Boolean.class));

    doReturn(GridDataFactory.fillDefaults().create())
        .when(renderer)
        .getLayoutData(
            any(SWTGridCell.class),
            any(SWTGridDescription.class),
            any(SWTGridDescription.class),
            any(SWTGridDescription.class),
            any(VElement.class),
            any(EObject.class),
            any(Control.class));

    doReturn(GridDataFactory.fillDefaults().create())
        .when(renderer)
        .getSpanningLayoutData(
            any(VContainedElement.class), any(Integer.class), any(Integer.class));

    /* act */
    final Control controls = renderer.createControls(shell);

    /* assert */
    assertTrue(Composite.class.isInstance(controls));
    final Composite controlsComposite = Composite.class.cast(controls);
    assertEquals(2, controlsComposite.getChildren().length);
    for (final Control control : controlsComposite.getChildren()) {
      assertTrue(Composite.class.isInstance(control));
    }

    final Composite control1Composite = Composite.class.cast(controlsComposite.getChildren()[0]);
    assertEquals(2, control1Composite.getChildren().length);
    for (final Control control : control1Composite.getChildren()) {
      assertTrue(Label.class.isInstance(control));
    }
    assertEquals(C_VALIDATION, Label.class.cast(control1Composite.getChildren()[0]).getText());
    assertEquals(C_CONTROL, Label.class.cast(control1Composite.getChildren()[1]).getText());

    final Composite control2Composite = Composite.class.cast(controlsComposite.getChildren()[1]);
    assertEquals(2, control2Composite.getChildren().length);
    for (final Control control : control2Composite.getChildren()) {
      assertTrue(Label.class.isInstance(control));
    }
    assertEquals(C_VALIDATION, Label.class.cast(control2Composite.getChildren()[0]).getText());
    assertEquals(C_CONTROL, Label.class.cast(control2Composite.getChildren()[1]).getText());

    verify(control1, times(1)).setLabelAlignment(LabelAlignment.NONE);
    verify(control2, times(1)).setLabelAlignment(LabelAlignment.NONE);
  }