Esempio n. 1
0
 public void drawOrbits(ArrayList alObjectsArchive) {
   //  println("SIZE:" + alObjectsArchive.size());
   //  ArrayList alObjectsArchive = timeline.getObjectStateArchive();
   ArrayList alPrevPos = new ArrayList();
   ArrayList alColors = new ArrayList();
   alColors.add(color(255, 0, 0));
   alColors.add(color(255, 255, 0));
   alColors.add(color(255, 0, 255));
   //  for (int i = timeline.getTimeIdx(); i >= 0 && i > (timeline.getTimeIdx() - 1 - 100); i--)
   for (int i = 0; i < alObjectsArchive.size(); i++) {
     ArrayList objects = (ArrayList) alObjectsArchive.get(i);
     for (int j = 0; j < objects.size(); j++) {
       CelestialObject obj = (CelestialObject) objects.get(j);
       //      CelestialObject obj = (CelestialObject)objects.get(1);
       PVector pos = obj.getPosition();
       //      stroke(0, 0, 255);
       stroke((Integer) alColors.get(j));
       if (alPrevPos.size() == objects.size()) {
         PVector prevPos = (PVector) alPrevPos.get(j);
         line(prevPos.x, prevPos.y, pos.x, pos.y);
         alPrevPos.set(j, pos);
       } else alPrevPos.add(pos);
     }
   }
 }
  public void setup() {
    size(600, 400);
    smooth();
    f = createFont("Georgia", 12, true);

    obstacles = new ArrayList();
    boids = new ArrayList();

    // A little algorithm to pick a bunch of random obstacles that don't overlap
    for (int i = 0; i < 100; i++) {
      float x = random(width);
      float y = random(height);
      float r = random(50 - i / 2, 50);
      boolean ok = true;
      for (int j = 0; j < obstacles.size(); j++) {
        Obstacle o = (Obstacle) obstacles.get(j);
        if (dist(x, y, o.loc.x, o.loc.y) < o.radius + r + 20) {
          ok = false;
        }
      }
      if (ok) obstacles.add(new Obstacle(x, y, r));
    }

    // Starting with three boids
    boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.2f));
    boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.1f));
    boids.add(new Boid(new PVector(random(width), random(height)), 2f, 0.05f));
  }
Esempio n. 3
0
  /** Generates array of XContour from local contours and modules. Used for TTF building. */
  private XContour[] toContours() {
    XContour[] retval;
    ArrayList<XContour> list = new ArrayList<>();
    XContour[] contours = m_glyph.getBody().getContour();
    for (int i = 0; i < contours.length; i++) {
      EContour contour = (EContour) contours[i];
      list.add(contour.toQuadratic());
    } // for i

    XModule[] modules = m_glyph.getBody().getModule();
    for (int i = 0; i < modules.length; i++) {
      EModuleInvoke module = (EModuleInvoke) modules[i];

      // push and pop happens inside toContour
      list.add(module.toContour(new AffineTransform()));
    } // for i

    if (list.size() == 0) return null;

    retval = new XContour[list.size()];
    for (int i = 0; i < list.size(); i++) {
      retval[i] = list.get(i);
    } // for i

    return retval;
  }
Esempio n. 4
0
  private boolean invokeMethod(String line, PrintWriter out, Method method, String[] fields)
      throws IllegalAccessException, InvocationTargetException {
    ArrayList<Object> methodArguments = new ArrayList<Object>();

    Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length == 2
        && parameterTypes[0] == PrintWriter.class
        && parameterTypes[1] == String.class) {
      // FIXME: there must be a better way to say "I want to parse the line myself."
      methodArguments.add(out);
      methodArguments.add(line);
    } else {
      int nextField = 1;
      for (Class<?> parameterType : parameterTypes) {
        if (parameterType == PrintWriter.class) {
          methodArguments.add(out);
        } else if (parameterType == String.class) {
          methodArguments.add(fields[nextField++]);
        }
        // FIXME: support other common types. "int" seems a likely first candidate.
      }
    }

    method.invoke(handler, methodArguments.toArray());
    return true;
  }
Esempio n. 5
0
    // Used in compiling to mark out "dirty" areas of the code; ie, comments and string literals.
    // These dirty areas don't get their syntax highlighted or any special treatment.
    // @returns: pairs of integers that represent dirty boundaries.
    private ArrayList<Integer> getDirty(String code) {
      ArrayList<Integer> dirtyBounds = new ArrayList<>();

      // Handles string literals
      int j = -1;
      while (true) {
        j = code.indexOf("\"", j + 1);
        if (j < 0) break;
        // Ignore escaped characters
        if (!code.substring(j - 1, j).equals("\\")) dirtyBounds.add(j);
      }

      // End of line comments
      j = -1;
      while (true) {
        j = code.indexOf("//", j + 1);
        if (j < 0) break;
        dirtyBounds.add(j);
        // If there's no newline, then the comment lasts for the length of the code
        dirtyBounds.add(
            code.indexOf("\n", j + 1) == -1 ? code.length() : code.indexOf("\n", j + 1));
      }

      // Block comments (and javadoc comments)
      j = -1;
      while (true) {
        j = code.indexOf("/*", j + 1);
        if (j < 0) break;
        dirtyBounds.add(j);
        dirtyBounds.add(code.indexOf("*/", j + 1));
      }

      return dirtyBounds;
    }
 /**
  * Recursively gets the ID of required features of this feature and adds them to the list
  *
  * @param model feature model to get requirements of
  * @param requiredFeatureList collector for the required features
  */
 private void getFeatureDependencies(
     IFeatureModel model, IFeatureModel[] allFeatures, ArrayList requiredFeatureList) {
   IFeature feature = model.getFeature();
   IFeatureImport[] featureImports = feature.getImports();
   for (int i = 0; i < featureImports.length; i++) {
     if (featureImports[i].getType() == IFeatureImport.FEATURE) {
       for (int j = 0; j < allFeatures.length; j++) {
         if (allFeatures[j].getFeature().getId().equals(featureImports[i].getId())) {
           requiredFeatureList.add(allFeatures[j]);
           getFeatureDependencies(allFeatures[j], allFeatures, requiredFeatureList);
           break;
         }
       }
     }
   }
   IFeatureChild[] featureIncludes = feature.getIncludedFeatures();
   for (int i = 0; i < featureIncludes.length; i++) {
     requiredFeatureList.add(featureIncludes[i].getId());
     for (int j = 0; j < allFeatures.length; j++) {
       if (allFeatures[j].getFeature().getId().equals(featureIncludes[i].getId())) {
         requiredFeatureList.add(allFeatures[j]);
         getFeatureDependencies(allFeatures[j], allFeatures, requiredFeatureList);
         break;
       }
     }
   }
 }
Esempio n. 7
0
  void isConnectable(SelectionKey k) {
    EventableSocketChannel ec = (EventableSocketChannel) k.attachment();
    long b = ec.getBinding();

    try {
      if (ec.finishConnecting()) eventCallback(b, EM_CONNECTION_COMPLETED, null);
      else UnboundConnections.add(b);
    } catch (IOException e) {
      UnboundConnections.add(b);
    }
  }
Esempio n. 8
0
  public void RememberState() // 记录棋盘
      {
    char[][] states = new char[8][8];
    boolean[][] takens = new boolean[8][8];

    for (int i = 0; i < 8; i++)
      for (int j = 0; j < 8; j++) {
        states[i][j] = cell[i][j].state;
        takens[i][j] = cell[i][j].taken;
      }
    stateList.add(states);
    takenList.add(takens);
  }
Esempio n. 9
0
  List keepUniqueTerms(List hypernymsList) {
    ArrayList uniqueList = new ArrayList();
    ArrayList uniqueHypernymList = new ArrayList();
    for (int i = 0; i < hypernymsList.size(); i++) {
      IWord word = (IWord) hypernymsList.get(i);
      if (!uniqueList.contains(word.getLemma().toString())) {
        uniqueList.add(word.getLemma().toString());
        uniqueHypernymList.add(word);
      }
    }

    return uniqueHypernymList;
  }
Esempio n. 10
0
  private ArrayList GetFolderTree(String s_Dir, String s_Flag, int n_Indent, int n_TreeIndex) {
    String s_List = "";
    ArrayList aSubFolders = new ArrayList();

    File file = new File(s_Dir);
    File[] filelist = file.listFiles();

    if (filelist != null && filelist.length > 0) {
      for (int i = 0; i < filelist.length; i++) {
        if (filelist[i].isDirectory()) {
          aSubFolders.add(filelist[i].getName());
        }
      }

      int n_Count = aSubFolders.size();
      String s_LastFlag = "";
      String s_Folder = "";
      for (int i = 1; i <= n_Count; i++) {
        if (i < n_Count) {
          s_LastFlag = "0";
        } else {
          s_LastFlag = "1";
        }

        s_Folder = aSubFolders.get(i - 1).toString();
        s_List =
            s_List
                + "arr"
                + s_Flag
                + "["
                + String.valueOf(n_TreeIndex)
                + "]=new Array(\""
                + s_Folder
                + "\","
                + String.valueOf(n_Indent)
                + ", "
                + s_LastFlag
                + ");\n";
        n_TreeIndex = n_TreeIndex + 1;
        ArrayList a_Temp =
            GetFolderTree(s_Dir + s_Folder + sFileSeparator, s_Flag, n_Indent + 1, n_TreeIndex);
        s_List = s_List + a_Temp.get(0).toString();
        n_TreeIndex = Integer.valueOf(a_Temp.get(1).toString()).intValue();
      }
    }

    ArrayList a_Return = new ArrayList();
    a_Return.add(s_List);
    a_Return.add(String.valueOf(n_TreeIndex));
    return a_Return;
  }
Esempio n. 11
0
  void isWritable(SelectionKey k) {
    EventableChannel ec = (EventableChannel) k.attachment();
    long b = ec.getBinding();

    if (ec.isWatchOnly()) {
      if (ec.isNotifyWritable()) eventCallback(b, EM_CONNECTION_NOTIFY_WRITABLE, null);
    } else {
      try {
        if (!ec.writeOutboundData()) UnboundConnections.add(b);
      } catch (IOException e) {
        UnboundConnections.add(b);
      }
    }
  }
Esempio n. 12
0
 private boolean startLauncher(File dir) {
   try {
     Runtime rt = Runtime.getRuntime();
     ArrayList<String> command = new ArrayList<String>();
     command.add("java");
     command.add("-jar");
     command.add("Launcher.jar");
     String[] cmdarray = command.toArray(new String[command.size()]);
     Process proc = rt.exec(cmdarray, null, dir);
     return true;
   } catch (Exception ex) {
     System.err.println("Unable to start the Launcher program.\n" + ex.getMessage());
     return false;
   }
 }
Esempio n. 13
0
  void close() {
    try {
      if (mySelector != null) mySelector.close();
    } catch (IOException e) {
    }
    mySelector = null;

    // run down open connections and sockets.
    Iterator<ServerSocketChannel> i = Acceptors.values().iterator();
    while (i.hasNext()) {
      try {
        i.next().close();
      } catch (IOException e) {
      }
    }

    // 29Sep09: We create an ArrayList of the existing connections, then iterate over
    // that to call unbind on them. This is because an unbind can trigger a reconnect,
    // which will add to the Connections HashMap, causing a ConcurrentModificationException.
    // XXX: The correct behavior here would be to latch the various reactor methods to return
    // immediately if the reactor is shutting down.
    ArrayList<EventableChannel> conns = new ArrayList<EventableChannel>();
    Iterator<EventableChannel> i2 = Connections.values().iterator();
    while (i2.hasNext()) {
      EventableChannel ec = i2.next();
      if (ec != null) {
        conns.add(ec);
      }
    }
    Connections.clear();

    ListIterator<EventableChannel> i3 = conns.listIterator(0);
    while (i3.hasNext()) {
      EventableChannel ec = i3.next();
      eventCallback(ec.getBinding(), EM_CONNECTION_UNBOUND, null);
      ec.close();

      EventableSocketChannel sc = (EventableSocketChannel) ec;
      if (sc != null && sc.isAttached()) DetachedConnections.add(sc);
    }

    ListIterator<EventableSocketChannel> i4 = DetachedConnections.listIterator(0);
    while (i4.hasNext()) {
      EventableSocketChannel ec = i4.next();
      ec.cleanup();
    }
    DetachedConnections.clear();
  }
Esempio n. 14
0
  void isReadable(SelectionKey k) {
    EventableChannel ec = (EventableChannel) k.attachment();
    long b = ec.getBinding();

    if (ec.isWatchOnly()) {
      if (ec.isNotifyReadable()) eventCallback(b, EM_CONNECTION_NOTIFY_READABLE, null);
    } else {
      myReadBuffer.clear();

      try {
        ec.readInboundData(myReadBuffer);
        myReadBuffer.flip();
        if (myReadBuffer.limit() > 0) {
          if (ProxyConnections != null) {
            EventableChannel target = ProxyConnections.get(b);
            if (target != null) {
              ByteBuffer myWriteBuffer = ByteBuffer.allocate(myReadBuffer.limit());
              myWriteBuffer.put(myReadBuffer);
              myWriteBuffer.flip();
              target.scheduleOutboundData(myWriteBuffer);
            } else {
              eventCallback(b, EM_CONNECTION_READ, myReadBuffer);
            }
          } else {
            eventCallback(b, EM_CONNECTION_READ, myReadBuffer);
          }
        }
      } catch (IOException e) {
        UnboundConnections.add(b);
      }
    }
  }
Esempio n. 15
0
  @Override
  public void sendMessage(Message message) throws MessagingException {
    ArrayList<Address> addresses = new ArrayList<Address>();
    {
      addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO)));
      addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC)));
      addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC)));
    }
    message.setRecipients(RecipientType.BCC, null);

    HashMap<String, ArrayList<String>> charsetAddressesMap =
        new HashMap<String, ArrayList<String>>();
    for (Address address : addresses) {
      String addressString = address.getAddress();
      String charset = MimeUtility.getCharsetFromAddress(addressString);
      ArrayList<String> addressesOfCharset = charsetAddressesMap.get(charset);
      if (addressesOfCharset == null) {
        addressesOfCharset = new ArrayList<String>();
        charsetAddressesMap.put(charset, addressesOfCharset);
      }
      addressesOfCharset.add(addressString);
    }

    for (Map.Entry<String, ArrayList<String>> charsetAddressesMapEntry :
        charsetAddressesMap.entrySet()) {
      String charset = charsetAddressesMapEntry.getKey();
      ArrayList<String> addressesOfCharset = charsetAddressesMapEntry.getValue();
      message.setCharset(charset);
      sendMessageTo(addressesOfCharset, message);
    }
  }
  public ArrayList<String> parseXML() throws Exception {
    ArrayList<String> ret = new ArrayList<String>();

    handshake();

    URL url =
        new URL(
            "http://mangaonweb.com/page.do?cdn="
                + cdn
                + "&cpn=book.xml&crcod="
                + crcod
                + "&rid="
                + (int) (Math.random() * 10000));
    String page = DownloaderUtils.getPage(url.toString(), "UTF-8", cookies);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(page));
    Document d = builder.parse(is);
    Element doc = d.getDocumentElement();

    NodeList pages = doc.getElementsByTagName("page");
    total = pages.getLength();
    for (int i = 0; i < pages.getLength(); i++) {
      Element e = (Element) pages.item(i);
      ret.add(e.getAttribute("path"));
    }

    return (ret);
  }
    public void trace(float x, float y) {

      println(x);

      if (frameCounter > 2 && mousePressed) {
        coords.add(new PVector(x, y));
        frameCounter = 0;
        if (coordCounter > 0) {
          PVector tempCoord = (PVector) coords.get(coordCounter - 1);
          line(x, y, tempCoord.x, tempCoord.y);
        }
        coordCounter++;
      }
      // println(coordCounter);

      for (int i = 0; i < coords.size(); i++) {
        PVector tempCoordnear = (PVector) coords.get(i);
        float coordDist = dist(x, y, tempCoordnear.x, tempCoordnear.y);
        if (coordDist < distance) {
          stroke(255, 0, 0);
          line(x, y, tempCoordnear.x, tempCoordnear.y);
        }
      }
      frameCounter++;
    }
  /** Creates the server. */
  public static void main(String args[]) {
    client = null;
    ServerSocket server = null;

    try {
      System.out.print("\nCreating Server...\n");
      // creates the server
      server = new ServerSocket(8008);
      System.out.print("Created\n");
      // get the ip Address and the host name.
      InetAddress localAddr = InetAddress.getLocalHost();
      System.out.println("IP address: " + localAddr.getHostAddress());
      System.out.println("Hostname: " + localAddr.getHostName());

    } catch (IOException e) {
      // sends a
      System.out.println("IO" + e);
    }

    // constantly checks for a new aocket trying to attach itself to the trhead
    while (true) {
      try {
        client = server.accept();
        // create a new thread.
        FinalMultiThread thr = new FinalMultiThread(client);
        System.out.print(client.getInetAddress() + " : " + thr.getUserName() + "\n");
        CliList.add(thr);
        current++;
        thr.start();
      } catch (IOException e) {
        System.out.println(e);
      }
    }
  }
Esempio n. 19
0
 private boolean processURL(URL url, String baseDir, StatusWindow status) throws IOException {
   if (processedLinks.contains(url)) {
     return false;
   } else {
     processedLinks.add(url);
   }
   URLConnection connection = url.openConnection();
   InputStream in = new BufferedInputStream(connection.getInputStream());
   ArrayList list = processPage(in, baseDir, url);
   if ((status != null) && (list.size() > 0)) {
     status.setMaximum(list.size());
   }
   for (int i = 0; i < list.size(); i++) {
     if (status != null) {
       status.setMessage(Utils.trimFileName(list.get(i).toString(), 40), i);
     }
     if ((!((String) list.get(i)).startsWith("RUN"))
         && (!((String) list.get(i)).startsWith("SAVE"))
         && (!((String) list.get(i)).startsWith("LOAD"))) {
       processURL(
           new URL(url.getProtocol(), url.getHost(), url.getPort(), (String) list.get(i)),
           baseDir,
           status);
     }
   }
   in.close();
   return true;
 }
Esempio n. 20
0
  public TTGlyph toSimpleGlyph() {
    // convert the file into array of contours
    XContour[] contours = toContours();
    if ((contours == null) && (!isRequiredGlyph())) {
      return null;
    } // if

    TTGlyph retval = new TTGlyph();
    retval.setSimple(true);
    retval.setAdvanceWidth(getAdvanceWidth());

    if (contours == null) {
      return retval;
    } // if

    ArrayList<EContourPoint> points = new ArrayList<>();
    for (int i = 0; i < contours.length; i++) {
      XContour contour = contours[i];
      XContourPoint[] contourPoints = contour.getContourPoint();
      for (int j = 0; j < contourPoints.length; j++) {
        points.add((EContourPoint) contourPoints[j]);
      } // for j
      retval.addEndPoint(points.size() - 1);
    } // for i

    for (EContourPoint point : points) {
      loadContourPoint(retval, point);
    } // for point

    boolean hasGridfit = false;
    // I need int i here.
    for (int i = 0; i < points.size(); i++) {
      EContourPoint point = points.get(i);

      if (!point.isRounded()) {
        continue;
      } // if

      hasGridfit = true;
      loadGridfit(retval, point, i);
    } // for i

    if (hasGridfit) {
      retval.addInstruction(TTGlyph.IUP1);
      retval.addInstruction(TTGlyph.IUP0);
    } // if

    // I need int i here.
    for (int i = 0; i < points.size(); i++) {
      EContourPoint point = points.get(i);
      if (point.getHint().length == 0) {
        continue;
      } // if

      loadHint(retval, point, i);
    } // for i

    return retval;
  }
Esempio n. 21
0
 public synchronized void addClientData(ClientData cd) {
   try {
     clientList.add(cd);
     sendList();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 22
0
    public ArrayList getPastObjectStates() {
      ArrayList alPast = new ArrayList();
      for (int i = intTimeIdx; i > 0 && i > intTimeIdx - 100; i--) {
        alPast.add(this.alObjectStateArchive.get(i));
      }

      return alPast;
    }
Esempio n. 23
0
 /**
  * Propagate an incoming trame to all the other ports of the switch
  *
  * @param msg the incoming trame
  * @param from the receiving port
  */
 public void propagate(Trame msg, OurPort from) {
   for (int i = 0; i < ports.length; ++i) {
     if (ports[i] != null && !ports[i].equals(from) && !dejaVu(msg)) {
       ports[i].send(msg);
     }
   }
   list.add(msg);
 }
Esempio n. 24
0
    // Does a deepcopy of an array list
    public static ArrayList cloneArrayList(ArrayList al) {
      ArrayList alNew = new ArrayList(al.size());
      for (int i = 0; i < al.size(); i++) {
        alNew.add(((CelestialObject) al.get(i)).clone());
      }

      return alNew;
    }
Esempio n. 25
0
 private void tickDown(Player z, Element x, ArrayList<Element> d) {
   if ((z.getY() - (x.getY() - 15)) > 0
       && (z.getY() - (x.getY() - 15)) < 15
       && (z.getX() - x.getX()) < 10
       && (z.getX() - x.getX()) > -5) {
     if (z.getCol().equals(x.getCol())) {
       d.add(x);
     } else if (x.getCol().equals(BLUE)) {
       if (meta.equals(NO)) {
         meta = WINNERS;
       } else {
         d.add(x);
       }
     } else {
       z.setY(z.getY() - (z.getY() - (x.getY() - 15)));
     }
   }
 }
Esempio n. 26
0
    // Does a deepcopy of an array list
    public ArrayList cloneArrayList(ArrayList al) {
      ArrayList alNew = new ArrayList(al.size());
      for (int i = 0; i < al.size(); i++) {
        PVector pv = (PVector) al.get(i);
        alNew.add(new PVector(pv.x, pv.y));
      }

      return alNew;
    }
 /** {@inheritDoc} */
 public void addHostListener(HostListener listener) {
   synchronized (listeners) {
     listeners.add(listener);
     if (task == null) {
       task = new NotifierTask();
       timer.schedule(task, 0, interval);
     }
   }
 }
Esempio n. 28
0
 public boolean addAt(int index, Object e) {
   if (index < 0) index = size();
   while (index > size()) {
     if (!add(Converter.convert(null, type))) return false;
   }
   if (type != null) e = Converter.convert(e, type);
   super.add(index, e);
   return true;
 }
Esempio n. 29
0
 public SocketChannel detachChannel(long sig) {
   EventableSocketChannel ec = (EventableSocketChannel) Connections.get(sig);
   if (ec != null) {
     UnboundConnections.add(sig);
     return ec.getChannel();
   } else {
     return null;
   }
 }
Esempio n. 30
0
 private static void readCaptchaFile(String fileName) {
   try {
     BufferedReader reader = new BufferedReader(new FileReader(new File(fileName)));
     String line;
     while ((line = reader.readLine()) != null) captchaList.add(line);
     reader.close();
   } catch (Exception exception) {
     throw new RuntimeException(exception);
   }
 }