public static void generateTrainingDataFromFile(
      String
          fileLocation) // Requires that the original file had the metadata and requires that this
        // file is formated the same in first sheet
      {
    testDataLL = (LinkedList<String[]>) dataLL.clone();
    actualClassifications = (LinkedList<String>) classificationsLL.clone();

    FileInputStream file;
    try {
      file = new FileInputStream(new File(fileLocation));
      Workbook excelFile = new HSSFWorkbook(file);
      Sheet sheet1 = excelFile.getSheetAt(0); // Data sheet
      for (Row row : sheet1) {
        String data[] = new String[row.getPhysicalNumberOfCells() - 1];
        String classification = "";

        int offset =
            0; // Used so that we can declare an array of the size of the attributes without the
        // classification
        for (Cell cell : row) {
          int index = cell.getColumnIndex();
          if (classificationLocation != index) {
            data[index - offset] = cell.toString();
          } else {
            classification = cell.toString();
            offset++;
          }
        }

        // Even though data and classifications are not really used add it onto the end so it is
        // still complete for in the event they end up being used in a later version
        dataLL.add(data);
        classificationsLL.add(classification);

        trainingDataLL.add(data);
        knownClassifications.add(classification);

        // Check to see if we have seen that classification yet
        int occurrences = 0;
        for (int i = 0; i < classificationTypes.size() && occurrences == 0; i++) {
          if (classificationTypes.get(i).compareTo(classification) == 0) {
            occurrences = 1;
          }
        }
        if (occurrences == 0) {
          classificationTypes.add(classification);
        }
      }
      excelFile.close();
    } catch (FileNotFoundException e) {
      System.out.println("Error file not found");
      System.exit(0);
    } catch (IOException e) {
      System.out.println("Unable to read file, disk drive may be failing");
      e.printStackTrace();
      System.exit(0);
    }
  }
  public static void generateTrainingDataFirst(int trainingDataSize) {
    testDataLL = (LinkedList<String[]>) dataLL.clone();
    actualClassifications = (LinkedList<String>) classificationsLL.clone();

    for (int i = 0; i < trainingDataSize; i++) {
      generateTrainingData(0);
    }
  }
  public static void generateTrainingDataRandom(int trainingDataSize) {
    testDataLL = (LinkedList<String[]>) dataLL.clone();
    actualClassifications = (LinkedList<String>) classificationsLL.clone();

    for (int i = 0; i < trainingDataSize; i++) {
      int index = (int) (Math.random() * testDataLL.size());
      generateTrainingData(index);
    }
  }
  public static void generateTrainingDataStride(int trainingDataSize) {
    testDataLL = (LinkedList<String[]>) dataLL.clone();
    actualClassifications = (LinkedList<String>) classificationsLL.clone();

    int removalCount = 0;

    for (int i = 0; i < trainingDataSize; i++) {
      double index = i * ((double) dataLL.size() / (double) trainingDataSize);
      generateTrainingData((int) (Math.round(index) - removalCount));

      removalCount++;
    }
  }
Exemple #5
0
 public LinkedList cloneList() {
   LinkedList t;
   LinkedList f = first();
   LinkedList k = (LinkedList) f.clone();
   LinkedList nf = k;
   while (f.hasMoreElements() != false) {
     f = (LinkedList) f.nextElement();
     t = (LinkedList) f.clone();
     t.prev = k;
     k.next = t;
     k = t;
   }
   ;
   return nf;
 }
  void mixLists(
      LinkedList<Integer> left,
      LinkedList<Integer> right,
      ArrayList<LinkedList<Integer>> mix,
      LinkedList<Integer> before) {
    if (before.isEmpty() || right.isEmpty()) {
      LinkedList<Integer> l = new LinkedList<>();
      l = (LinkedList<Integer>) before.clone();
      l.addAll(left);
      l.addAll(right);
      mix.add(l);
      return;
    }
    int hl = left.removeFirst();
    before.addLast(hl);
    mixLists(left, right, mix, before);
    before.removeLast();
    left.addFirst(hl);

    int hr = right.removeFirst();
    before.addLast(hr);
    mixLists(left, right, mix, before);
    before.removeLast();
    right.addFirst(hr);
  }
Exemple #7
0
  public void weavelists(
      LinkedList<Integer> first,
      LinkedList<Integer> second,
      ArrayList<LinkedList<Integer>> results,
      LinkedList<Integer> prefix) {
    if (first.size() == 0 || second.size() == 0) {
      LinkedList<Integer> result = (LinkedList<Integer>) prefix.clone();
      result.addAll(first);
      result.addAll(second);
      results.add(result);
      return;
    }

    int headFirst = first.removeFirst();
    prefix.addLast(headFirst);
    weavelists(first, second, results, prefix);
    prefix.removeLast();
    first.addFirst(headFirst);

    int secondHead = second.removeFirst();
    prefix.addLast(secondHead);
    weavelists(first, second, results, prefix);
    prefix.removeLast();
    second.addFirst(secondHead);
  }
 private static IActivity consumeXor(
     IActivity startActivity,
     LinkedList<ITransition> unconsumed,
     HashSet<ITransition> visited,
     boolean forward,
     boolean supportsLoops,
     ModelElementList<ITransition> transitions) {
   IActivity result = null;
   for (ITransition out : transitions) {
     if (visited.contains(out)) // loop
     {
       if (!supportsLoops) {
         return null;
       }
     } else {
       LinkedList<ITransition> unconsumedClone = (LinkedList<ITransition>) unconsumed.clone();
       HashSet<ITransition> visitedClone = (HashSet<ITransition>) visited.clone();
       visitedClone.add(out);
       unconsumedClone.add(out);
       IActivity next =
           consume(startActivity, unconsumedClone, visitedClone, forward, supportsLoops);
       if (next == null) {
         return null;
       } else if (result == null) {
         result = next;
       } else if (result != next) {
         return null;
       }
     }
   }
   return result;
 }
Exemple #9
0
  /** 测试从AbstractSequentialList中继承的方法 */
  private static void testLinkedListFromASL() {
    System.out.println(
        "Test methods: add(), addAll(Collection<?> extends E c), get(int index), set(int index, E e), remove(int index), clear(), clone()");

    // 将"a", "b"添加到list中
    LinkedList<String> list = new LinkedList<String>();
    list.add("a");
    list.add("b");
    printList(list);

    // 将含有"c", "d"的集合list2添加到list中
    LinkedList<String> list2 = new LinkedList<String>();
    list2.add("c");
    list2.add("d");
    list.addAll(list.size(), list2);
    printList(list);

    // 将list中的最后一个元素设置成第一个元素
    list.set(list.size() - 1, list.get(0)); // list.set(index, e)、list.get(index)都不推荐使用!
    printList(list);

    // 将第一个"a"元素从list中移除
    list.remove(list.indexOf("a"));
    printList(list);

    // 将list克隆一份
    LinkedList<String> cloneList = (LinkedList<String>) list.clone();
    printList(cloneList);

    // 将list中元素清除
    list.clear();
    System.out.println("list elements : " + list + " list size : " + list.size());
  }
Exemple #10
0
 public void addTickGroup(Tick tock) {
   LinkedList<Tick> newTicks = (LinkedList<Tick>) ticks.clone();
   if (!newTicks.contains(tock)) {
     newTicks.add(tock);
     ticks = newTicks;
   }
 }
  /**
   * Calculate the distance between two taskSet one assumption here taskA and taskB are at the same
   * level because it is horizontal clustering does not work with arbitary workflows
   *
   * @param taskA
   * @param taskB
   * @return
   */
  private int calDistance(TaskSet taskA, TaskSet taskB) {
    if (taskA == null || taskB == null || taskA == taskB) {
      return 0;
    }
    LinkedList<TaskSet> listA = new LinkedList<TaskSet>();
    LinkedList<TaskSet> listB = new LinkedList<TaskSet>();
    int distance = 0;
    listA.add(taskA);
    listB.add(taskB);

    if (taskA.getTaskList().isEmpty() || taskB.getTaskList().isEmpty()) {
      return Integer.MAX_VALUE;
    }
    do {

      LinkedList<TaskSet> copyA = (LinkedList) listA.clone();
      listA.clear();
      for (TaskSet set : copyA) {
        for (TaskSet child : set.getChildList()) {
          if (!listA.contains(child)) {
            listA.add(child);
          }
        }
      }
      LinkedList<TaskSet> copyB = (LinkedList) listB.clone();
      listB.clear();
      for (TaskSet set : copyB) {
        for (TaskSet child : set.getChildList()) {
          if (!listB.contains(child)) {
            listB.add(child);
          }
        }
      }

      for (TaskSet set : listA) {
        if (listB.contains(set)) {
          return distance * 2;
        }
      }

      distance++;

    } while (!listA.isEmpty() && !listB.isEmpty());

    return distance * 2;
  }
Exemple #12
0
  public FunType(Type _retType, LinkedList<Type> _args) {
    if (_args == null) {
      args = new LinkedList<Type>();
    } else {
      args = (LinkedList<Type>) _args.clone();
    }

    retType = _retType;
  }
Exemple #13
0
 public LinkedList allBut(Object key) {
   LinkedList t;
   LinkedList f = first();
   if (f.value.equals(key))
     if (f.next != null) f = f.next;
     else return null;
   LinkedList k = (LinkedList) f.clone();
   LinkedList nf = k;
   while (f.hasMoreElements() != false) {
     f = (LinkedList) f.nextElement();
     if (f.value.equals(key)) continue;
     t = (LinkedList) f.clone();
     t.prev = k;
     k.next = t;
     k = t;
   }
   ;
   return nf;
 }
  /**
   * Clones this set.
   *
   * @return Clone of this set.
   * @throws CloneNotSupportedException
   */
  @SuppressWarnings({"unchecked", "OverriddenMethodCallDuringObjectConstruction"})
  @Override
  protected Object clone() throws CloneNotSupportedException {
    GridListSet<V> clone = (GridListSet<V>) super.clone();

    clone.vals = (LinkedList<V>) vals.clone();
    clone.comp = comp;
    clone.strict = strict;

    return clone;
  }
  @SuppressWarnings("unchecked")
  public ViewComponentInfo(
      int ix, int iy, int iw, int ih, int mw, int mh, LinkedList<ViewComponentInfo> ic) {
    x = ix;
    y = iy;
    width = iw;
    height = ih;
    measuredWidth = mw;
    measuredHeight = mh;

    if (ic != null) children = (LinkedList<ViewComponentInfo>) ic.clone();
    else children = null;
  }
Exemple #16
0
  private void paintAnimations(Graphics2D g2d) {

    LinkedList<Animation> toRemove = new LinkedList<Animation>();
    // get all the animations you can, forget about the ones that are about to be added
    animationLock.lock();
    List<Animation> toPaint = (List<Animation>) animations.clone();
    animationLock.unlock();
    for (Animation x : toPaint) {
      if (x.isOver()) toRemove.add(x);
      else x.step(g2d);
    }

    animations.removeAll(toRemove);
  }
  /**
   * Gets rid of all the resources of the view. No other methods should be invoked on the view
   * afterwards.
   */
  @SuppressWarnings("unchecked")
  @Override
  public void dispose() {
    if (executor != null) {
      executor.shutdown();
      executor = null;
    }

    if (disposables != null) {
      for (Disposable d : (LinkedList<Disposable>) disposables.clone()) {
        d.dispose();
      }
      disposables = null;
    }

    removeAll();
  }
 public RfcommChannelPicker(UUID uuid) {
   synchronized (RfcommChannelPicker.class) {
     if (sChannels == null) {
       // lazy initialization of non-reserved rfcomm channels
       sChannels = new LinkedList<Integer>();
       for (int i = 1; i <= BluetoothSocket.MAX_RFCOMM_CHANNEL; i++) {
         sChannels.addLast(new Integer(i));
       }
       for (int reserved : RESERVED_RFCOMM_CHANNELS) {
         sChannels.remove(new Integer(reserved));
       }
       sRandom = new Random();
     }
     mChannels = (LinkedList<Integer>) sChannels.clone();
   }
   mUuid = uuid;
 }
  // $ANTLR start "parameters"
  // /Users/joachim/workspace/MartScript/ANTLR/MartScript.g:38:1: parameters returns [List value] :
  // ( WHITESPACE argument )* ;
  public final List parameters() throws RecognitionException {
    List value = null;

    try {
      // /Users/joachim/workspace/MartScript/ANTLR/MartScript.g:39:2: ( ( WHITESPACE argument )* )
      // /Users/joachim/workspace/MartScript/ANTLR/MartScript.g:39:4: ( WHITESPACE argument )*
      {
        // /Users/joachim/workspace/MartScript/ANTLR/MartScript.g:39:4: ( WHITESPACE argument )*
        loop4:
        do {
          int alt4 = 2;
          int LA4_0 = input.LA(1);

          if ((LA4_0 == WHITESPACE)) {
            alt4 = 1;
          }

          switch (alt4) {
            case 1:
              // /Users/joachim/workspace/MartScript/ANTLR/MartScript.g:39:5: WHITESPACE argument
              {
                match(input, WHITESPACE, FOLLOW_WHITESPACE_in_parameters161);
                pushFollow(FOLLOW_argument_in_parameters163);
                argument();

                state._fsp--;
              }
              break;

            default:
              break loop4;
          }
        } while (true);

        value = (List) parameters.clone();
        parameters.clear();
      }

    } catch (RecognitionException re) {
      reportError(re);
      recover(input, re);
    } finally {
    }
    return value;
  }
Exemple #20
0
  @SuppressWarnings("unchecked")
  protected void workerLoop() {

    log.debug("workerLoop();");

    if (scsn != null && sessionID != null) {
      startSC();
    }

    synchronized (cmdQueue) {
      while (running) {
        try {
          cmdQueue.wait();
        } catch (InterruptedException e) {
          log.error(e.getMessage(), e);
          return;
        }
        if (!running) return;

        if (!cmdQueue.isEmpty()) {
          // commands to send
          @SuppressWarnings("rawtypes")
          final LinkedList<Command> commands = (LinkedList<Command>) cmdQueue.clone();
          cmdQueue.clear();

          if (!running) return;

          threadPool.background(
              new Runnable() {

                @Override
                public void run() {
                  log.error("run();");
                  try {
                    processRequest(commands);
                  } catch (IOException e) {
                    handleError(e);
                  }
                }
              });
        }
      }
    }
  }
  @Test
  public void shouldStubbingWithThrowableBeVerifiable() {
    when(mock.size()).thenThrow(new RuntimeException());
    stubVoid(mock).toThrow(new RuntimeException()).on().clone();

    try {
      mock.size();
      fail();
    } catch (RuntimeException e) {
    }

    try {
      mock.clone();
      fail();
    } catch (RuntimeException e) {
    }

    verify(mock).size();
    verify(mock).clone();
    verifyNoMoreInteractions(mock);
  }
  void weaveList(
      LinkedList<Integer> first,
      LinkedList<Integer> sec,
      ArrayList<LinkedList<Integer>> results,
      LinkedList<Integer> pre) {
    if (first.size() == 0 || sec.size() == 0) {
      LinkedList<Integer> result = (LinkedList<Integer>) pre.clone();
      result.addAll(first);
      result.addAll(sec);
      results.add(result);
      return;
    }

    int headfirst = first.removeFirst();
    pre.addLast(headfirst);
    pre.removeLast();
    first.addFirst(headfirst);

    int headsec = sec.removeLast();
    pre.addLast(headsec);
    weaveList(first, sec, results, pre);
    pre.removeLast();
    sec.addFirst(headsec);
  }
Exemple #23
0
 /**
  * Return a copy of the array containing all class diagram elements.
  *
  * @return a copy of the array containing all class diagram elements
  */
 @SuppressWarnings("unchecked")
 public LinkedList<IDiagramComponent> getComponents() {
   return (LinkedList<IDiagramComponent>) components.clone();
 }
  public static void taatand(String s) {
    LinkedList<Lnode>[] lkarray = new LinkedList[10];
    // LinkedList<Integer>[] vertex = new LinkedList[5];
    LinkedList<Lnode> mergell = new LinkedList<Lnode>();
    LinkedList<Lnode> m2 = new LinkedList<Lnode>();
    LinkedList<Lnode> temp = new LinkedList<Lnode>();
    String[] result = Querymanip.getlinetoken(s);
    ArrayList<Integer> fin = new ArrayList<Integer>();
    int qno = result.length; // no of query terms
    long tStart, tEnd, tDelta;
    double elapsedSeconds;
    tStart = System.currentTimeMillis();
    int c = 0;
    for (int i = 0; i < qno; i++) {
      lkarray[i] =
          llbyfreq(result[i]); // here used function to get linked list cuz it wasnt messing up
      // int sz=lkarray[i].size();
      // System.out.println(sz);
    }
    int min = lkarray[0].size(); // find list with minimum size
    for (int i = 0; i < qno; i++)
      if (lkarray[i].size() < min) {
        min = lkarray[i].size();
      }
    // System.out.println("MIN POST LIST IS"+ min);
    for (int i = 0; i < qno; i++)
      if (lkarray[i].size() == min)
        mergell = (LinkedList<Lnode>) lkarray[i].clone(); // make that your starting list

    // System.out.println(mergell.get(0).docid);
    int x = 0;
    int j;
    while (x < qno) {
      for (int i = 0; i < mergell.size(); i++) {
        // System.out.println("mergell sx" + mergell.size());
        for (j = 0; j < lkarray[x].size(); j++) {
          c++;
          if (mergell.get(i).docid
              == lkarray[x].get(j)
                  .docid) { // if both are same then add to middle result and check for other terms
            // System.out.println("aded to m2"+mergell.get(i).docid);
            m2.add(mergell.get(i));
            // System.out.println();
            break;
          }
          /*if(j==lkarray[x+1].size())
          lkarray[x+1].add(lkarray[x].get(i));*/
        }
        /*if(j==lkarray[x].size())
        {mergell.remove(i);   //print mergell i to i-1size to check chang size?
        i=i-1;}*/
      }

      mergell =
          (LinkedList<Lnode>)
              m2.clone(); // after one row is done make the merged list the one with clasing values

      m2.clear(); // clear this to find clashin values of next iteration
      x++;
    }
    // end of while
    // System.out.println("CLASHING DOC\\n");
    // System.out.println(mergell.size());
    tEnd = System.currentTimeMillis();
    tDelta = tEnd - tStart;
    elapsedSeconds = tDelta / 1000.0;
    System.out.print(
        "FUNCTION: termAtATimeQueryAnd"); // print result did separately so arrays dont get mixed up
    for (int i = 0; i < qno - 1; i++) {
      System.out.print(" " + result[i] + ",");
    }
    System.out.print(" " + result[qno - 1]);
    System.out.println();
    System.out.println(mergell.size() + " documents are found");
    System.out.println(c + " comparisons are made");
    System.out.println(elapsedSeconds + " seconds are used");
    int sz = mergell.size(); // if not 0
    if (sz == 0) {
      System.out.print("Result: ");
      System.out.println("no docs found");
    } else if (sz == 1) {
      System.out.print("Result: ");
      System.out.println(mergell.get(0).docid);
    } else {
      int t;
      int p;
      for (int m = sz; m >= 0; m--) {
        for (int i = 0; i < sz - 1; i++) {
          p = i + 1;
          if (mergell.get(i).docid > mergell.get(p).docid) {

            t = mergell.get(i).docid;
            // temp1=klist[i].termk;
            mergell.get(i).docid = mergell.get(p).docid;
            mergell.get(p).docid = t;
            // klist[p].termk=temp1;

          }
        }
      }

      System.out.print("Result: ");
      for (int i = 0; i < sz - 1; i++) {
        System.out.print(mergell.get(i).docid + ", ");
      }
      System.out.println(mergell.get(sz - 1).docid);
    }

    // System.out.print(mergell.get(0).docid);

  } // end of method
  /**
   * This method calculates the path from the origin to the destination road segment.
   *
   * @param smiod The SMIOD object.
   */
  public boolean calculatePath(
      StreetMobilityInfoOD smiod, RoadSegment origin, Location nextEnd, RoadSegment destination) {
    // TODO support loading from OD pairs
    // after calling constructor, objects for A* search must be created
    boolean found = false;

    // TODO the caller should determine direction
    if (DEBUG_OD) {
      System.out.println("Calculating path...");
      System.out.println("Origin:      " + origin.printStreetName(streets));
      System.out.println("Destination: " + destination.printStreetName(streets));
      System.out.println(
          "Distance: " + origin.getStartPoint().distance(destination.getStartPoint()));
    }

    if (nextEnd == null) {
      if (smiod.rsEnd.distance(origin.getEndPoint()) == 0) {
        nextEnd = origin.getEndPoint();
      } else {
        nextEnd = origin.getStartPoint();
      }
    }
    if (DEBUG_OD && DEBUG_VIS_OD && v != null) {
      v.colorSegment(origin, Color.RED);
    }

    boolean endStart;
    Location endPoint;
    if (destination.getStartPoint().distance(nextEnd)
        < destination.getEndPoint().distance(nextEnd)) {
      endPoint = destination.getStartPoint();
      endStart = true;
    } else {
      endPoint = destination.getEndPoint();
      endStart = false;
    }

    SegmentNode startNode =
        new SegmentNode(
            nextEnd, origin.getSelfIndex(), origin.getStartPoint().distance(nextEnd) == 0, true);
    SegmentNode endNode = new SegmentNode(endPoint, destination.getSelfIndex(), endStart, false);
    sni.dest = endNode;

    // try to find cached path
    if (hm != null) {
      LinkedList ll = (LinkedList) hm.get(nextEnd);
      if (ll != null) {
        ListIterator li = ll.listIterator();

        while (li.hasNext()) {
          LinkedList path = (LinkedList) li.next();
          if (!matches(startNode, endNode, path)) {
            continue;
          }
          smiod.path = (LinkedList) path.clone();
          smiod.path.removeFirst();
          if (DEBUG_OD) System.out.println("Found cached path!");
          return true;
          //                    break;
        }
      }
    }
    if (!found) {

      //      TODO support locations at arbitrary points on road
      smiod.destinationSN = endNode;
      smiod.destinationLocation = destination.getEndPoint();

      AStarSearch ass = new AStarSearch(hm, this); // TODO rename variable
      smiod.path = ass.findPath(startNode, endNode); // find the path
    }

    // no path found
    if (smiod.path.get(0) == null) {
      AStarSearch ass = new AStarSearch(hm, this); // TODO rename variable
      smiod.path = ass.findPath(startNode, endNode); // find the path
      if (v != null) {
        v.colorSegments(
            new RoadSegment[] {origin, destination}, new Color[] {Color.RED, Color.RED});
      }
      smiod.path.remove(0);
      System.out.println("No path found!");
      return false;
    }

    if (DEBUG_VIS_OD && v != null) {
      showPath(smiod.path.toArray(), Color.BLUE);
    }

    // check for strange double entry in list
    for (int i = 1; i < smiod.path.size(); i++) {
      if (((SegmentNode) smiod.path.get(smiod.path.size() - i)).segmentID
          == ((SegmentNode) smiod.path.get(smiod.path.size() - (i + 1))).segmentID) {
        if (DEBUG_OD) System.out.println("Removed redundant entry!");
        smiod.path.remove(smiod.path.size() - i);
      }
    }

    if (DEBUG_OD) printPath(smiod.path);
    if (hm != null) cachePath(smiod, startNode, endNode);

    return true; // path found!
  }
Exemple #26
0
 public void delTickGroup(Tick tock) {
   LinkedList<Tick> newTicks = (LinkedList<Tick>) ticks.clone();
   if (newTicks.remove(tock)) ticks = newTicks;
 }
 @SuppressWarnings("unchecked")
 LinkedList<ViewComponentInfo> getChildren() {
   return (LinkedList<ViewComponentInfo>) children.clone();
 }
Exemple #28
0
 public void setDomainsBackup() {
   domainsBackup = (LinkedList<Domain>) domains.clone();
 }
 public LinkedList<Medium> getAllMedia() {
   return (LinkedList<Medium>) availableMedia.clone();
 }
 public synchronized LinkedList<SensorDataPoint> getDataPoints() {
   return (LinkedList<SensorDataPoint>) dataPoints.clone();
 }