@param element
@param toIndex
Swaps the elements indexes. "Element" gets "toIndex" index and
the previous element with index "toIndex" gets the previous
index of "element"
332381
public void replaceElementsIndexes(TopologyElement element, int toIndex) {
      int targetIndex = modules.indexOf(element);
      if (log.isDebugEnabled()) {
         if (modules == null) {
            log.warn("Modules in topology points to NULL");
         }
         if (element == null) {
            log.warn("Element to search in topology points to NULL");
         }
         log.debug("The topology consists of " + modules.size() + " modules. Replacing index " + toIndex + " with "
               + targetIndex + ". The element name whose index was searched was " + element.getName()
               + "and the topology was composed of modules: " + toString());
      }
      TopologyElement replaced = modules.set(toIndex, element);
      modules.set(targetIndex, replaced);
   }
14417
public static <T> PositionFactory<Iterable<? extends T>, T> atIndex(final int index) {
        return new PositionFactory<Iterable<? extends T>, T>(index) {

            @Override
            public String toString() {
                return String.format("Element [%s]", index);
            }

            @Override
            protected <P> Type evaluateElementType(Position<P> parentPosition) {
                return TypeUtils.getTypeArguments(parentPosition.getType(), Iterable.class)
                    .get(Iterable.class.getTypeParameters()[0]);
            }
        };
    }
347661
public void deselectByIndex(int index) {
        getDispatcher().beforeDeselect(this, index);
        
        new Select(getElement()).deselectByIndex(index);
        if (Config.getBoolConfigProperty(ConfigProperty.ENABLE_GUI_LOGGING)) {
            logUIActions(UIActions.CLEARED, Integer.toString(index));
        }
        
        getDispatcher().afterDeselect(this, index);
    }
1282432
public Element<T> getElement( int index , boolean fromFront ) {
		if( index > size || index < 0 ) {
			throw new IllegalArgumentException("index is out of bounds");
		}
		if( fromFront ) {
			Element<T> e = first;
			for( int i = 0; i < index; i++ ) {
				e = e.next;
			}
			return e;
		} else {
			Element<T> e = last;
			for( int i = 0; i < index; i++ ) {
				e = e.previous;
			}
			return e;
		}
	}
365393
public void remove( Element<T> element ) {
		if( element.next == null ) {
			last = element.previous;
		} else {
			element.next.previous = element.previous;
		}
		if( element.previous == null ) {
			first = element.next;
		} else {
			element.previous.next = element.next;
		}
		size--;
		element.clear();
		available.push(element);
	}
17063
public int lastIndexOf(E object, int to) {
        Object[] snapshot = elements;
        return lastIndexOf(object, snapshot, 0, to);
    }
732658
@Override
	public int lastIndexOf(long elem) {
		for (int i = size-1; i >= 0; i--)
			if (elem==elementData[i])
				return i;
		return -1;
	}
456334
public static <T> List<T> setOrAppend(List<T> list, int index, T element) {
		if (index < list.size()) {
			list.set(index, element);
		} else {
			list.add(element);
		}
		return list;
	}
1065593
function (collection, elements, settings, index) {
            for (var i = index + 1; i < elements.length; i++) {
                elements = swapElements(collection, elements, i - 1, i);
            }
            return collection.find(settings.elements_selector);
        }
1152848
private int getElementIndex(Node node) {
        final String nodeName = node.getNodeName();

        int count = 1;
        for (Node previousSibling = node.getPreviousSibling();
                previousSibling != null;
                previousSibling = previousSibling.getPreviousSibling()) {
            if (previousSibling.getNodeType() == Node.ELEMENT_NODE
                    && previousSibling.getNodeName().equals(nodeName)) {
                count++;
            }
        }

        return count;
    }
1028975
public Object set(int index, Object element)
    {
        checkElement(element);
        return super.set(index, element);
    }
405636
public void update(int element, double priority) {
    this.doImport(element);
    final double q = this.prior.get(element);
    if (Double.compare(q, priority) == 0)
      return;
    this.prior.set(element, priority);
    if (this.pos.get(element) < 0)
      return;
    if (priority < q)
      this.down(element);
    if (q < priority)
      this.up(element);
  }
1067694
@Override
    public void add(int index, T element) {
        if (displacement != null) {
            super.add(index - displacement, element);
        } else {
            super.add(index, element);
        }
    }
1323107
public Object set(int index, Object element)
    {
        if ((index < m_iStartIndex) || (index >= m_iStartIndex + m_iMaxSize))
        { // Out of bounds, re-adjust bounds
            int iNewStart = index - m_iMaxSize / 2;   // index should be right in the middle
            if (iNewStart < 0)
                iNewStart = 0;
            int iStart = 0;
            int iEnd = this.size() - 1;
            int iIncrement = +1;
            if (iNewStart < m_iStartIndex)
            {   // Go backwards to avoid overlaying values
                iStart = iEnd;
                iEnd = 0;
                iIncrement = -1;
            }
            for (int i = iStart; i * iIncrement <= iEnd; i = i + iIncrement)
            {
                Object obj = super.set(i, null);                // Get and clear value
                int iShiftedIndex = i + m_iStartIndex - iNewStart;
                if ((iShiftedIndex >= 0) && (iShiftedIndex < this.size()))
                    super.set(iShiftedIndex, obj);              // Move/set it!
                else
                    this.freeObject(m_iStartIndex + i, obj);    // Notify obj
            }
            m_iStartIndex = iNewStart;
        }
        if (index >= m_iStartIndex + this.size())
        { // Need to add empty elements inbetween
            for (int i = m_iStartIndex + this.size(); i <= index; i++)
                this.add(null);     // Add a placeholder
        }
        index = index - m_iStartIndex;
        return super.set(index, element);
    }
743514
@Override
    public void removeRange(int fromIndex, int toIndex) {
        if (fromIndex > toIndex) {
            throw new IllegalArgumentException("fromIndex must be <= toIndex");
        }
        for (int i = toIndex; i >= fromIndex; i--) {
            removeElementAt(i);
        }
        fireIntervalRemoved(this, fromIndex, toIndex);
    }
670124
public int swapIndex(final String index,
                       final String alias) throws IndexException {
    //IndicesAliasesResponse resp = null;
    try {
      /* index is the index we were just indexing into
       */

      final IndicesAdminClient idx = getAdminIdx();

      final GetAliasesRequestBuilder igarb = idx.prepareGetAliases(
              alias);

      final ActionFuture<GetAliasesResponse> getAliasesAf =
              idx.getAliases(igarb.request());
      final GetAliasesResponse garesp = getAliasesAf.actionGet();

      final ImmutableOpenMap<String, List<AliasMetaData>> aliasesmeta =
              garesp.getAliases();

      final IndicesAliasesRequestBuilder iarb = idx.prepareAliases();

      final Iterator<String> it = aliasesmeta.keysIt();

      while (it.hasNext()) {
        final String indexName = it.next();

        for (final AliasMetaData amd: aliasesmeta.get(indexName)) {
          if(amd.getAlias().equals(alias)) {
            iarb.removeAlias(indexName, alias);
          }
        }
      }

      iarb.addAlias(index, alias);

      final ActionFuture<IndicesAliasesResponse> af =
              idx.aliases(iarb.request());

      /*resp = */af.actionGet();

      return 0;
    } catch (final ElasticsearchException ese) {
      // Failed somehow
      error(ese);
      return -1;
    } catch (final IndexException ie) {
      throw ie;
    } catch (final Throwable t) {
      throw new IndexException(t);
    }
  }
556342
public void remove(T element) {
      lock.writeLock().lock();
      try {
         if (outgoingEdges.remove(element) != null) {
            for (Set<T> values : outgoingEdges.values()) {
               values.remove(element);
            }
         }
         if (incomingEdges.remove(element) != null) {
            for (Set<T> values : incomingEdges.values()) {
               values.remove(element);
            }
         }
      } finally {
         lock.writeLock().unlock();
      }
   }