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);
  }
Example #2
0
  @Test
  public final void testMyNodes() {
    Board b = TestAccessor.Game.getBoard(game);
    Node[] nodes = TestAccessor.Board.getNodes(b);

    // Set up board:
    nodes[0].setPlayer(aiPlayer);
    nodes[1].setPlayer(aiPlayer);
    nodes[2].setPlayer(aiPlayer);
    nodes[4].setPlayer(aiPlayer);
    nodes[5].setPlayer(aiPlayer);
    nodes[9].setPlayer(aiPlayer);
    nodes[11].setPlayer(aiPlayer);
    nodes[12].setPlayer(aiPlayer);
    nodes[18].setPlayer(aiPlayer);
    nodes[19].setPlayer(aiPlayer);
    nodes[22].setPlayer(aiPlayer);

    LinkedList<Node> mynodes = TestAccessor.AI.myNodes(ai);
    assertEquals(mynodes.size(), 11);
    assertTrue(mynodes.contains(nodes[0]));
    assertTrue(mynodes.contains(nodes[1]));
    assertTrue(mynodes.contains(nodes[2]));
    assertFalse(mynodes.contains(nodes[3]));
    assertTrue(mynodes.contains(nodes[4]));
    assertTrue(mynodes.contains(nodes[5]));
    assertFalse(mynodes.contains(nodes[6]));
  }
Example #3
0
  /**
   * Helper function: update the "old" RM group with the "next" group provided.
   *
   * @param old
   * @param next
   */
  private void updateRMGroup(LinkedList<MemberInfo> old, LinkedList<MemberInfo> next) {
    if (next == null || next.isEmpty()) {
      System.out.println("empty or null next MemberInfo sent in updated.");
      return;
    }

    // Add to our old list the memberInfo objects that were not previously there.
    for (MemberInfo m : next) {
      if (old == null) {
        System.out.println("OLD NULL");
      }

      if (m == null) {
        System.out.println("M NULL");
      }

      if (!old.contains(m)) {
        old.add(m);
      }
    }

    // Remove from our old list the memberInfo objects that are absent in next.
    LinkedList<MemberInfo> toRemove = new LinkedList<MemberInfo>();
    for (MemberInfo m : old) {
      if (!next.contains(m)) {
        toRemove.add(m);
      }
    }
    for (MemberInfo m : toRemove) {
      old.remove(m);
    }
  }
Example #4
0
 public static String[] minus(String[] arr1, String[] arr2) {
   LinkedList<String> list = new LinkedList<String>();
   LinkedList<String> history = new LinkedList<String>();
   String[] longerArr = arr1;
   String[] shorterArr = arr2;
   // 找出较长的数组来减较短的数组
   //        if (arr1.length > arr2.length) {
   //            longerArr = arr2;
   //            shorterArr = arr1;
   //        }
   for (String str : longerArr) {
     if (!list.contains(str)) {
       list.add(str);
     }
   }
   for (String str : shorterArr) {
     if (list.contains(str)) {
       history.add(str);
       list.remove(str);
     } else {
       if (!history.contains(str)) {
         list.add(str);
       }
     }
   }
   String[] result = {};
   return list.toArray(result);
 }
 public void testAdjacency10() {
   LinkedList testList = board.getAdjList(10);
   Assert.assertTrue(testList.contains(14));
   Assert.assertTrue(testList.contains(11));
   Assert.assertTrue(testList.contains(6));
   Assert.assertTrue(testList.contains(9));
   Assert.assertEquals(4, testList.size());
 }
 public boolean isPending(Runnable r) {
   if (r != null) {
     synchronized (m_listLock) {
       return m_dispatchingList.contains(r) || m_list.contains(r);
     }
   }
   return false;
 }
 @Test
 public void testAdjacency7() {
   LinkedList testList = board.getAdjList(7);
   Assert.assertTrue(testList.contains(11));
   Assert.assertTrue(testList.contains(3));
   Assert.assertTrue(testList.contains(6));
   Assert.assertEquals(3, testList.size());
 }
 @Test
 public void testAdjacenciesWalkways2() {
   list = board.getAdjList(board.calcIndex(5, 18));
   assertTrue(list.contains(board.calcIndex(5, 19)));
   assertTrue(list.contains(board.calcIndex(6, 18)));
   assertTrue(list.contains(board.calcIndex(5, 17)));
   assertEquals(3, list.size());
 }
 @Test
 public void testAdjacency8() {
   LinkedList testList = board.getAdjList(8);
   Assert.assertTrue(testList.contains(12));
   Assert.assertTrue(testList.contains(9));
   Assert.assertTrue(testList.contains(4));
   Assert.assertEquals(3, testList.size());
 }
 @Test
 public void testAdjacenciesRoomEntrances3() {
   list = board.getAdjList(board.calcIndex(15, 14));
   assertTrue(list.contains(board.calcIndex(14, 14)));
   assertTrue(list.contains(board.calcIndex(15, 15)));
   assertTrue(list.contains(board.calcIndex(15, 13)));
   assertEquals(3, list.size());
 }
 @Test
 public void testAdjacenciesRoomEntrances4() {
   list = board.getAdjList(board.calcIndex(14, 8));
   assertTrue(list.contains(board.calcIndex(13, 8)));
   assertTrue(list.contains(board.calcIndex(14, 9)));
   assertTrue(list.contains(board.calcIndex(15, 8)));
   assertTrue(list.contains(board.calcIndex(14, 7)));
   assertEquals(4, list.size());
 }
 @Test
 public void testAdjacenciesWalkways4() {
   list = board.getAdjList(board.calcIndex(10, 16));
   assertTrue(list.contains(board.calcIndex(9, 16)));
   assertTrue(list.contains(board.calcIndex(10, 17)));
   assertTrue(list.contains(board.calcIndex(11, 16)));
   assertTrue(list.contains(board.calcIndex(10, 15)));
   assertEquals(4, list.size());
 }
 // Green: adjacency list tests beside room entrance
 @Test
 public void testAdjacenciesRoomEntrances1() {
   list = board.getAdjList(board.calcIndex(6, 13));
   assertTrue(list.contains(board.calcIndex(5, 13)));
   assertTrue(list.contains(board.calcIndex(6, 14)));
   assertTrue(list.contains(board.calcIndex(7, 13)));
   assertTrue(list.contains(board.calcIndex(6, 12)));
   assertEquals(4, list.size());
 }
 @Test
 public void testAdjacenciesRoomEntrances2() {
   list = board.getAdjList(board.calcIndex(10, 17));
   assertTrue(list.contains(board.calcIndex(9, 17)));
   assertTrue(list.contains(board.calcIndex(10, 18)));
   assertTrue(list.contains(board.calcIndex(11, 17)));
   assertTrue(list.contains(board.calcIndex(10, 16)));
   assertEquals(4, list.size());
 }
Example #15
0
 @Override
 public void cancelEvent(Event event) {
   if (events.contains(event)) {
     events.remove(event);
   }
   if (worldevents.contains(event)) {
     worldevents.remove(event);
   }
 }
Example #16
0
  // ---------------- Public Methods ----------------//
  @Override
  public void registerEvent(Event event) {
    if (event == null) return;

    if (event instanceof WorldEvent && !worldevents.contains(event)) {
      worldevents.add((WorldEvent) event);
    } else if (!events.contains(event)) {
      events.add(event);
    }
  }
Example #17
0
 public int getPausableStatus(String methodName, String desc) {
   String md = methodName + desc;
   if (pausableMethods.contains(md)) {
     return Detector.PAUSABLE_METHOD_FOUND;
   } else if (otherMethods.contains(md)) {
     return Detector.METHOD_NOT_PAUSABLE;
   } else {
     return Detector.METHOD_NOT_FOUND_OR_PAUSABLE;
   }
 }
Example #18
0
 @Test
 public void testAdjacency5() {
   board.calcAdjacencies();
   LinkedList testList = board.getAdjList(5);
   Assert.assertTrue(testList.contains(4));
   Assert.assertTrue(testList.contains(1));
   Assert.assertTrue(testList.contains(6));
   Assert.assertTrue(testList.contains(9));
   Assert.assertEquals(4, testList.size());
 }
Example #19
0
  public static String writeGridOfRateCoeffs(ReactionModel p_reactionModel) {

    StringBuilder result = new StringBuilder();

    LinkedList pDepList = new LinkedList();
    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;

    for (Iterator iter = PDepNetwork.getNetworks().iterator(); iter.hasNext(); ) {
      PDepNetwork pdn = (PDepNetwork) iter.next();
      for (ListIterator pdniter = pdn.getNetReactions().listIterator(); pdniter.hasNext(); ) {
        PDepReaction rxn = (PDepReaction) pdniter.next();
        if (cerm.categorizeReaction(rxn) != 1) continue;
        // check if this reaction is not already in the list and also check if this reaction has a
        // reverse reaction
        // which is already present in the list.
        if (rxn.getReverseReaction() == null) rxn.generateReverseReaction();
        if (!rxn.reactantEqualsProduct()
            && !pDepList.contains(rxn)
            && !pDepList.contains(rxn.getReverseReaction())) {
          pDepList.add(rxn);
        }
      }
    }

    Temperature[] tempsUsedInFame = PDepRateConstant.getTemperatures();
    int numTemps = tempsUsedInFame.length;
    Pressure[] pressUsedInFame = PDepRateConstant.getPressures();
    int numPress = pressUsedInFame.length;

    for (int i = 0; i < numTemps; i++) {
      for (int j = 0; j < numPress; j++) {
        result.append(
            "T=" + tempsUsedInFame[i].getK() + "K,P=" + pressUsedInFame[j].getBar() + "bar\t");
      }
      result.append("\n");
    }
    result.append("\n");

    for (Iterator iter = pDepList.iterator(); iter.hasNext(); ) {
      PDepReaction r = (PDepReaction) iter.next();
      result.append(r.toString() + "\n");
      double[][] rates = new double[numTemps][numPress];
      rates = r.getPDepRate().getRateConstants();
      for (int i = 0; i < numTemps; i++) {
        for (int j = 0; j < numPress; j++) {
          result.append(rates[i][j] + "\t");
        }
        result.append("\n");
      }
      result.append("\n");
    }
    return result.toString();
  }
Example #20
0
 /** Fills the class combo with class names of the same package at other features. */
 private void initComboClassName() {
   String c = comboClass.getText();
   Object obj = selection.getFirstElement();
   if (obj instanceof IFile) {
     String fileExtension = ((IFile) obj).getFileExtension();
     if (composer.extensions().contains(fileExtension)) {
       String fileName = ((IFile) obj).getName();
       c = fileName.substring(0, fileName.lastIndexOf('.'));
     }
   }
   comboClass.removeAll();
   LinkedList<String> inclusions = new LinkedList<String>();
   LinkedList<String> exclusions = new LinkedList<String>();
   if (featureProject.getComposer().hasFeatureFolder()) {
     try {
       for (IResource res : featureProject.getSourceFolder().members()) {
         if (res instanceof IFolder) {
           IFolder folder = (IFolder) res;
           if (folder.getName().equals(comboFeature.getText())) {
             exclusions = getClasses(folder);
           } else {
             for (String className : getClasses(folder)) {
               boolean added = false;
               if (!inclusions.contains(className)) {
                 int i = 0;
                 for (String name : inclusions) {
                   if (className.compareToIgnoreCase(name) < 0) {
                     inclusions.add(i, className);
                     added = true;
                     break;
                   }
                   i++;
                 }
                 if (!added) {
                   inclusions.add(className);
                 }
               }
             }
           }
         }
       }
     } catch (CoreException e) {
       UIPlugin.getDefault().logError(e);
     }
   }
   for (String className : inclusions) {
     if (!exclusions.contains(className)) {
       comboClass.add(className);
     }
   }
   comboClass.setText(c);
 }
Example #21
0
  public static void filter(Link link) {
    // boolean c1, c2, c3, c4, c5;

    link.setUrl(link.getUrl().split("#")[0]);

    if (link.getUrl().toLowerCase().contains("https://en.wikipedia.org/wiki/".toLowerCase()))
      if ((link.getUrl().length() - link.getUrl().replaceAll(":", "").length()) == 1)
        if (!(link.getUrl()
            .toLowerCase()
            .contains("https://en.wikipedia.org/wiki/Main_Page".toLowerCase())))
          if (link.getDistance() <= MAX_DEPTH)
            if ((!toVisit.contains(link)) && (!visited.contains(link))) toVisit.add(link);
  }
Example #22
0
 // Test adjacency at entrance to rooms
 @Test
 public void testAdjacencyDoorways() {
   // Test beside a door direction RIGHT
   LinkedList<Integer> testList = board.getAdjList(board.calcIndex(4, 4));
   Assert.assertTrue(testList.contains(board.calcIndex(4, 3)));
   Assert.assertTrue(testList.contains(board.calcIndex(4, 5)));
   Assert.assertTrue(testList.contains(board.calcIndex(5, 4)));
   Assert.assertEquals(3, testList.size());
   // Test beside a door direction DOWN
   testList = board.getAdjList(board.calcIndex(6, 15));
   Assert.assertTrue(testList.contains(board.calcIndex(5, 15)));
   Assert.assertTrue(testList.contains(board.calcIndex(6, 14)));
   Assert.assertTrue(testList.contains(board.calcIndex(6, 16)));
   Assert.assertEquals(3, testList.size());
   // Test beside a door direction LEFT
   testList = board.getAdjList(board.calcIndex(15, 17));
   Assert.assertTrue(testList.contains(board.calcIndex(15, 16)));
   Assert.assertTrue(testList.contains(board.calcIndex(15, 18)));
   Assert.assertTrue(testList.contains(board.calcIndex(14, 17)));
   Assert.assertTrue(testList.contains(board.calcIndex(16, 17)));
   Assert.assertEquals(4, testList.size());
   // Test beside a door direction UP
   testList = board.getAdjList(board.calcIndex(13, 11));
   Assert.assertTrue(testList.contains(board.calcIndex(13, 10)));
   Assert.assertTrue(testList.contains(board.calcIndex(13, 12)));
   Assert.assertTrue(testList.contains(board.calcIndex(12, 11)));
   Assert.assertTrue(testList.contains(board.calcIndex(14, 11)));
   Assert.assertEquals(4, testList.size());
 }
Example #23
0
 /**
  * Find path to root
  *
  * @param event
  * @return
  */
 private LinkedList<EventType> pathToRoot(EventType event) {
   if (initialEvents.contains(event)) {
     LinkedList<EventType> path = new LinkedList<EventType>();
     path.add(event);
     return path;
   } else {
     Vector<EventType> predEventList = preds.get(event);
     if (predEventList == null) return null;
     else if (predEventList.size() == 0) {
       System.out.println(event.getEventId() + " has empty predEventList");
       return null;
     } else {
       for (EventType pred : predEventList) {
         // System.out.println("------------------------");
         // System.out.println("EventID: "+pred.getEventId());
         // System.out.println("PredID: "+pred.getEventId());
         //
         LinkedList<EventType> predPathToRoot = pathToRoot(pred);
         if (predPathToRoot == null) {
           continue;
         } else if (!predPathToRoot.contains(event)) {
           predPathToRoot.add(event);
           return predPathToRoot;
         }
       }
       return null;
     }
   }
 }
  @Override
  public SearchResult[] getSearchResults(String searchString) throws IOException {
    Document doc = Jsoup.connect(searchString).timeout(CONNECTION_TIMEOUT_VALUE).get();
    boolean onSearchResultsPage = doc.location().contains("adultSearch.htm");
    // found the movie without a search results page
    if (doc.location() != null && !onSearchResultsPage) {
      String idOfPage = getIDStringFromDocumentLocation(doc);
      String posterPath = getPosterPreviewPathFromIDString(idOfPage);
      String label = doc.select("title").first().text();
      Thumb previewImage = new Thumb(posterPath);
      // SearchResult directResult = new SearchResult(doc.location());
      SearchResult result = null;
      if (posterPath != null) result = new SearchResult(doc.location(), label, previewImage);
      else result = new SearchResult(doc.location(), label, null);

      SearchResult[] directResultArray = {result};
      return directResultArray;
    }
    Elements foundMovies = doc.select("table[width=690]:contains(Wish List) tr tbody:has(img)");
    LinkedList<SearchResult> searchList = new LinkedList<SearchResult>();

    for (Element movie : foundMovies) {
      String urlPath = movie.select("a").first().attr("href");
      String thumb = movie.select("img").first().attr("src");
      String label = movie.select("img").first().attr("alt");
      SearchResult searchResult = new SearchResult(urlPath, label, new Thumb(thumb));
      if (!searchList.contains(searchResult)) searchList.add(searchResult);
    }
    return searchList.toArray(new SearchResult[searchList.size()]);
  }
Example #25
0
 @Test
 public void testAdjacency15() {
   LinkedList testList = board.getAdjList(15);
   Assert.assertTrue(testList.contains(11));
   Assert.assertTrue(testList.contains(14));
   Assert.assertEquals(2, testList.size());
 }
 @Test
 public void testAdjacenciesWalkways5() {
   list = board.getAdjList(board.calcIndex(16, 0));
   assertTrue(list.contains(board.calcIndex(15, 0)));
   assertTrue(list.contains(board.calcIndex(16, 1)));
   assertEquals(2, list.size());
 }
Example #27
0
 private Grouping(List<GroupType> types) {
   groupOrder = new LinkedList<GroupType>(types);
   // at least marker should be shown
   if (!groupOrder.contains(GroupType.Marker)) {
     groupOrder.add(GroupType.Marker);
   }
 }
Example #28
0
 public int disCenterTotal(
     HashMap<Integer, LinkedList<Integer>> labelIn,
     HashMap<Integer, LinkedList<Integer>> labelOut) {
   LinkedList<Integer> center = new LinkedList<Integer>();
   Set<Integer> keySet = labelIn.keySet();
   for (int key : keySet) {
     LinkedList<Integer> temp = labelIn.get(key);
     for (int vertex : temp) if (!center.contains(vertex)) center.add(vertex);
   }
   keySet = labelOut.keySet();
   for (int key : keySet) {
     LinkedList<Integer> temp = labelOut.get(key);
     for (int vertex : temp) if (!center.contains(vertex)) center.add(vertex);
   }
   return center.size();
 }
 /**
  * Calculate largest prime factor.
  *
  * @return the largest prime factor
  */
 public int getLargestPrimeFactor() {
   int divider = PrimeChecker.FIRST_PRIME;
   double divideIt = this.divideIt;
   this.factors.addLast(PrimeChecker.FIRST_PRIME);
   while (divideIt > 1) {
     if (String.valueOf(divideIt).endsWith(String.valueOf(PrimeChecker.END_PRIME))) {
       divider = PrimeChecker.END_PRIME;
       divideIt = divideIt / divider;
     } else {
       boolean hasNext = false;
       for (final int prime : this.factors) {
         if (divideIt % prime == 0) {
           divider = prime;
           hasNext = true;
           break;
         }
       }
       if (!hasNext) {
         while (divideIt % divider == 0) {
           this.factors.addLast(divider);
           divider = PrimeChecker.getNextPrime(this.factors);
         }
         hasNext = false;
       }
     }
     divideIt = divideIt / divider;
     if (!factors.contains(divider)) {
       factors.add(divider);
     }
   }
   System.out.println("processed primes : " + factors.toString());
   return factors.getLast();
 }
Example #30
0
 public void addToGraphics(LinkedList<GraphicsComponent> components) {
   for (Entity e : entities) {
     if (components.contains(e.getGraphics()))
       System.out.println("From Square: redundant local storage adding: " + e);
     if (e.getGraphics() != null) components.add(e.getGraphics());
   }
 }