Esempio n. 1
1
  public Message send(Message query) {
    int q, r;
    Message best = null;
    byte rcode;

    for (q = 0; q < 20; q++) {
      boolean ok = false;
      for (r = 0; r < resolvers.length; r++) ok |= sendTo(query, r, q);
      if (!ok) break;
      Message m = null;
      synchronized (queue) {
        try {
          queue.wait((quantum + 1) * 1000);
        } catch (InterruptedException e) {
          System.out.println("interrupted");
        }
        if (queue.size() == 0) continue;
        m = (Message) queue.firstElement();
        queue.removeElementAt(0);
        Integer I = (Integer) queue.firstElement();
        queue.removeElementAt(0);
        r = I.intValue();
      }
      if (m == null) invalid[r] = true;
      else {
        rcode = m.getHeader().getRcode();
        if (rcode == Rcode.NOERROR) return m;
        else {
          if (best == null) best = m;
          invalid[r] = true;
        }
      }
    }
    return best;
  }
  protected void checkAndAppendSyllables(
      BufferedWriter w, String line, Vector<ClusterProperties> syllables) throws IOException {
    while (syllables.size() > 0) {
      int candidateLength = Math.min(syllables.size(), mMaxSyllables);

      for (; candidateLength > 0; --candidateLength) {
        ClusterProperties endSyllable = syllables.elementAt(candidateLength - 1);

        String candidate =
            line.substring(syllables.firstElement().getStart(), endSyllable.getEnd());
        if (mWordList.contains(candidate)) {
          w.append(candidate);
          appendSpacer(w, line, endSyllable);
          List<ClusterProperties> wordCP =
              new ArrayList<ClusterProperties>(syllables.subList(0, candidateLength));
          syllables.removeAll(wordCP);
          break;
        }
      }
      if (candidateLength == 0) {
        // no match found, so append first syllable as is
        w.append(
            line.substring(syllables.firstElement().getStart(), syllables.firstElement().getEnd()));
        appendSpacer(w, line, syllables.firstElement());
        syllables.remove(0);
      }
    }
  }
Esempio n. 3
1
  protected void close() {
    if (points.isEmpty()) {
      return;
    }

    if (points.size() > 1
        && ((Point2d) points.lastElement()).equals((Point2d) points.firstElement())) {
      points.setSize(points.size() - 1);
      normals.setSize(normals.size() - 2);
    }
    if (points.size() >= 3) {

      double dx = ((Point2d) points.firstElement()).x - ((Point2d) points.lastElement()).x;
      double dy = ((Point2d) points.firstElement()).y - ((Point2d) points.lastElement()).y;
      double len = Math.sqrt(dx * dx + dy * dy);
      Vector3d a = new Vector3d(dx / len, 0, dy / len);
      Vector3d b = new Vector3d(0, 1, 0);
      Vector3d c = MathUtilities.crossProduct(a, b);
      normals.setElementAt(new Vector3f(-(float) c.x, -(float) c.z, 0), 1);
      normals.setElementAt(new Vector3f(-(float) c.x, -(float) c.z, 0), (points.size() - 1) * 2);
    } else {
      points.clear();
      normals.clear();
    }
  }
Esempio n. 4
1
  @Override
  public void run() {
    while (true) {
      int a = 0;
      int b = 0;
      if (!Myvecx.isEmpty() && !Myvecy.isEmpty() && !Myvecmode.isEmpty()) {
        int x = Myvecx.firstElement().intValue();
        int y = Myvecy.firstElement().intValue();
        char m = Myvecmode.firstElement().charValue();
        Myvecx.removeElementAt(0);
        Myvecy.removeElementAt(0);
        Myvecmode.removeElementAt(0);
        out.println(x + " " + y + " " + m);
        System.err.println("Output: (" + x + "," + y + ") Mode: " + m);
        a = x;

        b = y;
        // if(x<0 || y<0) break;
      }
      // if(a<0 || b<0) break;
    }

    /*try{
    	out.close();
    } catch(Exception io){
    	io.printStackTrace();
    	System.err.println(io.getMessage());
    }*/
  }
Esempio n. 5
1
 public DMRepository getSelectedDMRepository() {
   SelectionManager sm = getDMController().getSelectionManager();
   Vector<FlexoModelObject> selection = sm.getSelection();
   if (selection.size() == 1 && selection.firstElement() instanceof DMRepository) {
     return (DMRepository) selection.firstElement();
   }
   return null;
 }
Esempio n. 6
1
 public void init(Vector<String> args) {
   if (args.size() == 1) {
     n = Integer.parseInt(args.firstElement());
   } else {
     id = args.get(args.size() - 1);
     n = Integer.parseInt(args.firstElement());
   }
 }
Esempio n. 7
1
  public ViewComponentInfo projectAbsoluteCoordinateRecursively(Integer ix, Integer iy) {
    // Miss
    if (!checkHit(ix, iy)) return null;

    if (this.viewType.endsWith("Spinner")) {
      this.isSpinner = true;
      return this;
    }

    // I'm hit and has child.
    if (this.children != null) {
      // Assumption : children never intersect

      ViewComponentInfo projected_child;

      if (this.isContainer || this.viewType.equals("android.widget.TabWidget")) {
        Vector<ViewComponentInfo> views = new Vector<ViewComponentInfo>();
        for (ViewComponentInfo child : children) {
          if (child.checkHit(ix, iy)) {
            child.isCollectionMember = true;
            views.add(child);
          }
        }
        if (views.size() == 1) {
          return views.firstElement();
        }
      }
      if (this.viewType.endsWith(("FrameLayout"))) {
        LinkedList<ViewComponentInfo> chlist = new LinkedList<ViewComponentInfo>(children);
        ViewComponentInfo child = getFrameContent(children);
        projected_child = child.projectAbsoluteCoordinateRecursively(ix, iy);
        if (projected_child != null) return projected_child;
      } else {
        Vector<ViewComponentInfo> views = new Vector<ViewComponentInfo>();
        for (ViewComponentInfo child : children) {
          projected_child = child.projectAbsoluteCoordinateRecursively(ix, iy);
          if (projected_child != null) views.add(projected_child);
        }
        if (views.size() == 1) {
          return views.firstElement();
        }
      }
    }

    // The point hit no child.
    // Thus return my self.
    if (this.viewType.endsWith("Layout")
        || this.viewType.endsWith("TextView")
        || this.viewType.endsWith("ScrollView")
        || this.viewType.endsWith("ViewStub")
        || this.viewType.endsWith("DialogTitle")
        || this.viewType.endsWith("ImageView")) {
      if (this.hasOnClickListener()) return this;
      else return null;
    }
    return this;
  }
Esempio n. 8
1
  /**
   * 鍒嗘淳宸ヤ綔
   *
   * @param state
   */
  private static void dispatchWorkItem() {
    WorkThread wt = null;
    while (true) {
      WorkTaskData data = null;
      if (quequeWorkTaskDatas.size() > 0) {
        data = (WorkTaskData) quequeWorkTaskDatas.firstElement();
        quequeWorkTaskDatas.removeElement(quequeWorkTaskDatas.firstElement());
        while (true) {
          int index = -1;
          int size = pooledWorkThreads.size();
          for (int i = 0; i < size; i++) {
            if (((WorkThread) pooledWorkThreads.elementAt(i)).IsIdle()) {
              index = i;
              break;
            }
          }
          if (index > -1) {

            for (int i = 0; i < size; i++) { // 宸茬粡鍚姩鐨勭嚎绋嬭缃瓑绾т负鏈�浣庣骇
              if (!((WorkThread) pooledWorkThreads.elementAt(i)).IsIdle()) {
                ((WorkThread) pooledWorkThreads.elementAt(i)).setPriority(WorkThread.MIN_PRIORITY);
              }
            }
            wt = (WorkThread) pooledWorkThreads.elementAt(index);
            wt.setPriority(WorkThread.MAX_PRIORITY); // 鏈�鍚庝竴涓惎鍔ㄧ殑璁剧疆涓洪珮绾�
            wt.setWorkTaskData(data);
            if (index <= DEFAULT_MAX_WORKTHREADS
                && index + 1 < pooledWorkThreads.size()) // 鍒ゆ柇鏄惁鍙堝彲浠ュ洖鏀剁殑鏉′欢
            {
              recycleThread();
            }
            break;
          } else {
            addThreadToPooled(); // 绾跨▼涓嶅鐢ㄦ坊鍔犳柊绾跨▼
          }
        }
        try {
          Thread.sleep(100);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        synchronized (lock) {
          try {

            if (quequeWorkTaskDatas.size() == 0) {
              isWating = true;
              lock.wait();
            }
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    }
  }
 private void doCurrentMethodStep() {
   switch (type) {
     case 0: // bisectiei
       if (Math.abs(function.evaluate((Cn.lastElement()).x)) < err) {
         complete = true;
         theTimer.stop();
       } else if (function.evaluate((An.lastElement()).x) * function.evaluate((Cn.lastElement()).x)
           < 0) {
         Bn.add(Cn.lastElement());
         Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0));
       } else {
         An.add(Cn.lastElement());
         Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0));
       }
       break;
     case 1: // coardei
       {
         double evn = function.evaluate((An.lastElement()).x);
         if (Math.abs(evn) < err) {
           complete = true;
           theTimer.stop();
         } else {
           double ev0 = function.evaluate((An.firstElement()).x);
           double newVal = (An.firstElement().x * evn - An.lastElement().x * ev0) / (evn - ev0);
           An.add(new PointDP(newVal, 0.0));
         }
       }
       break;
     case 2: // secantei
       {
         double exn = function.evaluate((An.lastElement()).x);
         if (Math.abs(exn) < err) {
           complete = true;
           theTimer.stop();
         } else {
           double exn1 = function.evaluate((An.elementAt(An.size() - 2)).x);
           double newVal =
               (An.elementAt(An.size() - 2).x * exn - (An.lastElement()).x * exn1) / (exn - exn1);
           An.add(new PointDP(newVal, 0.0));
         }
       }
       break;
     case 3: // newton
       double xn = An.lastElement().x;
       if (Math.abs(function.evaluate(xn)) < err) {
         complete = true;
         theTimer.stop();
       }
       An.add(new PointDP(xn - function.evaluate(xn) / function.evaluate_1(xn), 0.0));
       break;
   }
 }
Esempio n. 10
1
  private boolean isConsecutive() {
    Vector<Rank> checkRank = cards.get(0);
    // case Ace,one,two,three,four
    if (checkRank.firstElement().equals(Rank.ACE) && checkRank.get(1).equals(Rank.FIVE)) {
      int second = checkRank.get(1).ordinal();
      int last = checkRank.lastElement().ordinal();
      if (second - last == 3) return true;
      return false;
    }

    int first = checkRank.firstElement().ordinal();
    int last = checkRank.lastElement().ordinal();
    if (first - last == 4) return true;
    return false;
  }
Esempio n. 11
1
 protected Shape getShape() {
   if (points.isEmpty()) {
     return null;
   }
   java.awt.geom.GeneralPath gp = new java.awt.geom.GeneralPath();
   gp.moveTo(
       (float) ((Point2d) points.firstElement()).x, (float) ((Point2d) points.firstElement()).y);
   java.util.ListIterator li = points.listIterator(1);
   while (li.hasNext()) {
     Point2d cur = (Point2d) li.next();
     gp.lineTo((float) cur.x, (float) cur.y);
   }
   gp.closePath();
   return gp;
 }
Esempio n. 12
1
    /** 关闭一个连接 */
    public synchronized void releaseOne() {
      if (freeConnections.firstElement() != null) {
        Connection con = (Connection) freeConnections.firstElement();
        try {
          con.close();
          System.out.println("关闭连接池" + id + "中的一个连接");
          System.out.println("关闭连接池" + id + "中的一个连接");
        } catch (SQLException e) {

          System.out.println("无法关闭连接池" + id + "中的一个连接");
        }
      } else {
        System.out.println("releaseOne() err..........................");
      }
    }
Esempio n. 13
1
    public synchronized Connection returnConnection() {
      Connection con = null;
      // 如果闲置小于最大连接,返回一个新连接
      if (freeConnections.size() < maxConn) {
        con = newConnection();
      }
      // 如果闲置大于最大连接,返回一个可用的旧连接
      else if (freeConnections.size() >= maxConn) {

        con = (Connection) freeConnections.firstElement();
        System.out.println(" [a 连接池可用连接数 ] : " + "[ " + freeConnections.size() + " ]");
        freeConnections.removeElementAt(0);
        System.out.println(" [b 连接池可用连接数 ] : " + "[ " + freeConnections.size() + " ]");
        try {
          if (con.isClosed()) {
            System.out.println("从连接池" + id + "删除一个无效连接");
            System.out.println("从连接池" + id + "删除一个无效连接");
            returnConnection();
          }
        } catch (SQLException e) {
          System.out.println("从连接池" + id + "删除一个无效连接时错误");
          System.out.println("从连接池" + id + "删除一个无效连接出错");
          returnConnection();
        }
      }
      return con;
    }
  /**
   * remove member from the game. Also updates game's client version range, with remaining connected
   * members. Please call {@link #takeMonitorForGame(String)} before calling this.
   *
   * @param gaName the name of the game
   * @param conn the member's connection
   */
  public synchronized void removeMember(StringConnection conn, String gaName) {
    System.err.println("L139: game " + gaName + " remove " + conn); // JM TEMP
    Vector members = getMembers(gaName);

    if ((members != null)) {
      members.removeElement(conn);

      // Check version of remaining members
      if (!members.isEmpty()) {
        StringConnection c = (StringConnection) members.firstElement();
        int lowVers = c.getVersion();
        int highVers = lowVers;
        for (int i = members.size() - 1; i > 1; --i) {
          c = (StringConnection) members.elementAt(i);
          int v = c.getVersion();
          if (v < lowVers) lowVers = v;
          if (v > highVers) highVers = v;
        }
        SOCGame ga = getGameData(gaName);
        ga.clientVersionLowest = lowVers;
        ga.clientVersionHighest = highVers;
        ga.hasOldClients = (lowVers < Version.versionNumber());
      }
    }
  }
Esempio n. 15
1
    /** 从连接池获得一个可用连接.如没有空闲的连接且当前连接数小于最大连接 数限制,则创建新连接.如原来登记为可用的连接不再有效,则从向量删除之, 然后递归调用自己以尝试新的可用连接. */
    public synchronized Connection getConnection() {
      Connection con = null;
      if (freeConnections.size() > 0) {
        // 获取向量中第一个可用连接
        con = (Connection) freeConnections.firstElement();
        freeConnections.removeElementAt(0);
        try {
          if (con.isClosed()) {
            System.out.println("从连接池" + id + "删除一个无效连接");
            System.out.println("从连接池" + id + "删除一个无效连接");
            // 递归调用自己,尝试再次获取可用连接
            con = getConnection();
          }
        } catch (SQLException e) {
          System.out.println("从连接池" + id + "删除一个无效连接时错误");
          System.out.println("从连接池" + id + "删除一个无效连接出错");
          // 递归调用自己,尝试再次获取可用连接
          con = getConnection();
        }
        if (freeConnections.size() > maxConn) {
          System.out.println(" 删除一个溢出连接 ");
          releaseOne();
        }
      } else if ((maxConn == 0) || (freeConnections.size() < maxConn)) {
        con = newConnection();
      }

      return con;
    }
 @Override
 public boolean contains(JComponent a, int b, int c) {
   for (int i = 1; i < numberOfUIs; i++) {
     ((ComponentUI) uis.get(i)).contains(a, b, c);
   }
   return ((ComponentUI) uis.firstElement()).contains(a, b, c);
 }
Esempio n. 17
1
  /**
   * Uses a Vector of TransformerHandlers to pipe XML input document through a series of 1 or more
   * transformations. Called by {@link #pipeDocument}.
   *
   * @param vTHandler Vector of Transformation Handlers (1 per stylesheet).
   * @param source absolute URI to XML input
   * @param target absolute path to transformation output.
   */
  public void usePipe(Vector vTHandler, String source, String target)
      throws TransformerException, TransformerConfigurationException, FileNotFoundException,
          IOException, SAXException, SAXNotRecognizedException {
    XMLReader reader = XMLReaderFactory.createXMLReader();
    TransformerHandler tHFirst = (TransformerHandler) vTHandler.firstElement();
    reader.setContentHandler(tHFirst);
    reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHFirst);
    for (int i = 1; i < vTHandler.size(); i++) {
      TransformerHandler tHFrom = (TransformerHandler) vTHandler.elementAt(i - 1);
      TransformerHandler tHTo = (TransformerHandler) vTHandler.elementAt(i);
      tHFrom.setResult(new SAXResult(tHTo));
    }
    TransformerHandler tHLast = (TransformerHandler) vTHandler.lastElement();
    Transformer trans = tHLast.getTransformer();
    Properties outputProps = trans.getOutputProperties();
    Serializer serializer = SerializerFactory.getSerializer(outputProps);

    FileOutputStream out = new FileOutputStream(target);
    try {
      serializer.setOutputStream(out);
      tHLast.setResult(new SAXResult(serializer.asContentHandler()));
      reader.parse(source);
    } finally {
      // Always clean up the FileOutputStream,
      // even if an exception was thrown in the try block
      if (out != null) out.close();
    }
  }
Esempio n. 18
1
 public void redrawTree(boolean doRepaint) {
   displayText = false;
   if (argument == null) return;
   if (argument.isMultiRoots()) {
     argument.deleteDummyRoot();
     argument.setMultiRoots(false);
   }
   TreeVertex root = null;
   Vector roots = argument.getTree().getRoots();
   if (roots.size() > 1) {
     if (argument.getDummyRoot() == null) {
       argument.addDummyRoot(roots);
     }
     root = argument.getDummyRoot();
   } else if (roots.size() == 1) {
     root = (TreeVertex) roots.firstElement();
   }
   // if root == null, the entire tree has been erased,
   // so call emptyTree() to clean things up and
   // clear the display
   if (root == null) {
     argument.emptyTree(false);
   } else {
     calcTreeShape(root);
   }
   if (doRepaint) {
     repaint();
   }
   /*
   if (displayFrame.getMainDiagramPanel() == this)
   {
     searchFrame.updateDisplays(false);
   }
    */
 }
  /**
   * Action method invoked when an event triggers this action.
   *
   * <p>The {@link #_compartment} instance variable defines the action to take, and the {@link
   * #_display} instance variable whether it should set visibility or note.
   *
   * <p><em>Note</em>. The {@link #_display} instance variable is really redundant. Its value is
   * implied by the operation.
   *
   * @param ae The event that triggered us.
   */
  public void actionPerformed(ActionEvent ae) {

    // Only do anything if we have a single item selected (surely this
    // should work for multiple selections as well?).

    Vector sels = Globals.curEditor().getSelectionManager().selections();

    if (sels.size() == 1) {
      Selection sel = (Selection) sels.firstElement();
      Fig f = sel.getContent();

      // Perform the action

      if (_compartment.equals("Show Attribute Compartment")) {
        ((FigClass) f).setAttributeVisible(_display);
      } else if (_compartment.equals("Hide Attribute Compartment")) {
        ((FigClass) f).setAttributeVisible(_display);
      } else if (_compartment.equals("Show Operation Compartment")
          || _compartment.equals("Hide Operation Compartment")) {
        if (f instanceof FigClass) ((FigClass) f).setOperationVisible(_display);
        if (f instanceof FigInterface) ((FigInterface) f).setOperationVisible(_display);
      } else if (_compartment.equals("Show Extension Point Compartment")) {
        ((FigUseCase) f).setExtensionPointVisible(_display);
      } else if (_compartment.equals("Hide Extension Point Compartment")) {
        ((FigUseCase) f).setExtensionPointVisible(_display);
      } else if (_compartment.equals("Show All Compartments")) {
        ((FigClass) f).setAttributeVisible(_display);
        ((FigClass) f).setOperationVisible(_display);
      } else {
        ((FigClass) f).setAttributeVisible(_display);
        ((FigClass) f).setOperationVisible(_display);
      }
    }
  }
Esempio n. 20
1
 public static String list(Context c, Vector<BaseObject> objs) {
   String ret = new String();
   if (objs.size() == 0) return ret;
   if (objs.size() == 1) {
     ret = objs.firstElement().getName();
     return ret;
   }
   if (objs.size() == 2) {
     ret =
         objs.get(0).getName()
             + " "
             + c.getString(R.string.stringhandler_and1)
             + " "
             + objs.get(1).getName();
     return ret;
   }
   for (int i = 0; i < objs.size() - 1; i++) {
     ret += objs.get(i).getName();
     if (i < objs.size() - 2) {
       ret += c.getString(R.string.stringhandler_comma);
       ret += " ";
     } else {
       ret += c.getString(R.string.stringhandler_and2);
       ret += " ";
     }
   }
   ret += objs.lastElement().getName();
   return ret;
 }
Esempio n. 21
1
 public void viewChange(View new_view) {
   Vector mbrship;
   if (new_view != null && (mbrship = new_view.getMembers()) != null) {
     tree._put(SEP, "members", mbrship);
     tree._put(SEP, "coordinator", mbrship.firstElement());
   }
 }
 @Override
 public int getAccessibleChildrenCount(JComponent a) {
   for (int i = 1; i < numberOfUIs; i++) {
     ((ComponentUI) uis.get(i)).getAccessibleChildrenCount(a);
   }
   return ((ComponentUI) uis.firstElement()).getAccessibleChildrenCount(a);
 }
Esempio n. 23
0
  /* (non-Javadoc)
   * @see java.lang.Runnable#run()
   */
  public void run() {

    //		log.debug("running");

    setRunning(true);

    while (true) {

      ResourceRequest request = null;
      boolean reserved = false;

      if (queue.isEmpty()) {
        setRunning(false);
        //				log.debug("finished");
        return;
      }

      request = (ResourceRequest) queue.firstElement();

      reserved = manager.requestResources(request);
      if (reserved) {
        queue.remove(request);
        notifyResourceWaiter(request);
        log.info("grantResources: " + request.getRrId());
      } else {
        waitForResources();
      }
    }
  }
Esempio n. 24
0
  /**
   * Compiles a set of stylesheets pointed to by a Vector of URLs
   *
   * @param stylesheets A Vector containing URLs pointing to the stylesheets
   * @return 'true' if the compilation was successful
   */
  public boolean compile(Vector stylesheets) {
    // Get the number of stylesheets (ie. URLs) in the vector
    final int count = stylesheets.size();

    // Return straight away if the vector is empty
    if (count == 0) return true;

    // Special handling needed if the URL count is one, becuase the
    // _className global must not be reset if it was set explicitly
    if (count == 1) {
      final Object url = stylesheets.firstElement();
      if (url instanceof URL) return compile((URL) url);
      else return false;
    } else {
      // Traverse all elements in the vector and compile
      final Enumeration urls = stylesheets.elements();
      while (urls.hasMoreElements()) {
        _className = null; // reset, so that new name will be computed
        final Object url = urls.nextElement();
        if (url instanceof URL) {
          if (!compile((URL) url)) return false;
        }
      }
    }
    return true;
  }
		/**
		 * 从连接池获得一个空闲的连接. 如没有空闲的连接且当前连接数小于最大连接数限制, 则创建新连接.
		 * 如原来登记为空闲的连接不再有效,则从向量Vector中删除, 然后递归调用以尝试新的空闲连接.
		 */
		public synchronized Connection getConnection() {
			Connection con = null;
			if (freeConnections.size() > 0) {
				// 获取向量中第一个可用连接
				con = (Connection) freeConnections.firstElement();
				freeConnections.removeElementAt(0);
				try {
					if (con.isClosed()) {
						log("从连接池" + name + "删除一个无效连接");
						// 递归调用自己,尝试再次获取可用连接
						con = getConnection();
					}
				} catch (SQLException e) {
					log("从连接池" + name + "删除一个无效连接");
					// 递归调用自己,尝试再次获取可用连接
					con = getConnection();
				}
			} else if (maxConn == 0 || checkedOut < maxConn) {
				con = newConnection();
			}
			if (con != null) {
				checkedOut++;
			}
			return con;
		}
 @Override
 public Dimension getPreferredSize(JComponent a) {
   for (int i = 1; i < numberOfUIs; i++) {
     ((ComponentUI) uis.get(i)).getPreferredSize(a);
   }
   return ((ComponentUI) uis.firstElement()).getPreferredSize(a);
 }
 @Override
 public Accessible getAccessibleChild(JComponent a, int b) {
   for (int i = 1; i < numberOfUIs; i++) {
     ((ComponentUI) uis.get(i)).getAccessibleChild(a, b);
   }
   return ((ComponentUI) uis.firstElement()).getAccessibleChild(a, b);
 }
Esempio n. 28
0
  public DepthSetting getInterpolatedDepthSetting(double z) throws TwoPhotonException {
    // find matching entry in the list

    if (settings_.size() < 1) throw new TwoPhotonException("Depth List Empty!");

    DepthSetting ds = new DepthSetting();
    ds.z = z;

    int idx = Collections.binarySearch(settings_, ds);

    //      System.out.println("Index: " + idx + "Z: " + z);

    if (idx >= 0) return settings_.get(idx);
    else if (idx == -1) {
      return settings_.firstElement();
    } else if (-idx == (settings_.size() + 1)) {
      return settings_.lastElement();
    } else {
      DepthSetting dsLow = settings_.get(-idx - 1);
      DepthSetting dsHigh = settings_.get(-idx - 2);
      ds.resizePMT(dsLow.pmts.length);
      double zFactor = (z - dsLow.z) / (dsHigh.z - dsLow.z);
      ds.eomVolts1_ = linearInterpolation(dsLow.eomVolts1_, dsHigh.eomVolts1_, zFactor);
      //         System.out.println("VL=" + dsLow.eomVolts1_ + ", VH=" + dsHigh.eomVolts1_ + ", Z="
      // + z + ", ZL=" + dsLow.z + ", ZH=" + dsHigh.z);
      //         System.out.println("V=" + ds.eomVolts1_);
      ds.eomVolts2_ = linearInterpolation(dsLow.eomVolts2_, dsHigh.eomVolts2_, zFactor);
      for (int i = 0; i < ds.pmts.length; i++) {
        ds.pmts[i].name = new String(dsLow.pmts[i].name);
        ds.pmts[i].volts = linearInterpolation(dsLow.pmts[i].volts, dsHigh.pmts[i].volts, zFactor);
      }
      return ds;
    }
  }
Esempio n. 29
0
  protected String toGetResponse(String cmd, Vector<String> buf) {
    if (buf.size() == 0) return "No response is received.";
    String response = buf.firstElement();
    if (CommonUtils.isNullOrSpace(response)) return "Cannot get response for cmd " + cmd;

    String[] cmds = cmd.split("\n");
    String[] resps = response.split(CommonUtils.getReturnChars(response));
    StringBuffer sb = new StringBuffer();
    sb.append("OK:");

    int j = 0;
    boolean first = true;
    for (String command : cmds) {
      if (CommonUtils.isNullOrSpace(command)) continue;
      for (int i = j; i < resps.length; i++) {
        if (resps[i].trim().endsWith(command.trim())) {
          if (command.equals(CXT7090Constants.CXT7090MCMD_CMD_ATOMMODE)
              || command.equals(CXT7090Constants.CXT7090MCMD_CMD_EXIT)) {
            j = i + 1;
            break;
          }
          if (i + 2 < resps.length) {
            if (!resps[i + 1].startsWith(CXT7090Constants.CXT7090M_NODE_COMMAND_SUCCESS)
                && !resps[i + 2].startsWith(CXT7090Constants.CXT7090M_NODE_COMMAND_SUCCESS)) {
              return "unexcepted response end for command --> " + command;
            } else {
              String[] tokens = command.split(" ");
              String param = tokens[tokens.length - 1];
              if (mVars.contains(param)) {
                if (first) sb.append(param + CommonConstants.EQUAL + resps[i + 1].trim());
                else
                  sb.append(
                      CommonConstants.CAMA + param + CommonConstants.EQUAL + resps[i + 1].trim());
                first = false;
              } else if (mTmpParams.size() > 0) {
                if (this.mTmpParams.firstEntry().getValue().equals(param)) {
                  if (first)
                    sb.append(
                        CommonConstants.CATS_DYNAMIC_ATTRIBUTE_NAME
                            + CommonConstants.EQUAL
                            + resps[i + 1].trim());
                  else
                    sb.append(
                        CommonConstants.CAMA
                            + CommonConstants.CATS_DYNAMIC_ATTRIBUTE_NAME
                            + CommonConstants.EQUAL
                            + resps[i + 1].trim());
                  first = false;
                }
              }
              j = i + 1;
              break;
            }
          }
        }
      }
    }
    return sb.toString();
  }
  /**
   * Function that prints all the class variables to the console, except the path traveled by the
   * pointer during the trial.
   */
  public void printInfoWithoutPath() {
    double distancePoints;

    if (path.size() == 0) {
      distancePoints = 0.0;
    } else {
      distancePoints = calculateDistanceBetweenPoints(path.firstElement(), path.lastElement());
    }

    System.out.println(
        "The device number used was: "
            + device
            + ".\n"
            + "The User ID was: "
            + userId
            + ".\n"
            + "The current sequence number is: "
            + sequenceNumber
            + "\n"
            + "and belongs to block number: "
            + blockNumber
            + ".\n\n"
            + "In this trial "
            + numberOfClicks
            + " click(s) were performed.\n"
            + "There were "
            + numberOfCircles
            + " circles,\n"
            + "and were "
            + distanceBetweenCirclesAndFrameCenter
            + " pixels away from the center of the frame.\n"
            + "The starting circle's center was in pixel: <"
            + getStartingCircleCenter().getXCoordinate()
            + ","
            + getStartingCircleCenter().getYCoordinate()
            + ">\n"
            + "and the ending one was in pixel: <"
            + getEndingCircleCenter().getXCoordinate()
            + ","
            + getEndingCircleCenter().getYCoordinate()
            + ">\n"
            + "(whose ID is: "
            + circleId
            + " ).\n"
            + "As such, they were: "
            + distanceBetweenCircles
            + " pixels away from each other.\n"
            + "Both had a diameter of "
            + targetWidth
            + " pixels, which means "
            + ((double) targetWidth) / 2.0
            + " pixels as radius.\n"
            + "This trial took "
            + elapsedTime
            + " milisegundos to perform.\n"
            + "The first and last point recovered were "
            + distancePoints
            + " pixels away from each other.\n");
  }