/**
   * Moves a node (an Item) in the container immediately after a sibling node. The two nodes must
   * have the same parent in the container.
   *
   * @param itemId the identifier of the moved node (Item)
   * @param siblingId the identifier of the reference node (Item), after which the other node will
   *     be located
   */
  public void moveAfterSibling(Object itemId, Object siblingId) {
    Object parent2 = getParent(itemId);
    LinkedList<Object> childrenList;
    if (parent2 == null) {
      childrenList = roots;
    } else {
      childrenList = children.get(parent2);
    }
    if (siblingId == null) {
      childrenList.remove(itemId);
      childrenList.addFirst(itemId);

    } else {
      int oldIndex = childrenList.indexOf(itemId);
      int indexOfSibling = childrenList.indexOf(siblingId);
      if (indexOfSibling != -1 && oldIndex != -1) {
        int newIndex;
        if (oldIndex > indexOfSibling) {
          newIndex = indexOfSibling + 1;
        } else {
          newIndex = indexOfSibling;
        }
        childrenList.remove(oldIndex);
        childrenList.add(newIndex, itemId);
      } else {
        throw new IllegalArgumentException("Given identifiers no not have the same parent.");
      }
    }
    fireItemSetChange();
  }
  public void swap(LinkedList n, int a, int b) {
    if (n.isEmpty()) {
      return;
    } else {
      int x = 0;
      int y = 0;
      if (n.contains(a)) {
        x = n.indexOf(a);
      }
      if (n.contains(b)) {
        y = n.indexOf(b);
      }

      if (x < y) {
        n.remove(x);
        n.add(y, a);
        n.remove(y - 1);
        n.add(x, b);
      } else {
        n.remove(y);
        n.add(x, b);
        n.remove(x - 1);
        n.add(y, a);
      }
    }
    System.out.println(n);
  }
Пример #3
0
  @Override
  public void maybeShowPopup(MouseEvent e, JPopupMenu popupMenu) {
    if (e.isPopupTrigger()) {
      String text = "Delete ";

      // if context menu is requested on a TextBox, customize popup menu.
      if (pressedTextBox != null) {
        text += pressedTextBox.getText();
        menuItemMoveUp.setEnabled(
            attributesView.indexOf(pressedTextBox) != 0
                && methodsView.indexOf(pressedTextBox) != 0);
        menuItemMoveDown.setEnabled(
            (attributesView.size() == 0
                    || attributesView.indexOf(pressedTextBox) != attributesView.size() - 1)
                && (methodsView.size() == 0
                    || methodsView.indexOf(pressedTextBox) != methodsView.size() - 1));
      } else {
        text += component.getName();
        menuItemMoveUp.setEnabled(false);
        menuItemMoveDown.setEnabled(false);
      }
      menuItemDelete.setText(text);
    }

    super.maybeShowPopup(e, popupMenu);
  }
  public int determinerPlusPetiteCarte(LinkedList<Carte> cartes) {
    int index = -1;
    for (Iterator<Carte> cartesJoueur = cartes.iterator(); cartesJoueur.hasNext(); ) {
      Carte carteActuel = cartesJoueur.next();
      if (index == -1) {
        index = cartes.indexOf(carteActuel);
      } else if (carteActuel.getForceCarte() < cartes.get(index).getForceCarte()) {
        index = cartes.indexOf(carteActuel);
      }
    }

    return index;
  }
  public int determinerMeilleurCarteInferieur(Partie p, LinkedList<Carte> cartes) {
    int index = -1;
    for (Iterator<Carte> cartesJoueur = cartes.iterator(); cartesJoueur.hasNext(); ) {
      Carte carteActuel = cartesJoueur.next();
      if (index == -1) {
        index = cartes.indexOf(carteActuel);
      } else if ((carteActuel.getForceCarte() < cartes.get(index).getForceCarte())
          && p.getTas().isCarteValide(carteActuel)) {
        index = cartes.indexOf(carteActuel);
      }
    }

    return index;
  }
Пример #6
0
  private void buildStateModel() {
    stateModel = new DynamicMenuModel();
    DefaultMenuItem homeItem = new DefaultMenuItem();
    homeItem.setAjax(false);
    homeItem.setValue("home");
    homeItem.setId(
        FacesContext.getCurrentInstance().getViewRoot().createUniqueId() + "_state_home");
    homeItem.setImmediate(true);
    homeItem.setCommand("#{stateController.clearStateAndGoHome}");
    stateModel.addElement(homeItem);
    for (StateItem stateItem : stateItens) {
      DefaultMenuItem item = new DefaultMenuItem();
      item.setAjax(stateItem.isAjax());
      item.setGlobal(stateItem.isGlobal());
      item.setResetValues(stateItem.isResetValues());
      item.setTitle(stateItem.getTitle());
      item.setImmediate(stateItem.isImmediate());
      item.setValue(getItemValue(stateItem.getValue()));
      if (stateItem.getOncomplete() != null && !"".equals(stateItem.getOncomplete())) {
        item.setOncomplete(stateItem.getOncomplete());
      }
      item.setId(FacesContext.getCurrentInstance().getViewRoot().createUniqueId() + "_state");
      if (stateItem.getOutcome() != null && !"".equals(stateItem.getOutcome())) {
        item.setIncludeViewParams(true);
        StringBuilder url = new StringBuilder(stateItem.getOutcome());
        if (stateItem.isAddEntityIdParam()) {
          url.append("?id=").append(((BaseEntity) stateItem.getEntity()).getId());
        }
        if (url.toString().contains("?")) {
          url.append("&pullState=true");
        } else {
          url.append("?pullState=true"); // tell statePusher to not call preRenderView event
        }
        url.append("&itemIndex=").append(stateItens.indexOf(stateItem));
        item.setUrl(url.toString());
      } else { // if has not outcome set command, note that they are muttually exclusive:
               // http://stackoverflow.com/questions/16437336/using-both-setactionexpression-and-seturl-on-menuitem-object-is-not-working
        item.setCommand("#{stateController.pullStateItem(" + stateItens.indexOf(stateItem) + ")}");
      }
      if (!"".equals(stateItem.getUpdate())) {
        item.setUpdate(stateItem.getUpdate());
      }

      if (stateItens.indexOf(stateItem) == stateItens.size() - 1) {
        item.setDisabled(true);
        item.setStyleClass("ui-state-disabled");
      }
      stateModel.addElement(item);
    }
  }
  private static void addFacetsToJSONObjectToReturn(JSONObject jsonToReturn) {
    JSONArray arr_of_facets = new JSONArray();
    JSONObject facet = new JSONObject();
    LinkedList<Count> facets = new LinkedList<Count>();

    facets.addAll(ChartSearchSearcher.getFacetFieldValueNamesAndCounts());
    if (!facets.isEmpty()) {
      for (int i = facets.indexOf(facets.getFirst()); i <= facets.indexOf(facets.getLast()); i++) {
        facet.put("facet", generateFacetsJson(facets.get(i)));
        arr_of_facets.add(facet);
      }
    }
    jsonToReturn.put("facets", arr_of_facets);
  }
Пример #8
0
  private boolean addItem(LinkedList<ItemInfo> items, ItemInfo itemInfo) {
    boolean added = false;

    int idx = items.indexOf(itemInfo);
    if (idx != -1) {
      // HACK: Always swap existing ItemInfos with our new one, since it will
      // more up-to-date information
      ItemInfo existing = items.set(idx, itemInfo);
      assert (existing != null);
      return (true);
    }
    if (itemInfo.hasCurrentPrice())
      assert (itemInfo.getCurrentPrice() > 0) : "Negative current price for " + itemInfo;

    // If we have room, shove it right in
    // We'll throw it in the back because we know it hasn't been used yet
    if (items.size() < AuctionMarkConstants.ITEM_ID_CACHE_SIZE) {
      items.addLast(itemInfo);
      added = true;

      // Otherwise, we can will randomly decide whether to pop one out
    } else if (this.rng.nextBoolean()) {
      items.pop();
      items.addLast(itemInfo);
      added = true;
    }
    return (added);
  }
Пример #9
0
  /** 测试从AbstractSequentialList中继承的方法 */
  private static void testLinkedListFromASL() {
    System.out.println(
        "Test methods: add(), addAll(Collection<?> extends E c), get(int index), set(int index, E e), remove(int index), clear(), clone()");

    // 将"a", "b"添加到list中
    LinkedList<String> list = new LinkedList<String>();
    list.add("a");
    list.add("b");
    printList(list);

    // 将含有"c", "d"的集合list2添加到list中
    LinkedList<String> list2 = new LinkedList<String>();
    list2.add("c");
    list2.add("d");
    list.addAll(list.size(), list2);
    printList(list);

    // 将list中的最后一个元素设置成第一个元素
    list.set(list.size() - 1, list.get(0)); // list.set(index, e)、list.get(index)都不推荐使用!
    printList(list);

    // 将第一个"a"元素从list中移除
    list.remove(list.indexOf("a"));
    printList(list);

    // 将list克隆一份
    LinkedList<String> cloneList = (LinkedList<String>) list.clone();
    printList(cloneList);

    // 将list中元素清除
    list.clear();
    System.out.println("list elements : " + list + " list size : " + list.size());
  }
Пример #10
0
 /*
  *(non-Javadoc)
  * @see android.widget.AdapterView#setSelection(int)
  */
 @Override
 public void setSelection(int position) {
   mNextScreen = INVALID_SCREEN;
   mScroller.forceFinished(true);
   if (mAdapter != null) {
     position = Math.max(position, 0);
     position = Math.min(position, mAdapter.getCount() - 1);
     recycleViews();
     View currentView = makeAndAddView(position, true);
     mLoadedViews.addLast(currentView);
     for (int offset = 1; mBufferedItemCount - offset >= 0; offset++) {
       int leftIndex = position - offset;
       int rightIndex = position + offset;
       if (leftIndex >= 0) {
         mLoadedViews.addFirst(makeAndAddView(leftIndex, false));
       }
       if (rightIndex < mAdapter.getCount()) {
         mLoadedViews.addLast(makeAndAddView(rightIndex, true));
       }
     }
     mCurrentBufferIndex = mLoadedViews.indexOf(currentView);
     mCurrentAdapterIndex = position;
     requestLayout();
     setVisibleView(mCurrentBufferIndex, false);
     if (viewSwitchListener != null) {
       viewSwitchListener.onSwitched(currentView, mCurrentAdapterIndex);
     }
   }
 }
    private void zoomOut() {
      int M = communities.size();
      LinkedList<Edge>[] newTopology = new LinkedList[M];
      int index = 0;
      nodeCommunities = new Community[M];
      nodeConnectionsWeight = new HashMap[M];
      nodeConnectionsCount = new HashMap[M];
      HashMap<Integer, Community> newInvMap = new HashMap<>();
      for (int i = 0; i < communities.size(); i++) { // Community com : mCommunities) {
        Community com = communities.get(i);
        nodeConnectionsWeight[index] = new HashMap<>();
        nodeConnectionsCount[index] = new HashMap<>();
        newTopology[index] = new LinkedList<>();
        nodeCommunities[index] = new Community(com);
        Set<Community> iter = com.connectionsWeight.keySet();
        double weightSum = 0;

        Community hidden = new Community(structure);
        for (Integer nodeInt : com.nodes) {
          Community oldHidden = invMap.get(nodeInt);
          hidden.nodes.addAll(oldHidden.nodes);
        }
        newInvMap.put(index, hidden);
        for (Community adjCom : iter) {
          int target = communities.indexOf(adjCom);
          double weight = com.connectionsWeight.get(adjCom);
          if (target == index) {
            weightSum += 2. * weight;
          } else {
            weightSum += weight;
          }
          Edge e = new Edge(index, target, weight);
          newTopology[index].add(e);
        }
        weights[index] = weightSum;
        nodeCommunities[index].seed(index);

        index++;
      }
      communities.clear();

      for (int i = 0; i < M; i++) {
        Community com = nodeCommunities[i];
        communities.add(com);
        for (Edge e : newTopology[i]) {
          nodeConnectionsWeight[i].put(
              nodeCommunities[e.getTarget()],
              Double.parseDouble(e.getProperty("weight").toString()));
          nodeConnectionsCount[i].put(nodeCommunities[e.getTarget()], 1);
          com.connectionsWeight.put(
              nodeCommunities[e.getTarget()],
              Double.parseDouble(e.getProperty("weight").toString()));
          com.connectionsCount.put(nodeCommunities[e.getTarget()], 1);
        }
      }

      N = M;
      topology = newTopology;
      invMap = newInvMap;
    }
Пример #12
0
  /**
   * Obtain top callers by calls.
   *
   * @param activity caller activity
   * @param startBillingDay starting billing day
   * @return ArrayList with all calls made
   */
  private static ArrayList<CallStat> getTopCallersByCalls() {

    LinkedList<ContactValue> data = new LinkedList<ContactValue>();

    for (Chargeable chargeable : calls) {
      Call call = (Call) chargeable;
      Contact contact = call.getContact();
      if (data.contains(contact)) {
        ContactValue contactValue = data.get(data.indexOf(contact));
        contactValue.incValue((long) 1);
      } else {
        ContactValue contactValue = new ContactValue(contact, (long) 1);
        data.add(contactValue);
      }
    }

    Collections.sort(data);

    ArrayList<CallStat> ret = new ArrayList<CallStat>();
    int i = 0;
    for (ContactValue cv : data) {
      ret.add(new CallStat(cv.getContact().getContactName(), String.valueOf(cv.getValue())));
      i++;
      if (i > 20) {
        break;
      }
    }
    return ret;
  }
Пример #13
0
 public WorldPowerName getNextWorldPower(WorldPowerName currentWorldPower) {
   int nextPowerIndex = worldPowerOrder.indexOf(currentWorldPower) + 1;
   if (nextPowerIndex >= worldPowerOrder.size()
       || worldPowerOrder.get(nextPowerIndex) == WorldPowerName.UNKNOWN)
     return WorldPowerName.SOVIET_UNION;
   return worldPowerOrder.get(nextPowerIndex);
 }
 private static Configuration getConfiguration(IProject project) {
   Configuration configuration = null;
   if (!configurations.isEmpty()) {
     System.out.println("1");
     for (Configuration tempConfiguration : configurations) {
       if (tempConfiguration.getProject().equals(project)) configuration = tempConfiguration;
     }
   }
   if (configuration == null) {
     System.out.println("2");
     configuration = loadConfiguration(project);
   }
   if (configuration == null) {
     System.out.println("3");
     configuration = new Configuration(project);
     LinkedList<String> smellIdList = new LinkedList<String>();
     if (allSmells == null) getAllModelSmells();
     double[] limits = new double[allSmells.size()];
     for (ModelSmell smell : allSmells) {
       smellIdList.add(smell.getId());
       System.out.println("add: " + smell.getId());
       if (smell.getFinderClass() instanceof MetricBasedModelSmellFinderClass) {
         limits[allSmells.indexOf(smell)] = 1.0;
         // ((MetricBasedModelSmellFinderClass)smell.getFinderClass()).setLimit(1.0);
       }
     }
     configuration.setSelection(smellIdList);
     configuration.setLimits(limits);
   }
   configurations.add(configuration);
   return configuration;
 }
  private Node nodeFilter(Node currentNode) {
    LinkedList<Node> currentChildNode = currentNode.getChildNodes();
    if (currentNode.getParentNode() != null) {
      if (!currentNode.getContent().equals("")) {
        LinkedList<Node> parentChildNodes = currentNode.getParentNode().getChildNodes();
        int startPostion = parentChildNodes.indexOf(currentNode);
        int i = startPostion;
        Node parentNode = currentNode.getParentNode();
        String content = currentNode.getContent();
        String[] contentArray = content.split("\\r?\\n");

        if (contentArray.length > 1) {
          currentNode.setContent(contentArray[0]);
          for (int j = 1; j < contentArray.length; j++) {
            Node nodeToAdd = new Node();
            nodeToAdd.setTitle("br");
            nodeToAdd.setParentNode(parentNode);
            parentChildNodes.add(++i, nodeToAdd);
            nodeToAdd = new Node();
            nodeToAdd.setContent(contentArray[i]);
            nodeToAdd.setParentNode(parentNode);
            parentChildNodes.add(++i, nodeToAdd);
          }
        }
      }
    }
    for (int i = 0; i < currentChildNode.size(); i++) {
      nodeFilter(currentChildNode.get(i));
    }
    return currentNode;
  }
  @Override
  public void setSelection(int position) {
    if (adapter == null) {
      return;
    }

    Assert.assertTrue("Invalid selection position", position >= 0 && position < adapterDataCount);

    releaseViews();

    View selectedView = viewFromAdapter(position, true);
    bufferedViews.add(selectedView);

    for (int i = 1; i <= sideBufferSize; i++) {
      int previous = position - i;
      int next = position + i;

      if (previous >= 0) {
        bufferedViews.addFirst(viewFromAdapter(previous, false));
      }
      if (next < adapterDataCount) {
        bufferedViews.addLast(viewFromAdapter(next, true));
      }
    }

    bufferIndex = bufferedViews.indexOf(selectedView);
    adapterIndex = position;

    requestLayout();
    updateVisibleView(inFlipAnimation ? -1 : bufferIndex);

    cards.resetSelection(position, adapterDataCount);
  }
Пример #17
0
 /**
  * Returns the index at which the given annotation exists in the range. -1 if the item is
  * disposed, or doesn't exist in this slider.
  *
  * @param item
  * @return the index at which the given annotation exists in the range. -1 if the item is
  *     disposed, or doesn't exist in this slider.
  */
 public int getIndex(RangeAnnotation item) {
   checkWidget();
   if (item == null || item.isDisposed()) {
     return -1;
   }
   return (items.indexOf(item));
 }
  public int determinerSiCarteSimilaire(Partie p, LinkedList<Carte> cartes) {
    int index = -1;
    for (Iterator<Carte> cartesJoueur = cartes.iterator(); cartesJoueur.hasNext(); ) {
      Carte carteActuel = cartesJoueur.next();
      if (p.getTas().getDerniereCarte().getValeurCarte() == ValeurCarte.AS
          && (carteActuel.getForceCarte() == p.getTas().getDerniereCarte().getForceCarte())) {
        index = cartes.indexOf(carteActuel);
      }

      if (!p.getTas().getDerniereCarte().isCarteSpeciale()
          && (carteActuel.equals(p.getTas().getDerniereCarte()))) {
        index = cartes.indexOf(carteActuel);
      }
    }
    return index;
  }
Пример #19
0
  public String taxiUnavailable(Order order) {
    System.out.println("TaxiDispatcher: " + order.getTaxiID() + " now unavailable");

    for (TaxiQueueItem t : availableTaxis) {
      if (order.getTaxiID().equals(t.getTaxiID())) {
        availableTaxis.remove(t);
      }
    }

    if (order.getUserID() == null) {
      System.out.println("TaxiDispatcher: noReject");
      return "noReject"; // no need to do anything more; is not handled as case in diagram
    }

    if (!availableTaxis.isEmpty()) {
      return "assignTaxi";
    } else {
      order.setMessage("No taxis available at the moment, see queue number...");

      for (Order o : pendingOrders) {
        if (o.getUserID().equals(order.getUserID())) {
          order.setPlaceInQueue(pendingOrders.indexOf(o));
        }
      }

      this.tempOrder = order;
      System.out.println("TaxiDispatcher: queueing " + order.getOrderInfo());
      return "queue";
    }
  }
  protected void listMouseClicked(EventObject e) {
    for (ListLevel listLevelTuple : depthLists) {
      listLevelTuple.list.setCellRenderer(new SceneDepthListCellRender());
    }

    JList list = (JList) e.getSource();
    selectedScene = (Scene) list.getSelectedValue();
    jumpToBt.setEnabled(true);
    jumpToBt.setText("Jump to [" + selectedScene.getName() + "]");

    int idx = depthLists.indexOf(new ListLevel(-1, list));
    assert idx != -1 : "Should have found a scenesList";

    if (idx == 0) {
      JList startList = depthLists.get(1).list;
      startList.setCellRenderer(new ToCellRenderer(selectedScene));
      Util.showComponent(startList);
    } else if (idx > 0) {
      JList fromList = depthLists.get(idx - 1).list;
      logger.debug("Before: " + fromList.getSelectedValue());

      fromList.setCellRenderer(new FromCellRenderer(selectedScene));
      Util.showComponent(fromList);

      if (idx + 1 < depthLists.size()) {
        JList afterList = depthLists.get(idx + 1).list;
        logger.debug("After: " + afterList.getSelectedValue());

        afterList.setCellRenderer(new ToCellRenderer(selectedScene));
        Util.showComponent(afterList);
      }
    }

    Util.showComponent(panel);
  }
Пример #21
0
 public static void main(String args[]) {
   ArrayList<Integer> numList = new ArrayList<Integer>();
   for (int i = 1; i <= 5; i++) {
     numList.add(i);
   }
   System.out.println("Size of Array List is " + numList.size());
   System.out.println("List elements");
   ListIterator<Integer> li = numList.listIterator();
   for (; li.hasNext(); ) {
     Integer num = li.next();
     System.out.println(num);
   }
   System.out.println("List elements in reverse");
   for (; li.hasPrevious(); ) {
     Integer num = li.previous();
     System.out.println(num);
   }
   LinkedList<String> strList = new LinkedList<String>();
   strList.add("abc");
   strList.add("def");
   strList.add("abc");
   strList.add("ghi");
   System.out.println("Index of abc is: " + strList.indexOf("abc"));
   System.out.println("Size of Linked List is " + strList.size());
   strList.remove("abc");
   for (ListIterator<String> ls = strList.listIterator(); ls.hasNext(); ) {
     String str = ls.next();
     System.out.println(str);
   }
 }
Пример #22
0
  @Override
  public void addProbe(
      JrdsElement hostElement, ProbeDescSummary summary, HttpServletRequest request) {
    String name = summary.name;

    // Don't discover if asked to don't do
    if (summary.specifics.get("nodiscover") != null) return;

    summaries.put(summary.name, summary);
    String hidesStr = summary.specifics.get("hides");
    if (hidesStr != null && !hidesStr.trim().isEmpty()) {
      int pos = Integer.MAX_VALUE;
      for (String hides : hidesStr.split(",")) {
        int hidesPos = sortedProbeName.indexOf(hides.trim());
        pos = hidesPos != -1 ? Math.min(pos, hidesPos) : pos;
      }
      if (pos > sortedProbeName.size()) {
        // No hides found, add at the end
        sortedProbeName.add(name);
      } else {
        // add before the first hidden probe
        sortedProbeName.add(pos, name);
      }
    }
    // No hide, just put
    else {
      sortedProbeName.add(name);
    }
    return;
  }
  public void updateRecentlyOpenedFiles(String s) {
    // try to add this file to the list and update the preference
    Iterator i = list.iterator();

    // update the maxFile count in case it changed...
    list.remove(0);
    list.add(0, maxSize);

    // is file already in list?
    if (list.contains(s)) {
      int index = list.indexOf(s);
      list.remove(index);
      list.add(1, s);

    } else {
      // if it's not in the list add it to the top and deal with it later
      list.add(1, s);
    }

    // trim list if necessary...
    while (list.size() > (maxsize + 1)) list.removeLast();

    // build a new pref String;
    StringBuffer sbuffer = new StringBuffer();

    i = list.iterator();

    while (i.hasNext()) {
      sbuffer.append((String) i.next());
      sbuffer.append("*");
    }
    // update the preference
    openFilePref.setValue(sbuffer.toString());
  }
 void unregisterAccelerator(AWTKeyStroke stroke) {
   if (stroke == null) return;
   if (embedder != null && embedder.isActive()) {
     int index = strokes.indexOf(stroke);
     embedder.unregisterAccelerator(index);
   }
 }
Пример #25
0
  /**
   * Deeply list the opaque ports connected to this port on the outside. Begin by listing the ports
   * that are connected to this port. If any of those are transparent ports that we are connected to
   * from the inside, then list all the ports deeply connected on the outside to that transparent
   * port. If any are transparent ports that we are connected to from the outside, then list opaque
   * ports deeply inside that port. Note that a port may be listed more than once. The path argument
   * is the path from the port that originally calls this method to this port. If this port is
   * already on the list of ports on the path to this port in deeply traversing the topology, then
   * there is a loop in the topology, and an InvalidStateException is thrown. This method not
   * synchronized on the workspace, so the caller should.
   *
   * @param path The list of ports on the path to this port in deeply traversing the topology.
   * @return An unmodifiable list of ComponentPort objects.
   */
  protected List _deepConnectedPortList(LinkedList path) {
    if (_deepLinkedPortsVersion == _workspace.getVersion()) {
      // Cache is valid.  Use it.
      return _deepLinkedPorts;
    }

    if (path == null) {
      path = new LinkedList();
    } else {
      if (path.indexOf(this) >= 0) {
        throw new InvalidStateException(path, "Loop in topology!");
      }
    }

    path.add(0, this);

    Iterator nearRelations = linkedRelationList().iterator();
    LinkedList result = new LinkedList();

    while (nearRelations.hasNext()) {
      ComponentRelation relation = (ComponentRelation) nearRelations.next();

      // A null link (supported since indexed links) might
      // yield a null relation here. EAL 7/19/00.
      if (relation != null) {
        Iterator connectedPorts = relation.linkedPortList(this).iterator();

        while (connectedPorts.hasNext()) {
          ComponentPort port = (ComponentPort) connectedPorts.next();

          // NOTE: If level-crossing transitions are not allowed,
          // then a simpler test than that of the following
          // would work.
          if (port._isInsideLinkable(relation.getContainer())) {
            // We are coming at the port from the inside.
            if (port.isOpaque()) {
              result.add(port);
            } else {
              // Port is transparent
              result.addAll(port._deepConnectedPortList(path));
            }
          } else {
            // We are coming at the port from the outside.
            if (port.isOpaque()) {
              result.add(port);
            } else {
              // It is transparent.
              result.addAll(port._deepInsidePortList(path));
            }
          }
        }
      }
    }

    _deepLinkedPorts = Collections.unmodifiableList(result);
    _deepLinkedPortsVersion = _workspace.getVersion();
    path.remove(0);
    return _deepLinkedPorts;
  }
Пример #26
0
 /**
  * @param players
  * @return the player array with the this player first, while conserving the order
  */
 private LinkedList<Player> putCurrentPlayerFirst(LinkedList<Player> players) {
   LinkedList<Player> sorted = new LinkedList<>();
   int indexOfPlayer = players.indexOf(this);
   for (int i = 0; i < 4; i++) {
     sorted.add(players.get((indexOfPlayer + i) % 4));
   }
   return sorted;
 }
  private boolean __insertEdge(Vertex vertexFrom, Vertex vertexTo, int weight) {

    if (vertices.indexOf(vertexFrom) == -1 || vertices.indexOf(vertexTo) == -1) return false;
    else {

      Edge edge = new Edge(vertexTo, vertexFrom, weight);

      int indexOfVertexList = 0;

      if (vertexFrom.getEdges().size() == 0) {
        vertexFrom.getEdges().add(edge);
        vertexFrom.outDegree++;
        vertexTo.inDegree++;
        return true;
      } else {

        while (indexOfVertexList < vertexFrom.getEdges().size()
            && vertexTo
                    .getData()
                    .compareTo(vertexFrom.getEdges().get(indexOfVertexList).getToVertex().getData())
                == 1) {

          indexOfVertexList++;
        }

        if (indexOfVertexList < vertexFrom.getEdges().size()
            && vertexTo
                    .getData()
                    .compareTo(vertexFrom.getEdges().get(indexOfVertexList).getToVertex().getData())
                == 0) {
          System.out.println("?????????????? ?????? ????????????");
          return false;
        } else {

          if (indexOfVertexList < vertexFrom.getEdges().size())
            vertexFrom.getEdges().add(indexOfVertexList, edge);
          else vertexFrom.getEdges().addLast(edge);

          vertexFrom.outDegree++;
          vertexTo.inDegree++;

          return true;
        }
      }
    }
  }
Пример #28
0
 @Override
 public void DoStandInWaitingForServiceLine() {
   customersWaitingForService.add(customer);
   waitingForService = true;
   xDestination =
       MarketPanel.SERVICEWAITINGX + (customersWaitingForService.indexOf(customer) * 30);
   yDestination = MarketPanel.SERVICEWAITINGY;
 }
  void flippedToView(final int indexInAdapter, boolean isPost) {
    if (AphidLog.ENABLE_DEBUG) {
      AphidLog.d("flippedToView: %d, isPost %s", indexInAdapter, isPost);
    }

    debugBufferedViews();

    if (indexInAdapter >= 0 && indexInAdapter < adapterDataCount) {

      if (indexInAdapter == adapterIndex + 1) { // forward one page
        if (adapterIndex < adapterDataCount - 1) {
          adapterIndex++;
          View old = bufferedViews.get(bufferIndex);
          if (bufferIndex + 1 > sideBufferSize) {
            releaseView(bufferedViews.removeFirst());
          }
          if (adapterIndex + sideBufferSize < adapterDataCount) {
            bufferedViews.addLast(viewFromAdapter(adapterIndex + sideBufferSize, true));
          }
          bufferIndex = bufferedViews.indexOf(old) + 1;
          requestLayout();
          updateVisibleView(bufferIndex);
        }
      } else if (indexInAdapter == adapterIndex - 1) {
        if (adapterIndex > 0) {
          adapterIndex--;
          View old = bufferedViews.get(bufferIndex);
          if (bufferIndex - 1 + sideBufferSize < bufferedViews.size() - 1) {
            releaseView(bufferedViews.removeLast());
          }
          if (adapterIndex - sideBufferSize >= 0) {
            bufferedViews.addFirst(viewFromAdapter(adapterIndex - sideBufferSize, false));
          }
          bufferIndex = bufferedViews.indexOf(old) - 1;
          requestLayout();
          updateVisibleView(bufferIndex);
        }
      } else {
        AphidLog.e(
            "Should not happen: indexInAdapter %d, adapterIndex %d", indexInAdapter, adapterIndex);
      }
    } else {
      Assert.fail("Invalid indexInAdapter: " + indexInAdapter);
    }
    // debugBufferedViews();
  }
Пример #30
0
 @Override
 public void DoStandInWaitingForItemsLine() {
   customersWaitingForItems.add(customer);
   waitingForItems = true;
   xDestination =
       MarketPanel.ITEMSWAITINGX - (customersWaitingForItems.indexOf(customer) * 30) - 20;
   ;
   yDestination = MarketPanel.ITEMSWAITINGY;
 }