예제 #1
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;
 }
  @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));
          }
        });
  }
예제 #4
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.
  }
예제 #5
0
파일: GraphImpl.java 프로젝트: teropa/stem
  /**
   *
   * <!-- 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
 private void fixZOrder(BPMNDiagram bpmnDiagram) {
   EList<DiagramElement> elements =
       (EList<DiagramElement>) bpmnDiagram.getPlane().getPlaneElement();
   ECollections.sort(elements, new DIZorderComparator());
 }