/** 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));
 }
Ejemplo n.º 2
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);
    }
  }
  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()));
  }
Ejemplo n.º 4
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);
  }
Ejemplo n.º 5
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)");
  }
Ejemplo n.º 6
0
  public int lastIndexOf(Object arg0) {

    return list.lastIndexOf(arg0);
  }
 public int lastIndexOf(Object o) {
   return documents.lastIndexOf(o);
 }
Ejemplo n.º 8
0
 public int lastIndexOf(Object o) {
   return page.lastIndexOf(o);
 }
Ejemplo n.º 9
0
 public int lastIndexOf(Object o) {
   return _delegate.lastIndexOf(o);
 }
Ejemplo n.º 10
0
 @Override
 public int lastIndexOf(Object o) {
   return verts.lastIndexOf(o);
 }
  public void run() {
    System.out.println("markov 0");
    // Get the number of students who visit each node.
    List<Trajectory> trajectories = TrajectoryLoader.load(TRAJECTORY_DIR);
    System.out.println("next");
    Map<String, Integer> nodeCount = new HashMap<String, Integer>();
    for (Trajectory t : trajectories) {
      List<String> visited = t.getProgramIds();
      List<String> noCycle = new ArrayList<String>();
      for (int i = 0; i < visited.size(); i++) {
        String state = visited.get(i);
        noCycle.add(state);
        int lastIndex = visited.lastIndexOf(state);
        i = lastIndex;
      }

      for (String v : noCycle) {
        if (!nodeCount.containsKey(v)) {
          nodeCount.put(v, 0);
        }
        int newCount = nodeCount.get(v) + t.getCount();
        nodeCount.put(v, newCount);
      }
    }
    double sumCount = 0.0;
    for (String s : nodeCount.keySet()) {
      sumCount += nodeCount.get(s);
    }
    roadMap = GraphLoader.loadRoadMap();
    groundTruth = GraphLoader.loadGroundTruth();

    // Make a graph where each edge has cost = coherence of the next node
    System.out.println("make coherenceCost");
    DirectedGraph<String> coherenceCost = new DirectedGraph<String>();
    for (String node : roadMap.vertexSet()) {
      double count = EPSILON;
      if (nodeCount.containsKey(node)) {
        count = nodeCount.get(node);
      }

      for (String previous : roadMap.getIncoming(node)) {

        double cost = -Math.log(count / sumCount);

        coherenceCost.addEdge(previous, node, cost);
      }
    }

    // Turn it all into a prediction
    System.out.println("predict");
    DirectedGraph<String> bestNext = new DirectedGraph<String>();
    String soln = "0";

    for (String node : groundTruth.vertexSet()) {
      if (node.equals(soln)) continue;
      if (groundTruth.getOutgoing(node).size() == 0) continue;

      List<Edge<String>> path = coherenceCost.getShortestPath(node, soln);
      if (path != null) {

        Edge<String> firstEdge = path.get(0);
        String next = firstEdge.getTarget();
        bestNext.addEdge(node, next);
      }
    }

    System.out.println("connected: " + roadMap.getInConnected("0").size());
    System.out.println("node count size: " + nodeCount.size());
    System.out.println("best next size: " + bestNext.vertexSet().size());

    DirectedGraph<String> toSave = new DirectedGraph<String>();

    for (int i = 0; i < 1000; i++) {
      String node = "" + i;
      if (!bestNext.containsVertex(node)) continue;
      String next = null;
      for (String s : bestNext.getOutgoing(node)) {
        next = s;
        break;
      }
      if (next != null) {
        toSave.addEdge(node, next);
      }
    }

    GraphLoader.savePolicy(toSave, OUTPUT_FILE);

    System.out.println("done");
  }