Exemplo n.º 1
1
    public static void storeThis(Activity activity, int numOfInstance) {
      int num = 0;
      int size = activityList.size();
      for (int i = 0; i < size; i++) {
        Activity _activity = activityList.get(i);
        if (_activity.getClass() == activity.getClass()) {
          num++;
        }
      }

      if (num > numOfInstance) {
        int toDelete = num - numOfInstance;
        int lastIndex = activityList.lastIndexOf(activity);
        for (int i = lastIndex - 1; i >= 0; i--) {
          Activity _activity = activityList.get(i);
          if (_activity.getClass() == activity.getClass()) {
            try {
              if (toDelete > 0) {
                activityList.remove(i).finish();
                toDelete--;
              }
            } catch (Exception e) {
            }
          }
        }
      }
    }
 /** lastIndexOf returns the index for the given object */
 public void testLastIndexOf1() {
   List full = populatedArray(3);
   full.add(one);
   full.add(three);
   assertEquals(3, full.lastIndexOf(one));
   assertEquals(-1, full.lastIndexOf(six));
 }
 @Override
 public int lastIndexOf(final Object arg0) {
   if (arg0 instanceof Item) {
     return itemNames_.lastIndexOf(((Item) arg0).getName());
   } else if (arg0 instanceof String) {
     return itemNames_.lastIndexOf(arg0);
   }
   return -1;
 }
Exemplo n.º 4
0
 /** @tests java.util.ArrayList#lastIndexOf(java.lang.Object) */
 public void test_lastIndexOfLjava_lang_Object() {
   // Test for method int java.util.ArrayList.lastIndexOf(java.lang.Object)
   alist.add(new Integer(99));
   assertEquals("Returned incorrect index", 100, alist.lastIndexOf(objArray[99]));
   assertEquals("Returned index for invalid Object", -1, alist.lastIndexOf(new Object()));
   alist.add(25, null);
   alist.add(50, null);
   assertTrue(
       "Wrong lastIndexOf for null.  Wanted 50 got: " + alist.lastIndexOf(null),
       alist.lastIndexOf(null) == 50);
 }
Exemplo n.º 5
0
 @Override
 public void moveLayer(com.metaaps.eoclipse.common.views.ILayer layer, boolean up) {
   List<ILayer> layers = root.getLayers();
   layers.lastIndexOf(layer);
   int curindex = layers.lastIndexOf(layer);
   if (curindex > 0) {
     layers.remove(curindex);
     if (curindex + 1 < layers.size()) {
       layers.add(curindex + 1, (ILayer) layer);
     } else {
       layers.add((ILayer) layer);
     }
   }
 }
Exemplo n.º 6
0
  // TODO make this work or remove before publishing
  // commonElement = position of element to be maintained
  public void animatedUpdateDataset(List<String> dataset, int commonElementPosition) {
    if (commonElementPosition == -1) {
      updateDataset(dataset);
      return;
    }

    int datasetSize = dataset.size();
    String commonElement = "";
    ArrayList<String> removeItems = new ArrayList<String>();

    // Find common element in new dataset
    mPositionInDataset = dataset.lastIndexOf(mDataset.get(commonElementPosition));
    commonElement = mDataset.get(commonElementPosition);

    // Add everything except common element to a new list to be removed later
    Iterator<String> iterator = mDataset.iterator();
    while (iterator.hasNext()) {
      String item = iterator.next();
      if (!item.equals(commonElement)) {
        removeItems.add(item);
      }
    }

    // Remove everything from newly populated list from mDataset
    iterator = removeItems.iterator();
    while (iterator.hasNext()) {
      int i = mDataset.lastIndexOf(iterator.next());
      removeItem(i);
    }

    if (mPositionInDataset != -1) {
      // Add new elements
      for (int i = 0; i < datasetSize; i++) {
        if (i < mPositionInDataset) {
          addItem(dataset.get(i), mDataset.size() - 1); // Add item before common element
        } else if (i > mPositionInDataset) {
          addItem(dataset.get(i)); // Add item to end
        } else {
          // item is the common element
          notifyItemChanged(i);
        }
      }
    } else {
      Log.d(TAG, "Element not found. Updating mDataset vanilla style.");
      mDataset = dataset;
      notifyDataSetChanged();
    }
  }
Exemplo n.º 7
0
 public static void basicTest(List a) {
   a.add(1, "x"); // Add at location 1
   a.add("x"); // Add at end
   // Add a collection:
   a.addAll(fill(new ArrayList()));
   // Add a collection starting at  location 3:
   a.addAll(3, fill(new ArrayList()));
   b = a.contains("1");
   // Is it in there
   // Is the entire collection in there?
   b = a.containsAll(fill(new ArrayList()));
   // Lists allow random access, which is cheap for ArrayList, expensive for LinkedList:
   o = a.get(1); // Get object at location 1
   i = a.indexOf("1");
   // Tell index of object  indexOf, starting search at location 2: i = a.indexOf("1", 2);
   b = a.isEmpty(); // Any elements inside?
   it = a.iterator(); // Ordinary Iterator
   lit = a.listIterator(); // ListIterator
   lit = a.listIterator(3); // Start at loc 3
   i = a.lastIndexOf("1"); // Last match
   // i = a.lastIndexOf("1", 2); // ...after loc 2
   a.remove(1); // Remove location 1
   a.remove("3"); // Remove this object
   a.set(1, "y"); // Set location 1 to "y" // Keep everything that's in the
   // argument // (the intersection of the two sets):
   a.retainAll(fill(new ArrayList())); // Remove elements in this range:
   // a.removeRange(0, 2); // Remove everything that's in the argument:
   a.removeAll(fill(new ArrayList()));
   i = a.size(); // How big is it?
   a.clear(); // Remove all elements
 }
Exemplo n.º 8
0
  /**
   * Encode the CertPath using PKIPATH format.
   *
   * @return a byte array containing the binary encoding of the PkiPath object
   * @exception CertificateEncodingException if an exception occurs
   */
  private byte[] encodePKIPATH() throws CertificateEncodingException {

    ListIterator<X509Certificate> li = certs.listIterator(certs.size());
    try {
      DerOutputStream bytes = new DerOutputStream();
      // encode certs in reverse order (trust anchor to target)
      // according to PkiPath format
      while (li.hasPrevious()) {
        X509Certificate cert = li.previous();
        // check for duplicate cert
        if (certs.lastIndexOf(cert) != certs.indexOf(cert)) {
          throw new CertificateEncodingException("Duplicate Certificate");
        }
        // get encoded certificates
        byte[] encoded = cert.getEncoded();
        bytes.write(encoded);
      }

      // Wrap the data in a SEQUENCE
      DerOutputStream derout = new DerOutputStream();
      derout.write(DerValue.tag_SequenceOf, bytes);
      return derout.toByteArray();

    } catch (IOException ioe) {
      throw new CertificateEncodingException("IOException encoding " + "PkiPath data: " + ioe, ioe);
    }
  }
Exemplo n.º 9
0
 int indexOf(String name) {
   int index = table.get(name);
   if (index != -1 && name.equals(names.get(index))) {
     return index;
   }
   return names.lastIndexOf(name);
 }
Exemplo n.º 10
0
 /**
  * modeHelper Used to determine the mode of a list of Blocks
  *
  * @param brickList, a list of Blocks to be analyzed
  * @param key, a long describing the key
  * @return a String describing the mode
  */
 private static String modeHelper(List<Block> brickList, long key) {
   int ind = brickList.lastIndexOf(key);
   if (ind != -1) {
     return brickList.get(ind).getMode();
   } else {
     return brickList.get(brickList.size() - 1).getMode();
   }
 }
Exemplo n.º 11
0
 private void checkForDups(List<Object> list) {
   for (int i = 0; i < list.size(); i++) {
     if (list.lastIndexOf(list.get(i)) != i) {
       System.err.println("We have a dup: " + list.get(i));
       list.remove(i);
       i--;
     }
   }
 }
Exemplo n.º 12
0
  protected void updateOnPageChange() {
    List<MappedBlockBean> blocks = mdfbean.getBlocks();
    if (blocks.isEmpty()) return;
    options = new String[blocks.size()];
    for (int i = 0; i < blocks.size(); i++) options[i] = blocks.get(i).getName();

    if (!mdfbean.getMaps().isEmpty()) {

      Iterator<MapBean> it = mdfbean.getMaps().iterator();

      List<String> l = Arrays.asList(options);

      while (it.hasNext()) {
        MapBean b = it.next();

        if (!datasetNames.containsKey(b.getName()) || !l.contains(b.getParent())) {
          it.remove();
          continue;
        }

        mapToParent.put(b.getName(), l.lastIndexOf(b.getParent()));

        for (Entry<String, int[]> entry : datasetNames.entrySet()) {
          if (entry.getKey().equals(b.getName())) {
            cviewer.setChecked(entry, true);
          }
        }
      }
    }

    validatePage();

    //		if (description != null && description.getBlockNames() != null){
    //			options = description.getBlockNames().toArray(new
    // String[description.getBlockNames().size()]);
    //
    //			if (description.getDataBlockToMapMapping() != null) {
    //				for (Entry<String, List<String>> e : description.getDataBlockToMapMapping().entrySet()) {
    //					if (datasetNames.containsKey(e.getKey())) {
    //
    //						for (String a : e.getValue()) {
    //							if (a != null && datasetNames.containsKey(a)) {
    //								int i = 0;
    //								for (;i< options.length; i++) if (e.getKey().equals(options[i])) break;
    //								mapToParent.put(a, i);
    //								for (Entry<String, int[]> ent : datasetNames.entrySet()) if (ent.getKey().equals(a))
    // cviewer.setChecked(ent, true);
    //							}
    //						}
    //
    //					}
    //				}
    //			}

    //		}
  }
Exemplo n.º 13
0
 @Override
 public int lastIndexOf(Object o) {
   int index = females.lastIndexOf(o);
   if (index == -1) {
     index = males.indexOf(o);
   } else {
     index += males.size();
   }
   return index;
 }
Exemplo n.º 14
0
  @Test
  public void callbackOrder() throws InterruptedException {
    final List<String> callbacks = new CopyOnWriteArrayList<String>();
    final CountDownLatch latch = new CountDownLatch(1);

    NuProcessHandler handler =
        new NuProcessHandler() {
          private NuProcess nuProcess;

          @Override
          public void onStdout(ByteBuffer buffer, boolean closed) {
            callbacks.add("stdout");
            nuProcess.closeStdin();
          }

          @Override
          public boolean onStdinReady(ByteBuffer buffer) {
            callbacks.add("stdin");
            buffer.put("foobar".getBytes()).flip();
            return false;
          }

          @Override
          public void onStderr(ByteBuffer buffer, boolean closed) {
            callbacks.add("stderr");
          }

          @Override
          public void onStart(NuProcess nuProcess) {
            callbacks.add("start");
            this.nuProcess = nuProcess;
            nuProcess.wantWrite();
          }

          @Override
          public void onPreStart(NuProcess nuProcess) {
            callbacks.add("prestart");
          }

          @Override
          public void onExit(int exitCode) {
            callbacks.add("exit");
            latch.countDown();
          }
        };

    Assert.assertNotNull("process is null", new NuProcessBuilder(handler, command).start());
    latch.await();

    Assert.assertEquals("onPreStart was not called first", 0, callbacks.indexOf("prestart"));
    Assert.assertFalse(
        "onExit was called before onStdout",
        callbacks.indexOf("exit") < callbacks.lastIndexOf("stdout"));
  }
Exemplo n.º 15
0
  @Override
  public ItemStack onRightClick() {
    int ind = options.lastIndexOf(value.getValue());
    ind--;
    if (ind == -1) ind = options.size() - 1;

    value.setValue(options.get(ind));
    updateDescription();

    return getItem();
  }
Exemplo n.º 16
0
 /**
  * Adds a new tracing statistic to a trace
  *
  * @param tracingStatistic to enable a run
  * @return The index of this statistic (for use with stat.extraInfo()), or -1 if the statistic is
  *     not enabled.
  */
 static int addTracingStatistic(TracingStatistic tracingStatistic) {
   // Check to see if we can enable the tracing statistic before actually
   // adding it.
   if (tracingStatistic.enable()) {
     // No synchronization needed, since this is a copy-on-write array.
     extraTracingStatistics.add(tracingStatistic);
     // 99.9% of the time, this will be O(1) and return
     // extraTracingStatistics.length - 1
     return extraTracingStatistics.lastIndexOf(tracingStatistic);
   } else {
     return -1;
   }
 }
Exemplo n.º 17
0
  private List<OntClass> OntClassInheritanceChain(List<OntClass> _subClasses) {

    List<OntClass> removeSubClasses = new ArrayList<OntClass>();

    for (OntClass jenaClass : _subClasses) {
      List<OntClass> subClassCopy = jenaClass.listSubClasses().toList();
      for (OntClass subClass : subClassCopy) {
        if (_subClasses.contains(subClass)) {
          if (!removeSubClasses.contains(subClass)) removeSubClasses.add(subClass);
        }
      }
    }

    for (OntClass subClass : removeSubClasses)
      _subClasses.remove(_subClasses.lastIndexOf(subClass));

    return _subClasses;
  }
Exemplo n.º 18
0
    /**
     * Methods that takes care of pruning and adding an action to the dynamic action list.
     *
     * <pre>
     *  If you add a component and the dynamic action list does not contain
     *  the component yet then add it to the dynamic action list, regardless
     *  whether or not if was an ADD or REMOVE.
     * </pre>
     *
     * <pre>
     *  Else if you add a component and it is already in the dynamic action
     *  list and it is the only action for that client id in the dynamic
     *  action list then:
     *   1) If the previous action was an ADD then
     *      a) If the current action is a REMOVE then remove the component
     *         out of the dynamic action list.
     *      b) If the current action is an ADD then throw a FacesException.
     *   2) If the previous action was a REMOVE then
     *      a) If the current action is an ADD then add it to the dynamic
     *         action list.
     *      b) If the current action is a REMOVE then throw a FacesException.
     * </pre>
     *
     * <pre>
     *  Else if a REMOVE and ADD where captured before then:
     *   1) If the current action is REMOVE then remove the last dynamic
     *      action out of the dynamic action list.
     *   2) If the current action is ADD then throw a FacesException.
     * </pre>
     *
     * @param component the UI component.
     * @param struct the dynamic action.
     */
    private void handleAddRemoveWithAutoPrune(UIComponent component, ComponentStruct struct) {

      List<ComponentStruct> actionList = getDynamicActions();
      HashMap<String, UIComponent> componentMap = getDynamicComponents();

      int firstIndex = actionList.indexOf(struct);
      if (firstIndex == -1) {
        actionList.add(struct);
        componentMap.put(struct.clientId, component);
      } else {
        int lastIndex = actionList.lastIndexOf(struct);
        if (lastIndex == firstIndex) {
          ComponentStruct previousStruct = actionList.get(firstIndex);
          if (ComponentStruct.ADD.equals(previousStruct.action)) {
            if (ComponentStruct.ADD.equals(struct.action)) {
              throw new FacesException("Cannot add the same component twice: " + struct.clientId);
            }
            if (ComponentStruct.REMOVE.equals(struct.action)) {
              actionList.remove(firstIndex);
              componentMap.remove(struct.clientId);
            }
          }
          if (ComponentStruct.REMOVE.equals(previousStruct.action)) {
            if (ComponentStruct.ADD.equals(struct.action)) {
              actionList.add(struct);
              componentMap.put(struct.clientId, component);
            }
            if (ComponentStruct.REMOVE.equals(struct.action)) {
              throw new FacesException(
                  "Cannot remove the same component twice: " + struct.clientId);
            }
          }
        } else {
          if (ComponentStruct.ADD.equals(struct.action)) {
            throw new FacesException("Cannot add the same component twice: " + struct.clientId);
          }
          if (ComponentStruct.REMOVE.equals(struct.action)) {
            actionList.remove(lastIndex);
          }
        }
      }
    }
  private void loadBondedParams() {
    String fileName = "res/amber03/ffbonded.itp";
    List<String> fileAsList = FileReader.readFile(fileName);
    int bondtypes = fileAsList.indexOf("[ bondtypes ]");
    int constrainttypes = fileAsList.indexOf("[ constrainttypes ]");
    int angletypes = fileAsList.indexOf("[ angletypes ]");
    int improperDihedral = fileAsList.indexOf("[ dihedraltypes ]");
    int properDihedral = fileAsList.lastIndexOf("[ dihedraltypes ]");

    //		System.out.println(bondtypes);
    //		System.out.println(constrainttypes);
    //		System.out.println(angletypes);
    //		System.out.println(improperDihedral);
    //		System.out.println(properDihedral);

    loadBondParams(fileAsList.subList(bondtypes + 1, constrainttypes));
    loadAngleParams(fileAsList.subList(angletypes + 1, improperDihedral));
    loadImproperDihedralParams(fileAsList.subList(improperDihedral + 1, properDihedral));
    loadProperDihedralParams(fileAsList.subList(properDihedral + 1, fileAsList.size()));
  }
Exemplo n.º 20
0
  /** @return - found path, in reverse, without the loops. */
  public List<Edge> findWayBackWithoutLoops() {
    List<Edge> noLoopList = new ArrayList<Edge>();

    for (int i = 0; i < pathList.size(); i++) {
      Edge next = pathList.get(i);
      Node from = next.getFrom();
      for (int j = pathList.size() - 1; j >= 0; j--) {
        Edge last = pathList.get(j);
        Node lastfrom = last.getFrom();
        if (from == lastfrom) {
          i = j;
          next = last;
          break;
        }
      }
      noLoopList.add(next);
      i = pathList.lastIndexOf(next);
    }
    return noLoopList;
  }
Exemplo n.º 21
0
  /**
   * Replaces an SsaInsn containing a PlainInsn with a new PlainInsn. The new PlainInsn is
   * constructed with a new RegOp and new sources.
   *
   * <p>TODO move this somewhere else.
   *
   * @param insn {@code non-null;} an SsaInsn containing a PlainInsn
   * @param newSources {@code non-null;} new sources list for new insn
   * @param newOpcode A RegOp from {@link RegOps}
   * @param cst {@code null-ok;} constant for new instruction, if any
   */
  private void replacePlainInsn(
      NormalSsaInsn insn, RegisterSpecList newSources, int newOpcode, Constant cst) {

    Insn originalRopInsn = insn.getOriginalRopInsn();
    Rop newRop = Rops.ropFor(newOpcode, insn.getResult(), newSources, cst);
    Insn newRopInsn;
    if (cst == null) {
      newRopInsn =
          new PlainInsn(newRop, originalRopInsn.getPosition(), insn.getResult(), newSources);
    } else {
      newRopInsn =
          new PlainCstInsn(
              newRop, originalRopInsn.getPosition(), insn.getResult(), newSources, cst);
    }
    NormalSsaInsn newInsn = new NormalSsaInsn(newRopInsn, insn.getBlock());

    List<SsaInsn> insns = insn.getBlock().getInsns();

    ssaMeth.onInsnRemoved(insn);
    insns.set(insns.lastIndexOf(insn), newInsn);
    ssaMeth.onInsnAdded(newInsn);
  }
Exemplo n.º 22
0
  private void createPainToTree2(
      final DefaultTreeModel treeModel, DefaultMutableTreeNode root, Collection paintCollection) {
    ArrayList a = (ArrayList) paintCollection;
    DefaultMutableTreeNode parent = root;
    System.out.println("a = " + a.size());
    Iterator i = a.iterator();
    // Person lastPerson = null;
    while (i.hasNext()) {
      Person p = (Person) i.next();

      Object[] pathTree = {
        root, p.getFio().getLastName(), p.getFio().getMidllName(), p.getFio().getFirstName()
      };
      // int poz=Arrays.binarySearch(pathTree, parent.getUserObject());
      List l = Arrays.asList(pathTree);
      int poz = l.lastIndexOf(parent.getUserObject());
      while (poz > -1) { // bvtyf yt cjdgflf.n
        while (pathTree.length > poz) {
          DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(pathTree[poz + 1]);
          treeModel.insertNodeInto(newNode, parent, parent.getChildCount());
          parent = newNode;
          poz = Arrays.binarySearch(pathTree, parent.getUserObject());
        }
      }
      //   TreePath path = new TreePath(pathTree);
      //  TreeNode[] pa = parent.getPath();
      // Object[] o = parent.getUserObjectPath();
      // if (p.getFio().getFirstName() != (o[o.length - 1])) {

      //
      //                treeModel.insertNodeInto(
      //                        new DefaultMutableTreeNode(
      //                                path.getLastPathComponent()),
      //                        parent, parent.getChildCount());
      //   lastPerson = p;
      // }
    }
  }
Exemplo n.º 23
0
  /**
   * Reorder files.
   *
   * @param documentId Document ID
   * @param idList List of files ID in the new order
   * @return Response
   * @throws JSONException
   */
  @POST
  @Path("reorder")
  @Produces(MediaType.APPLICATION_JSON)
  public Response reorder(
      @FormParam("id") String documentId, @FormParam("order") List<String> idList)
      throws JSONException {
    if (!authenticate()) {
      throw new ForbiddenClientException();
    }

    // Validate input data
    ValidationUtil.validateRequired(documentId, "id");
    ValidationUtil.validateRequired(idList, "order");

    // Get the document
    DocumentDao documentDao = new DocumentDao();
    try {
      documentDao.getDocument(documentId, principal.getId());
    } catch (NoResultException e) {
      throw new ClientException(
          "DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
    }

    // Reorder files
    FileDao fileDao = new FileDao();
    for (File file : fileDao.getByDocumentId(documentId)) {
      int order = idList.lastIndexOf(file.getId());
      if (order != -1) {
        file.setOrder(order);
      }
    }

    // Always return ok
    JSONObject response = new JSONObject();
    response.put("status", "ok");
    return Response.ok().entity(response).build();
  }
Exemplo n.º 24
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    List list = (List) newInstance(Vector.class);
    Object value = "TEST";
    list.add(value);
    list.contains(value);
    try {
      list.set(2, "ArrayIndexOutOfBounds");
    } catch (ArrayIndexOutOfBoundsException ignore) {

    }
    list.add(value + "1");
    list.add(value + "2");
    list.toString();
    list.equals(list);
    list.set(0, null);
    list.toString();
    list.add(list);
    list.get(1);
    list.toArray();
    list.remove(list);
    list.remove("");
    list.containsAll(list);
    list.lastIndexOf(value);
  }
Exemplo n.º 25
0
 @Override
 public int lastIndexOf(Object o) {
   return internal.lastIndexOf(o);
 }
  public static List<String> adjustTrail(
      List<String> origTrail, String currentCategoryId, String previousCategoryId) {
    List<String> trail = FastList.newInstance();
    if (origTrail != null) {
      trail.addAll(origTrail);
    }

    // if no previous category was specified, check to see if currentCategory is in the list
    if (UtilValidate.isEmpty(previousCategoryId)) {
      if (trail.contains(currentCategoryId)) {
        // if cur category is in crumb, remove everything after it and return
        int cindex = trail.lastIndexOf(currentCategoryId);

        if (cindex < (trail.size() - 1)) {
          for (int i = trail.size() - 1; i > cindex; i--) {
            trail.remove(i);
            // FIXME can be removed ?
            // String deadCat = trail.remove(i);
            // if (Debug.infoOn()) Debug.logInfo("[CategoryWorker.setTrail] Removed after current
            // category index: " + i + " catname: " + deadCat, module);
          }
        }
        return trail;
      } else {
        // current category is not in the list, and no previous category was specified, go back to
        // the beginning
        trail.clear();
        trail.add("TOP");
        if (UtilValidate.isNotEmpty(previousCategoryId)) {
          trail.add(previousCategoryId);
        }
        // if (Debug.infoOn()) Debug.logInfo("[CategoryWorker.setTrail] Starting new list, added TOP
        // and previousCategory: " + previousCategoryId, module);
      }
    }

    if (!trail.contains(previousCategoryId)) {
      // previous category was NOT in the list, ERROR, start over
      // if (Debug.infoOn()) Debug.logInfo("[CategoryWorker.setTrail] previousCategory (" +
      // previousCategoryId + ") was not in the crumb list, position is lost, starting over with
      // TOP", module);
      trail.clear();
      trail.add("TOP");
      if (UtilValidate.isNotEmpty(previousCategoryId)) {
        trail.add(previousCategoryId);
      }
    } else {
      // remove all categories after the previous category, preparing for adding the current
      // category
      int index = trail.indexOf(previousCategoryId);
      if (index < (trail.size() - 1)) {
        for (int i = trail.size() - 1; i > index; i--) {
          trail.remove(i);
          // FIXME can be removed ?
          // String deadCat = trail.remove(i);
          // if (Debug.infoOn()) Debug.logInfo("[CategoryWorker.setTrail] Removed after current
          // category index: " + i + " catname: " + deadCat, module);
        }
      }
    }

    // add the current category to the end of the list
    trail.add(currentCategoryId);
    if (Debug.verboseOn())
      Debug.logVerbose(
          "[CategoryWorker.setTrail] Continuing list: Added currentCategory: " + currentCategoryId,
          module);

    return trail;
  }
Exemplo n.º 27
0
  public static void main(String[] args) {
    int numItr = 100;
    int listSize = 100;

    for (int i = 0; i < numItr; i++) {
      List s1 = newList();
      AddRandoms(s1, listSize);

      List s2 = newList();
      AddRandoms(s2, listSize);

      List intersection = clone(s1);
      intersection.retainAll(s2);
      List diff1 = clone(s1);
      diff1.removeAll(s2);
      List diff2 = clone(s2);
      diff2.removeAll(s1);
      List union = clone(s1);
      union.addAll(s2);

      if (diff1.removeAll(diff2)) fail("List algebra identity 2 failed");
      if (diff1.removeAll(intersection)) fail("List algebra identity 3 failed");
      if (diff2.removeAll(diff1)) fail("List algebra identity 4 failed");
      if (diff2.removeAll(intersection)) fail("List algebra identity 5 failed");
      if (intersection.removeAll(diff1)) fail("List algebra identity 6 failed");
      if (intersection.removeAll(diff1)) fail("List algebra identity 7 failed");

      intersection.addAll(diff1);
      intersection.addAll(diff2);
      if (!(intersection.containsAll(union) && union.containsAll(intersection)))
        fail("List algebra identity 1 failed");

      Iterator e = union.iterator();
      while (e.hasNext()) intersection.remove(e.next());
      if (!intersection.isEmpty()) fail("Copy nonempty after deleting all elements.");

      e = union.iterator();
      while (e.hasNext()) {
        Object o = e.next();
        if (!union.contains(o)) fail("List doesn't contain one of its elements.");
        e.remove();
      }
      if (!union.isEmpty()) fail("List nonempty after deleting all elements.");

      s1.clear();
      if (s1.size() != 0) fail("Clear didn't reduce size to zero.");

      s1.addAll(0, s2);
      if (!(s1.equals(s2) && s2.equals(s1))) fail("addAll(int, Collection) doesn't work.");
      // Reverse List
      for (int j = 0, n = s1.size(); j < n; j++) s1.set(j, s1.set(n - j - 1, s1.get(j)));
      // Reverse it again
      for (int j = 0, n = s1.size(); j < n; j++) s1.set(j, s1.set(n - j - 1, s1.get(j)));
      if (!(s1.equals(s2) && s2.equals(s1))) fail("set(int, Object) doesn't work");
    }

    List s = newList();
    for (int i = 0; i < listSize; i++) s.add(new Integer(i));
    if (s.size() != listSize) fail("Size of [0..n-1] != n");

    List even = clone(s);
    Iterator it = even.iterator();
    while (it.hasNext()) if (((Integer) it.next()).intValue() % 2 == 1) it.remove();
    it = even.iterator();
    while (it.hasNext())
      if (((Integer) it.next()).intValue() % 2 == 1) fail("Failed to remove all odd nubmers.");

    List odd = clone(s);
    for (int i = 0; i < (listSize / 2); i++) odd.remove(i);
    for (int i = 0; i < (listSize / 2); i++)
      if (((Integer) odd.get(i)).intValue() % 2 != 1) fail("Failed to remove all even nubmers.");

    List all = clone(odd);
    for (int i = 0; i < (listSize / 2); i++) all.add(2 * i, even.get(i));
    if (!all.equals(s)) fail("Failed to reconstruct ints from odds and evens.");

    all = clone(odd);
    ListIterator itAll = all.listIterator(all.size());
    ListIterator itEven = even.listIterator(even.size());
    while (itEven.hasPrevious()) {
      itAll.previous();
      itAll.add(itEven.previous());
      itAll.previous(); // ???
    }
    itAll = all.listIterator();
    while (itAll.hasNext()) {
      Integer i = (Integer) itAll.next();
      itAll.set(new Integer(i.intValue()));
    }
    itAll = all.listIterator();
    it = s.iterator();
    while (it.hasNext())
      if (it.next() == itAll.next()) fail("Iterator.set failed to change value.");
    if (!all.equals(s)) fail("Failed to reconstruct ints with ListIterator.");

    it = all.listIterator();
    int i = 0;
    while (it.hasNext()) {
      Object o = it.next();
      if (all.indexOf(o) != all.lastIndexOf(o)) fail("Apparent duplicate detected.");
      if (all.subList(i, all.size()).indexOf(o) != 0
          || all.subList(i + 1, all.size()).indexOf(o) != -1) fail("subList/indexOf is screwy.");
      if (all.subList(0, i + 1).lastIndexOf(o) != i) fail("subList/lastIndexOf is screwy.");
      i++;
    }

    List l = newList();
    AddRandoms(l, listSize);
    Integer[] ia = (Integer[]) l.toArray(new Integer[0]);
    if (!l.equals(Arrays.asList(ia))) fail("toArray(Object[]) is hosed (1)");
    ia = new Integer[listSize];
    Integer[] ib = (Integer[]) l.toArray(ia);
    if (ia != ib || !l.equals(Arrays.asList(ia))) fail("toArray(Object[]) is hosed (2)");
    ia = new Integer[listSize + 1];
    ia[listSize] = new Integer(69);
    ib = (Integer[]) l.toArray(ia);
    if (ia != ib || ia[listSize] != null || !l.equals(Arrays.asList(ia).subList(0, listSize)))
      fail("toArray(Object[]) is hosed (3)");
  }
Exemplo n.º 28
0
 public int lastIndexOf(Object o) {
   return items.lastIndexOf(o);
 }
Exemplo n.º 29
0
 /** @see java.util.List#lastIndexOf(java.lang.Object) */
 public synchronized int lastIndexOf(Object o) {
   return rows.lastIndexOf(o);
 }
Exemplo n.º 30
0
  public int lastIndexOf(Object arg0) {

    return list.lastIndexOf(arg0);
  }