Ejemplo n.º 1
1
 @Override
 public synchronized void swapColumns(final int a, final int b) {
   ensureChangeAllowed();
   setColumn(setColumn(getColumn(null, a), b), a).clear();
   Collections.swap(widths, a, b);
   Collections.swap(colNames, a, b);
 }
Ejemplo n.º 2
0
 public boolean onContextItemSelected(MenuItem item) {
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
   switch (item.getItemId()) {
     case ADD_STEP:
       selectedStep = preset.blankStep();
       preset.steps.add(info.position + 1, selectedStep);
       modifiedStep = selectedStep.clone();
       showDialog(EDIT_STEP);
       return true;
     case DUP_STEP:
       selectedStep = preset.steps.get(info.position).clone();
       selectedStep.name = selectedStep.name + " copy";
       preset.steps.add(info.position + 1, selectedStep);
       modifiedStep = selectedStep.clone();
       showDialog(EDIT_STEP);
       return true;
     case UP_STEP:
       Collections.swap(preset.steps, info.position, info.position - 1);
       adapter.notifyDataSetChanged();
       return true;
     case DOWN_STEP:
       Collections.swap(preset.steps, info.position, info.position + 1);
       adapter.notifyDataSetChanged();
       return true;
     case DEL_STEP: // Unreachable right now.
       preset.steps.remove(preset.steps.get(info.position));
       adapter.notifyDataSetChanged();
       return true;
     default:
       return super.onContextItemSelected(item);
   }
 }
Ejemplo n.º 3
0
 @Override
 public synchronized void swapRows(final int a, final int b) {
   ensureChangeAllowed();
   Collections.swap(matrix, a, b);
   Collections.swap(heights, a, b);
   Collections.swap(rowNames, a, b);
 }
Ejemplo n.º 4
0
 private void permute(
     ArrayList<State> list, int left, int right, ArrayList<ArrayList<State>> permutations) {
   if (left == right) { // In case no element is left add to permutation list
     permutations.add(new ArrayList<State>(list));
   } else {
     for (int index = left; index <= right; index++) {
       Collections.swap(list, left, index);
       permute(list, left + 1, right, permutations);
       Collections.swap(list, left, index);
     }
   }
 }
Ejemplo n.º 5
0
  /*
   * 移动Item
   * */
  public void moveItem(int fromPosition, int toPosition) {
    // 数据的交换
    if (fromPosition < toPosition) {
      for (int index = fromPosition; index < toPosition; index++)
        Collections.swap(mContentInfoList, index, index + 1);
    } else {
      for (int index = fromPosition; index > toPosition; index--) {
        Collections.swap(mContentInfoList, index, index - 1);
      }
    }

    notifyItemMoved(fromPosition, toPosition);
  }
Ejemplo n.º 6
0
 private void moveTab(UITabContainer container, String childId, boolean isToLeft) {
   UIComponent selectedChild = container.getChildById(childId);
   List<UIComponent> children = container.getChildren();
   int selectedIndex = children.indexOf(selectedChild);
   if (isToLeft) {
     if (selectedIndex > 0) {
       Collections.swap(children, selectedIndex, selectedIndex - 1);
     }
   } else {
     if (selectedIndex < children.size() - 1) {
       Collections.swap(children, selectedIndex, selectedIndex + 1);
     }
   }
 }
Ejemplo n.º 7
0
 static boolean permuteSubtractions(int solution, List<Integer> arr, int k) {
   for (int i = k; i < arr.size(); i++) {
     java.util.Collections.swap(arr, i, k);
     if (permuteSubtractions(solution, arr, k + 1)) {
       return true;
     }
     java.util.Collections.swap(arr, k, i);
   }
   if (k == arr.size() - 1) {
     if (subtract(arr, solution)) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 8
0
  public void sort(List<Integer> array) {
    sum += array.size() - 1;
    if (array.size() == 1) return;

    // @BeforeRecursion
    Integer p = PIVOT_.choose(array);
    Collections.swap(array, 0, p);
    Integer i = PARTIONER_.partition(array, 0);

    // Если левая часть не пуста
    if (i != 0) {
      // Проверить инвариант
      /*Integer minLeft = Collections.max(array.subList(0, i));
      if (!(minLeft < array.get(i)))
        throw new RuntimeException("Left postcondition failed"); */
      sort(array.subList(0, i));
    }

    // Если правая не пуста
    if (i != array.size() - 1) {
      /*Integer minRight = Collections.min(array.subList(i+1, array.size()));

      if (!(minRight > array.get(i)))
        throw new RuntimeException("Right postcondition failed."); */
      sort(array.subList(i + 1, array.size()));
    }
  }
Ejemplo n.º 9
0
  /**
   * Checks what npc in the array should be attacked.
   *
   * <p>Does canReach and isInCombat checks as well.
   *
   * @param npcs
   * @return the npc to attack, or null if input array was null.
   */
  public static RSNPC[] orderOfAttack(RSNPC[] npcs) {

    if (npcs.length > 0) {

      npcs = NPCs.sortByDistance(Player.getPosition(), npcs);

      List<RSNPC> orderedNPCs = new ArrayList<RSNPC>();

      for (RSNPC npc : npcs) {

        if (npc.isInCombat() || !npc.isValid() || !MovementMgr.canReach(npc)) continue;

        orderedNPCs.add(npc);
      }

      if (orderedNPCs.size() > 1) {

        if (getUtil().BOOL_TRACKER.USE_CLOSEST.next()) {

          // if the 2nd closest npc is within 3 tiles of the closest npc, attack the 2nd one first.
          if (orderedNPCs.get(0).getPosition().distanceTo(orderedNPCs.get(1)) <= 3)
            Collections.swap(orderedNPCs, 0, 1);
        }

        getUtil().BOOL_TRACKER.USE_CLOSEST.reset();
      }

      return orderedNPCs.toArray(new RSNPC[orderedNPCs.size()]);
    }

    return null;
  }
Ejemplo n.º 10
0
  /**
   * Re-orders a slide, to a new position.
   *
   * @param oldSlideNumber The old slide number (1 based)
   * @param newSlideNumber The new slide number (1 based)
   */
  public void reorderSlide(int oldSlideNumber, int newSlideNumber) {
    // Ensure these numbers are valid
    if (oldSlideNumber < 1 || newSlideNumber < 1) {
      throw new IllegalArgumentException("Old and new slide numbers must be greater than 0");
    }
    if (oldSlideNumber > _slides.size() || newSlideNumber > _slides.size()) {
      throw new IllegalArgumentException(
          "Old and new slide numbers must not exceed the number of slides ("
              + _slides.size()
              + ")");
    }

    // The order of slides is defined by the order of slide atom sets in the
    // SlideListWithText container.
    SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
    SlideAtomsSet[] sas = slwt.getSlideAtomsSets();

    SlideAtomsSet tmp = sas[oldSlideNumber - 1];
    sas[oldSlideNumber - 1] = sas[newSlideNumber - 1];
    sas[newSlideNumber - 1] = tmp;

    Collections.swap(_slides, oldSlideNumber - 1, newSlideNumber - 1);
    _slides.get(newSlideNumber - 1).setSlideNumber(newSlideNumber);
    _slides.get(oldSlideNumber - 1).setSlideNumber(oldSlideNumber);

    ArrayList<Record> lst = new ArrayList<Record>();
    for (SlideAtomsSet s : sas) {
      lst.add(s.getSlidePersistAtom());
      lst.addAll(Arrays.asList(s.getSlideRecords()));
    }

    Record[] r = lst.toArray(new Record[lst.size()]);
    slwt.setChildRecord(r);
  }
Ejemplo n.º 11
0
    void calculateNextPermutation() {
      j = list.size() - 1;
      int s = 0;

      // Handle the special case of an empty list. Skip the calculation of the
      // next permutation.
      if (j == -1) {
        return;
      }

      while (true) {
        int q = c[j] + o[j];
        if (q < 0) {
          switchDirection();
          continue;
        }
        if (q == j + 1) {
          if (j == 0) {
            break;
          }
          s++;
          switchDirection();
          continue;
        }

        Collections.swap(list, j - c[j] + s, j - q + s);
        c[j] = q;
        break;
      }
    }
  @Override
  public boolean onItemMove(int fromPosition, int toPosition) {
    changed = true;

    if (fromPosition < toPosition) {
      for (int i = fromPosition; i < toPosition; i++) {
        Collections.swap(people, i, i + 1);
      }
    } else {
      for (int i = fromPosition; i > toPosition; i--) {
        Collections.swap(people, i, i - 1);
      }
    }
    notifyItemMoved(fromPosition, toPosition);
    return true;
  }
 @Override
 public boolean itemTouchOnMove(int oldPosition, int newPosition) {
   Collections.swap(
       fastItemAdapter.getAdapterItems(), oldPosition, newPosition); // change position
   fastItemAdapter.notifyAdapterItemMoved(oldPosition, newPosition);
   return true;
 }
Ejemplo n.º 14
0
 /**
  * Moves a pile the user selects over 2 piles
  *
  * @param cardSelected The card to be moved
  * @param isAI Whether the AI called the function or not
  * @param isLegal Whether the move is legal or not
  */
 private void movePileTwoPlacesLeft(int cardSelected, boolean isAI, boolean isLegal) {
   int selectedCard = cardSelected - 1;
   int movePlace = selectedCard - 3;
   if (cardStrings.size() > 3 && selectedCard > 2 && selectedCard < cardStrings.size()) {
     if (!isAI) { // If the AI is calling this function, isLegal has already been decided, so
       // shouldn't be changed
       isLegal = false;
     }
     if (!isAI) {
       isLegal = piles.movePileTwoPlacesLeft(isLegal, selectedCard, moveMade);
     }
     if (isLegal) { // If the move can be made
       String cardToMove = cardStrings.get(selectedCard); // Get the pile you want to move
       int moveTarget = movePlace;
       while (cardStrings.indexOf(cardToMove)
           != moveTarget) { // while the pile isn't in the correct new position
         int i = cardStrings.indexOf(cardToMove);
         Collections.swap(cardStrings, i, i - 1); // Swap the pile with the one next to it
       }
       int index = cardStrings.indexOf(cardToMove) + 1; // Get the index of the pile being removed
       String cardToDelete = cardStrings.get(index); // Get the pile in that index
       cardStrings.remove(cardToDelete); // Remove the pile the pile was placed onto
       saveLog();
     }
     printFrame();
   } else {
     if (!isAI) {
       System.out.println("There is no pile to move the selected pile onto");
     }
   }
 }
Ejemplo n.º 15
0
  /**
   * Déplacer un élément vers le bas
   *
   * @param row indice de l'élément à déplacer vers le bas
   * @return déplacement effectué ?
   */
  public boolean moveDown(int row) {
    if (this.validateMove(row, +1)) {
      // Déplacer l'élément et la correspondance vers le bas
      Collections.swap(this.tsModifies, row, row + 1);
      Collections.swap(this.correspondances, row, row + 1);

      // Fires des listeners
      this.fireRowUpdated(row, this.tsModifies.get(row + 1), this.tsModifies.get(row));
      this.fireRowUpdated(row + 1, this.tsModifies.get(row), this.tsModifies.get(row + 1));

      // Le déplacement a bien été effectué
      return true;
    }

    // Le déplacement n'a pas été effectué
    return false;
  }
Ejemplo n.º 16
0
  public List<BoardItem> moveWorkItem(int fromPosition, int toPosition) {
    if (isPositionOutOfRange(fromPosition) || isPositionOutOfRange(toPosition)) {
      throw new ArrayIndexOutOfBoundsException();
    }
    Collections.swap(boardItems, fromPosition - 1, toPosition - 1);

    return boardItems;
  }
 private void swapElements(List<? extends FOXTreeNode> nodeList, List<Integer> indices) {
   for (int i = 0; i < indices.size(); i++) {
     int index = indices.get(i);
     if (index >= 1) {
       Collections.swap(nodeList, index, index - 1);
     }
   }
 }
Ejemplo n.º 18
0
  /**
   * Déplacer un élément vers le haut
   *
   * @param row indice de l'élément à déplacer vers le haut
   * @return déplacement effectué ?
   */
  public boolean moveUp(int row) {
    // Vérifier si les validateurs acceptent le déplacement
    if (this.validateMove(row, -1)) {
      // Déplacer l'élément et la correspondance vers le haut
      Collections.swap(this.tsModifies, row, row - 1);
      Collections.swap(this.correspondances, row, row - 1);

      // Fires des listeners
      this.fireRowUpdated(row, this.tsModifies.get(row - 1), this.tsModifies.get(row));
      this.fireRowUpdated(row - 1, this.tsModifies.get(row), this.tsModifies.get(row - 1));

      // Le déplacement a bien été effectué
      return true;
    }

    // Le déplacement n'a pas été effectué
    return false;
  }
Ejemplo n.º 19
0
  /**
   * @param seed the random seed
   * @param training the training data
   */
  public TrainingGenerator(long seed, Collection<String> training) {

    this.names = Lists.newArrayList(training);
    Random random = new FastRandom(seed);

    for (int i = names.size(); i > 1; i--) {
      Collections.swap(names, i - 1, random.nextInt(i));
    }
  }
Ejemplo n.º 20
0
 static boolean permuteDivision(int solution, List<Integer> arr, int k) {
   for (int i = k; i < arr.size(); i++) {
     java.util.Collections.swap(arr, i, k);
     if (permuteDivision(solution, arr, k + 1)) {
       Log.d(DIV, "returning true 1");
       return true;
     }
     java.util.Collections.swap(arr, k, i);
   }
   if (k == arr.size() - 1) {
     if (divide(arr, solution)) {
       Log.d(DIV, "returning true 2");
       return true;
     }
   }
   Log.d(DIV, "returning false 3");
   return false;
 }
Ejemplo n.º 21
0
 public void setDeckWithSpecificTopCard(String topCardText) {
   deck = new Deck(true);
   for (Card card : deck.getCards()) {
     if (card.getCardText().equals(topCardText)) {
       Collections.swap(deck.getCards(), 0, deck.getCards().indexOf(card));
       break;
     }
   }
 }
Ejemplo n.º 22
0
  /**
   * Swaps the order of the two annotation sets. The two annotation sets must be distinct and must
   * be contained in this network view set, otherwise this method does nothing.
   */
  public void swap(AnnotationSet first, AnnotationSet second) {
    int i1 = annotationSets.indexOf(first);
    int i2 = annotationSets.indexOf(second);

    if (i1 < 0 || i2 < 0 || i1 == i2) return;

    Collections.swap(annotationSets, i1, i2);
    parent.postEvent(new ModelEvents.NetworkViewSetChanged(this, Type.ANNOTATION_SET_ORDER));
  }
Ejemplo n.º 23
0
  public static void swapTwoElementsInArrayList() {

    List<Pessoa> pessoas5 = new ArrayList<>();
    pessoas5.add(new Pessoa("Lindomar", LocalDate.of(1973, 1, 1)));
    pessoas5.add(new Pessoa("Alonso", LocalDate.of(1989, 9, 1)));
    pessoas5.add(new Pessoa("Jamerson", LocalDate.of(1981, 1, 2)));

    Collections.swap(pessoas5, 1, 2);
  }
Ejemplo n.º 24
0
  public void refresh() {
    // Update this track piece based on environment
    this.neighbours.clear();
    this.genNeighbours(true);

    System.out.println("Refreshing: " + this.toString());

    if (this.neighbours.size() == 1) {
      // align tracks straight to face this direction
      MinecartTrackLogic to = this.neighbours.get(0);
      this.connect(to, null);
      to.connect();
    } else if (this.neighbours.size() == 2 || this.neighbours.size() == 4) {
      // try to make a fixed curve
      MinecartTrackLogic r1 = this.neighbours.get(0);
      MinecartTrackLogic r2 = this.neighbours.get(1);
      this.connect(r1, r2);
      r1.connect();
      r2.connect();
    } else if (this.neighbours.size() == 3) {
      // sort neighbours: middle at index 1
      BlockFace middle = this.neighbours.get(1).direction.getOpposite();
      if (middle == this.neighbours.get(2).direction) {
        // dirs[1] need to be swapped with dirs[2]
        Collections.swap(this.neighbours, 1, 2);
      } else if (middle == this.neighbours.get(0).direction) {
        // dirs[1] need to be swapped with dirs[0]
        Collections.swap(this.neighbours, 1, 0);
      }

      // this will ALWAYS be a curve leading to [1]
      // pick [0] or [2]?
      MinecartTrackLogic from = this.neighbours.get(1);
      MinecartTrackLogic to;
      if (this.isPowered) {
        to = this.neighbours.get(0);
      } else {
        to = this.neighbours.get(2);
      }
      this.connect(from, to);
      from.connect();
      to.connect();
    }
  }
Ejemplo n.º 25
0
Archivo: Deck.java Proyecto: quendi/svn
  private void shuffleTiles(int start, int end, int repeat) {
    int one;
    int two;

    for (int i = 0; i < repeat; i++) {
      one = (generator.nextInt(end - start + 1)) + start;
      two = (generator.nextInt(end - start + 1)) + start;
      Collections.swap(tiles, one, two);
    }
  }
Ejemplo n.º 26
0
 @Override
 public void onSubmit() {
   final List list = getListView().getList();
   final int index = item.getIndex();
   if (index != -1) {
     getListView().modelChanging();
     Collections.swap(list, index, index + 1);
     getListView().modelChanged();
   }
 }
Ejemplo n.º 27
0
  @Override
  public void onMoveDownVocabulary(VocabularyDto vocabularyDto) {
    List<VocabularyDto> vocabularies = JsArrays.toList(taxonomy.getVocabulariesArray());
    int idx = vocabularies.indexOf(vocabularyDto);

    if (idx > -1 && idx < vocabularies.size() - 1) {
      Collections.swap(vocabularies, idx, idx + 1);
      getView().setDirty(true);
      getView().setTaxonomy(taxonomy);
    }
  }
Ejemplo n.º 28
0
 private void bubbleUpLastElement() {
   int i = items.size() - 1;
   T item = items.get(i);
   T parent = items.get((i - 1) / 2);
   while (i != 0 && parent.compareTo(item) == 1) {
     Collections.swap(items, i, (i - 1) / 2);
     i = (i - 1) / 2;
     item = items.get(i);
     parent = items.get((i - 1) / 2);
   }
 }
Ejemplo n.º 29
0
    public void moveDown(int pos) {
      JComponent comp = valueComponents.get(pos);
      Collections.swap(valueComponents, pos, pos + 1);

      remove(comp);
      add(comp, pos + 2);

      updatePositions();
      setStatus(StatusFlag.Update);

      revalidate();
    }
Ejemplo n.º 30
0
  public static void main(String[] args) {
    ArrayList arrayList = new ArrayList();
    arrayList.add("element_1");
    arrayList.add("element_2");
    arrayList.add("element_3");
    arrayList.add("element_4");
    arrayList.add("element_5");
    System.out.println("ArrayList elements : " + arrayList);

    Collections.swap(arrayList, 1, 3);
    System.out.println("ArrayList elements after swapping : " + arrayList);
  }