Exemple #1
0
  public void run() {
    // each file is processed into a local hash table and then merged with the global results
    // this will cause much less contention on the global table, but still avoids a sequential
    // update
    Hashtable<String, Integer> local_results =
        new Hashtable<String, Integer>(WordCountJ.HASH_SIZE, WordCountJ.LF);
    // grab a file to work on
    String cf;
    while ((cf = files.poll()) != null) {
      try {
        BufferedReader input = new BufferedReader(new FileReader(cf));
        String text;
        // well go line-by-line... maybe this is not the fastest
        while ((text = input.readLine()) != null) {
          // parse words
          Matcher matcher = pattern.matcher(text);
          while (matcher.find()) {
            String word = matcher.group(1);
            if (local_results.containsKey(word)) {
              local_results.put(word, 1 + local_results.get(word));
            } else {
              local_results.put(word, 1);
            }
          }
        }
        input.close();
      } catch (Exception e) {
        System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage());
        return;
      }
      // merge local hashmap with shared one,could have a
      // seperate thread do this but that might be cheating

      Iterator<Map.Entry<String, Integer>> updates = local_results.entrySet().iterator();
      while (updates.hasNext()) {
        Map.Entry<String, Integer> kv = updates.next();
        String k = kv.getKey();
        Integer v = kv.getValue();
        synchronized (results) {
          if (results.containsKey(k)) {
            results.put(k, v + results.get(k));
          } else {
            results.put(k, v);
          }
        }
      }
      local_results.clear();
    }
  }
 public void persistentRequestError(final String id, final NodeMessage nm) {
   if (uploadModelItems.containsKey(id)) {
     final FrostUploadItem item = uploadModelItems.get(id);
     item.setEnabled(false);
     item.setState(FrostUploadItem.STATE_FAILED);
     item.setErrorCodeDescription(nm.getStringValue("CodeDescription"));
   } else if (downloadModelItems.containsKey(id)) {
     final FrostDownloadItem item = downloadModelItems.get(id);
     item.setEnabled(false);
     item.setState(FrostDownloadItem.STATE_FAILED);
     item.setErrorCodeDescription(nm.getStringValue("CodeDescription"));
   } else {
     System.out.println("persistentRequestError: ID not in any model: " + id);
   }
 }
Exemple #3
0
  /**
   * Callback method from _scanKeychain. If a trusted certificate is found, this method will be
   * called.
   */
  private void createTrustedCertEntry(
      String alias, long keychainItemRef, long creationDate, byte[] derStream) {
    TrustedCertEntry tce = new TrustedCertEntry();

    try {
      CertificateFactory cf = CertificateFactory.getInstance("X.509");
      InputStream input = new ByteArrayInputStream(derStream);
      X509Certificate cert = (X509Certificate) cf.generateCertificate(input);
      input.close();
      tce.cert = cert;
      tce.certRef = keychainItemRef;

      // Make a creation date.
      if (creationDate != 0) tce.date = new Date(creationDate);
      else tce.date = new Date();

      int uniqueVal = 1;
      String originalAlias = alias;

      while (entries.containsKey(alias.toLowerCase())) {
        alias = originalAlias + " " + uniqueVal;
        uniqueVal++;
      }

      entries.put(alias.toLowerCase(), tce);
    } catch (Exception e) {
      // The certificate will be skipped.
      System.err.println("KeychainStore Ignored Exception: " + e);
    }
  }
  public synchronized void messageReceived(int to, Message m) {

    DrainMsg mhMsg = (DrainMsg) m;

    log.debug(
        "incoming: localDest: "
            + to
            + " type:"
            + mhMsg.get_type()
            + " hops:"
            + (16 - mhMsg.get_ttl())
            + " seqNo:"
            + mhMsg.get_seqNo()
            + " source:"
            + mhMsg.get_source()
            + " finalDest:"
            + mhMsg.get_dest());

    // lets assume that the network cannot buffer more than 25 drain msgs from a single source at a
    // time (should be more than reasonable)
    if (seqNos.containsKey(new Integer(mhMsg.get_source()))) {
      int oldSeqNo = ((Integer) seqNos.get(new Integer(mhMsg.get_source()))).intValue();
      int upperBound = mhMsg.get_seqNo() + 25;
      int wrappedUpperBound = 25 - (255 - mhMsg.get_seqNo());
      if ((oldSeqNo >= mhMsg.get_seqNo() && oldSeqNo < upperBound)
          || (oldSeqNo >= 0 && oldSeqNo < wrappedUpperBound)) {
        log.debug(
            "Dropping message from "
                + mhMsg.get_source()
                + " with duplicate seqNo: "
                + mhMsg.get_seqNo());
        return;
      }
    }
    seqNos.put(new Integer(mhMsg.get_source()), new Integer(mhMsg.get_seqNo()));

    if (to != spAddr && to != MoteIF.TOS_BCAST_ADDR && to != TOS_UART_ADDR) {
      log.debug("Dropping message not for me.");
      return;
    }

    HashSet promiscuousSet = (HashSet) idTable.get(new Integer(BCAST_ID));
    HashSet listenerSet = (HashSet) idTable.get(new Integer(mhMsg.get_type()));

    if (listenerSet != null && promiscuousSet != null) {
      listenerSet.addAll(promiscuousSet);
    } else if (listenerSet == null && promiscuousSet != null) {
      listenerSet = promiscuousSet;
    }

    if (listenerSet == null) {
      log.debug("No Listener for type: " + mhMsg.get_type());
      return;
    }

    for (Iterator it = listenerSet.iterator(); it.hasNext(); ) {
      MessageListener ml = (MessageListener) it.next();
      ml.messageReceived(to, mhMsg);
    }
  }
Exemple #5
0
  /**
   * Provede prihlaseni uzivatele Odesle mu seznam aktualnich uzivatelu a r ozesle informaci o
   * prihlaseni ostatnim uzivatelum
   *
   * @param serverThread Vlakno serveru
   */
  public synchronized boolean login(ServerThread serverThread) {
    if (clients.containsKey(serverThread.getLogin().toLowerCase())) {
      return false;
    }

    // Send login info to other clients
    Enumeration<ServerThread> e = getClients().elements();
    while (e.hasMoreElements()) {
      e.nextElement().userLogin(serverThread.getLogin());
    }

    // Send users list to client
    Enumeration<ServerThread> e2 = getClients().elements();
    while (e2.hasMoreElements()) {
      ServerThread serverThread2 = e2.nextElement();
      serverThread.userLogin(serverThread2.getLogin());
      if (serverThread2.getServerGame() != null) {
        serverThread.userInGame(serverThread2.getLogin());
      }
    }

    // Append client to list
    clients.put(serverThread.getLogin().toLowerCase(), serverThread);

    return true;
  }
Exemple #6
0
  /** Prints StatisticsData structures to local logs. */
  public void printStatistics(final EvolutionState state, StatisticsData data) {
    int log = -6;
    String sender;

    EvolutionAgent agent = (EvolutionAgent) state;

    sender = data.sender.name;
    if (logtable.containsKey(sender)) log = ((Integer) logtable.get(sender)).intValue();
    else log = addLog(state, sender);
    if (log < 0) {
      if (defaultlog < 0) defaultlog = addLog(state, agent.getName());
      state.output.message(
          "Received a stats message from an unknown sender, will be logged to: "
              + ((Integer) logtable.get(new Integer(defaultlog))).intValue());
      log = defaultlog;
    }
    state.output.println(data.toStringForHumans(), Output.V_NO_GENERAL, log);

    if (store_best && data.finalStats) {
      for (int i = 0; i < data.best_of_run.length; i++)
        storeIndividual(
            state,
            basefilename + data.sender.name.substring(data.sender.name.lastIndexOf(".")) + ".best",
            data.best_of_run[i]);
    }
  }
 private void showExternalDownloadItems() {
   final Map<String, FcpPersistentGet> items = persistentQueue.getDownloadRequests();
   for (final FcpPersistentGet downloadRequest : items.values()) {
     if (!downloadModelItems.containsKey(downloadRequest.getIdentifier())) {
       addExternalItem(downloadRequest);
     }
   }
 }
Exemple #8
0
 sck.Integer getDesiredFR(int ivChIndex) {
   if (videoTable.containsKey(new Integer(ivChIndex))) {
     videoEntry_t auxVideoEntry = (videoEntry_t) videoTable.get(new Integer(ivChIndex));
     return auxVideoEntry.getvideoDesiredFR();
   } else {
     return null;
   }
 }
Exemple #9
0
 // If a channel is not actualized for a long time
 // it will be deleted from de MIB with this function.
 boolean deleteChannel(Integer ivChIndex) {
   if (videoTable.containsKey(ivChIndex)) {
     videoTable.remove(ivChIndex);
     delOldOids(ivChIndex.intValue());
     return true;
   }
   return false;
 }
Exemple #10
0
 boolean deleteChannel(int ivChIndex) {
   if (videoTable.containsKey(new Integer(ivChIndex))) {
     videoTable.remove(new Integer(ivChIndex));
     delOldOids(ivChIndex);
     return true;
   }
   return false;
 }
Exemple #11
0
 private int getRandomGame(int num) {
   int ranGame;
   Random randomNum = new Random();
   ranGame = randomNum.nextInt(num) + 1;
   while (!gameRecord.containsKey(ranGame)) {
     ranGame = randomNum.nextInt(num) + 1;
   }
   return ranGame;
 }
  public static Hashtable find_combos(Hashtable table, ArrayList<User> users, int r_value) {
    ArrayList<Integer> combinations = new ArrayList<Integer>();
    ArrayList<List<Integer>> combvalues = new ArrayList<List<Integer>>();
    // System.out.println("current hash "+table);
    Iterator iter = table.keySet().iterator();
    while (iter.hasNext()) {
      ArrayList<Integer> hashvalue = (ArrayList<Integer>) iter.next();
      // System.out.println(hashvalue+"::value with support "+table.get(hashvalue));
      if ((Integer) table.get(hashvalue) >= MINSUP) {
        combinations.add((Integer) table.get(hashvalue));
        combvalues.add(hashvalue);
      }
    }
    // System.out.println("combinations that survive: "+combvalues);

    ArrayList<Integer> unique_combo_values = new ArrayList<Integer>();
    for (int i = 0; i < combvalues.size(); i++) {
      for (int k = 0; k < combvalues.get(i).size(); k++) {
        if (!unique_combo_values.contains(combvalues.get(i).get(k))) {
          unique_combo_values.add(combvalues.get(i).get(k));
        }
      }
    }
    ArrayList<List<Integer>> new_combos = new ArrayList<List<Integer>>();
    new_combos = (ArrayList<List<Integer>>) combinations(unique_combo_values, r_value);
    // System.out.println("generated new combinations: "+new_combos);
    Hashtable t = new Hashtable();
    for (int j = 0; j < new_combos.size(); j++) {
      for (int i = 1; i <= num_users; i++) {
        if (users.get(i).hasSameNumbers((new_combos.get(j)))) {
          if (t.containsKey(new_combos.get(j))) {
            int count = (Integer) t.get(new_combos.get(j));
            count++;
            t.put(new_combos.get(j), count);
            // System.out.println("added one to "+new_combos.get(j));
          } else {
            t.put(new_combos.get(j), 1);
            // System.out.println("set to 1"+new_combos.get(j));
          }
        }
      }
    }
    // System.out.println("before weeding "+t);
    Iterator final_iter = t.keySet().iterator();
    while (final_iter.hasNext()) {
      ArrayList<Integer> next = (ArrayList<Integer>) final_iter.next();
      // System.out.println("current support of "+ next+ " is "+t.get(next));
      // System.out.println(MINSUP);
      if ((Integer) t.get(next) < MINSUP || next.isEmpty()) {
        // System.out.println("hi");
        final_iter.remove();
      }
    }

    return t;
  }
 private void doQuery(String cmd) {
   // if(cmd.charAt(0) == ' ') cmd = cmd.substring(1);
   cmd = cmd.trim();
   if (onlineUsers.containsKey(cmd)) {
     ClientThread c = (ClientThread) onlineUsers.get(cmd);
     writeLine("CHAT *** " + c.getNickname() + " is from " + c.getRemoteAddr() + " ***");
   } else {
     writeLine("CHAT *** " + cmd + " is UNKNOWN ***");
   }
 } // doQuery
  private static boolean checkUserName(String username, boolean newUserName) {

    if (username == null || (username.length() == 1 && username.charAt(0) == ' ')) {
      System.out.println("Please enter a proper username.");
      return false;
    }

    if (newUserName) {
      if (registeredUsers.containsKey(username)) {
        System.out.println("User Name already exists, please enter a different one");
        return false;
      } else return true;
    } else {
      boolean exist = registeredUsers.containsKey(username);
      if (!exist) {
        System.out.println("Username doesn't exist");
      }
      return exist;
    }
  }
  /**
   * Get the named properties for this resource and (potentially) its children.
   *
   * @param names an arrary of property names to retrieve
   * @return a MultiStatus of PropertyResponses
   * @exception com.ibm.webdav.WebDAVException
   */
  public MultiStatus getProperties(PropertyName[] names) throws WebDAVException {
    MultiStatus multiStatus = resource.getProperties(resource.getContext());
    MultiStatus newMultiStatus = new MultiStatus();

    Enumeration responses = multiStatus.getResponses();

    while (responses.hasMoreElements()) {
      PropertyResponse response = (PropertyResponse) responses.nextElement();
      PropertyResponse newResponse = new PropertyResponse(response.getResource());
      newResponse.setDescription(response.getDescription());
      newMultiStatus.addResponse(newResponse);

      Hashtable properties = (Hashtable) response.getPropertiesByPropName();

      // Hashtable newProperties = (Hashtable) newResponse.getProperties();
      for (int i = 0; i < names.length; i++) {
        if (properties.containsKey(names[i])) {
          PropertyValue srcval = response.getProperty(names[i]);
          newResponse.setProperty(names[i], srcval);

          // newProperties.put(names[i], properties.get(names[i]));
        } else {
          Document factory = null;

          try {
            factory = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
          } catch (Exception e) {
            throw new WebDAVException(WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
          }

          // we'll create an xml element with no value because that's
          //    what webdav will need to return for most methods... even if the
          //    property doesn't exist.   That's because the
          //    distinction between a propertyname and propertyvalue
          //    is fuzzy in WebDAV xml. A property name is
          //    essentially an empty property value because
          //    all property values have their property
          //    name stuck on.
          // if we decide to set reviewStatus to null instead (as
          //    we did previously, then the code for MultiStatus.asXML()
          //    needs to be updated to expect null values.
          // (jlc 990520)
          Element elTm = factory.createElementNS("X", "X:" + names[i].getLocal());

          elTm.setAttribute("xmlns:X", names[i].getNamespace());

          newResponse.addProperty(names[i], elTm, WebDAVStatus.SC_NOT_FOUND);
        }
      }
    }

    return newMultiStatus;
  }
  void CommonTokenAction(Token token) {
    if (!hashtable_initialized) {
      initialize_the_hashtable();
    }

    if (token.kind == ID_OR_KEYWORD && keywords.containsKey(token.image)) {
      token.style = KEYWORD;
    }
    //        if( token.kind == METHOD_OR_FIELD){
    //        	token.style = METHODS ;
    //        }
    if (token.style == null) token.style = PLAIN;
  }
 /**
  * called to let us know we have processed all the META-INF entries, and if we re-read one of
  * them, don't re-process it. Also gets rid of any data structures we needed when parsing META-INF
  * entries.
  */
 void doneWithMeta() {
   parsingMeta = false;
   anyToVerify = !sigFileSigners.isEmpty();
   baos = null;
   sigFileData = null;
   pendingBlocks = null;
   signerCache = null;
   manDig = null;
   // MANIFEST.MF is always treated as signed and verified,
   // move its signers from sigFileSigners to verifiedSigners.
   if (sigFileSigners.containsKey(JarFile.MANIFEST_NAME)) {
     verifiedSigners.put(JarFile.MANIFEST_NAME, sigFileSigners.remove(JarFile.MANIFEST_NAME));
   }
 }
Exemple #18
0
 void setOrCreateNewVideoEntry(
     int ivChIndex,
     String ivAcronym,
     String ivCodec,
     int ivQuality,
     String ivImageSize,
     int ivDesiredFR,
     int ivDesiredBW,
     int ivCodecBW,
     int ivSentFR,
     int ivSentBW,
     int ivReceivedBW,
     int ivEnsembledFR,
     int ivPaintFR) {
   videoEntry_t auxVideoEntry =
       new videoEntry_t(
           ivChIndex,
           ivAcronym,
           ivCodec,
           ivQuality,
           ivImageSize,
           ivDesiredFR,
           ivDesiredBW,
           ivCodecBW,
           ivSentFR,
           ivSentBW,
           ivReceivedBW,
           ivEnsembledFR,
           ivPaintFR);
   if (videoTable.containsKey(new Integer(ivChIndex))) {
     videoTable.remove(new Integer(ivChIndex));
     videoTable.put(new Integer(ivChIndex), auxVideoEntry);
   } else {
     newVideoEntry(
         ivChIndex,
         ivAcronym,
         ivCodec,
         ivQuality,
         ivImageSize,
         ivDesiredFR,
         ivDesiredBW,
         ivCodecBW,
         ivSentFR,
         ivSentBW,
         ivReceivedBW,
         ivEnsembledFR,
         ivPaintFR);
   }
 }
 private void doMsg(String cmd) {
   cmd = cmd.trim();
   int pos = cmd.indexOf(' '); // find tell whom
   if (pos < 0) return; // no message on the line
   String dst = cmd.substring(0, pos);
   String msg = cmd.substring(pos + 1);
   msg = msg.trim();
   if (msg == null) msg = " ";
   if (onlineUsers.containsKey(dst)) {
     ClientThread c = (ClientThread) onlineUsers.get(dst);
     c.writeLine("*** [" + myName + "] " + msg);
   } else {
     writeLine("CHAT *** " + dst + " not in the ROOM ***");
   }
 }
 public HashMap getDictSql(String sql) {
   if (sql == null) {
     Debug.getAppErrLogger().warn("字典Sql为空");
     return null;
   }
   sql = sql.trim();
   if (hashCache.containsKey(sql)) {
     //         Debug.getAppErrLogger().debug("缓存中取字典:[" + sql + "]");
     return (HashMap) hashCache.get(sql);
   } else {
     //         Debug.getAppErrLogger().debug("新缓存字典:[" + sql + "]");
     loadNewDict(sql);
     return (HashMap) hashCache.get(sql);
   }
 }
  // Scans the given file and creates symbols for its functions & label names.
  private void updateSymbolTable(File file, Hashtable symbols, Hashtable functions)
      throws ProgramException {
    BufferedReader reader = null;

    try {
      reader = new BufferedReader(new FileReader(file.getAbsolutePath()));
    } catch (FileNotFoundException fnfe) {
      throw new ProgramException("file " + file.getName() + " does not exist");
    }

    String line;
    String currentFunction = null;
    String label;
    int lineNumber = 0;

    isSlashStar = false;
    try {
      while ((line = unCommentLine(reader.readLine())) != null) {
        lineNumber++;
        if (!line.trim().equals("")) {
          if (line.startsWith("function ")) {
            StringTokenizer tokenizer = new StringTokenizer(line);
            tokenizer.nextToken();
            currentFunction = tokenizer.nextToken();
            if (symbols.containsKey(currentFunction))
              throw new ProgramException("subroutine " + currentFunction + " already exists");
            functions.put(currentFunction, new Short(nextPC));
            symbols.put(currentFunction, new Short(nextPC));
          } else if (line.startsWith("label ")) {
            StringTokenizer tokenizer = new StringTokenizer(line);
            tokenizer.nextToken();
            label = currentFunction + "$" + tokenizer.nextToken();
            symbols.put(label, new Short((short) (nextPC + 1)));
          }

          nextPC++;
        }
      }
      reader.close();
    } catch (IOException ioe) {
      throw new ProgramException("Error while reading from file");
    } catch (NoSuchElementException nsee) {
      throw new ProgramException("In line " + lineNumber + ": unexpected end of command");
    }
    if (isSlashStar) {
      throw new ProgramException("Unterminated /* comment at end of file");
    }
  }
  /** replaces the font (PS name) if necessary and returns the new name */
  private static String replacePSFont(String font) {
    String result;

    result = font;

    // do we have to replace it? -> same style, size
    if (m_PSFontReplacement.containsKey(font)) {
      result = m_PSFontReplacement.get(font).toString();
      if (DEBUG)
        System.out.println(
            Messages.getInstance().getString("PostscriptGraphics_ReplacePSFont_Text_First")
                + font
                + Messages.getInstance().getString("PostscriptGraphics_ReplacePSFont_Text_Second")
                + result
                + Messages.getInstance().getString("PostscriptGraphics_ReplacePSFont_Text_Third"));
    }

    return result;
  }
 private String askNickname() throws Exception {
   String name = null;
   boolean ok = false;
   writeLine("=> Enter Your Nickname: ");
   while (!ok) {
     name = in.readLine();
     while (onlineUsers.containsKey(name)) {
       writeLine("=> " + name + " exists! Re-enter your nickname: ");
       name = in.readLine();
     }
     ok = true;
     if (name.equalsIgnoreCase("yoshiki")) {
       System.out.println("!!! " + name + " is trying ... ");
       writeLine("? Yoshiki 你這日本的走狗滾開!");
       close();
       return null;
     }
     if (name.endsWith("ki")
         || name.endsWith("kli")
         || name.endsWith("KI")
         || name.endsWith("KLI")) {
       System.out.println("!!! " + name + " is trying ... ");
       writeLine("? No Japanese! Sorry! Re-enter your nickname: ");
       ok = false;
     }
     if (name.equals("tsaiwn")) {
       writeLine("? Do Not use God's name -- 別盜用別人 username");
       writeLine("=> Re-Enter Your Nickname: ");
       ok = false;
     }
     if (name.startsWith(" ") || name.startsWith("/")) {
       writeLine("? Do Not cheat me ! 別亂打!");
       writeLine("=> Re-Enter Your Nickname: ");
       ok = false;
     }
     if (name.equalsIgnoreCase("quit")) {
       return "QUIT";
     }
   } // while(!ok)
   if (!name.equals(SECRET_NAME)) setNickname(name);
   return name;
 } // askNickname()
 private void blossomDirectory(File dir) throws IOException {
   // System.out.println(">> blossomDirectory() on " + dir.getPath());
   String canonicalPath = dir.getCanonicalPath();
   String[] listing = (filter == null ? dir.list() : dir.list(filter));
   for (int i = listing.length; --i >= 0; ) {
     // System.out.println(">> listing: " + listing[i]);
     if (filter == null || filter.accept(dir, listing[i])) {
       String name = (canonical ? canonicalPath : dir.getPath()) + File.separator + listing[i];
       File file = new File(name);
       // System.out.println(">> parent: " + dir.getName());
       // System.out.println(">> created file: " + file.getPath());
       if (file.isFile()) files.push(file);
       else // dir
       {
         if (!markedDirex.containsKey(file.getCanonicalPath())) direx.push(file);
       }
     }
   }
   markedDirex.put(canonicalPath, dummy);
 }
  /** Collects the stems of the file names. */
  public Hashtable collectStems() throws Exception {

    Hashtable stems = new Hashtable();

    try {
      File dir = new File(m_dirName);
      String[] files = dir.list();
      for (int i = 0; i < files.length; i++) {
        if (files[i].endsWith(".txt")) {
          String stem = files[i].substring(0, files[i].length() - 4);
          if (!stems.containsKey(stem)) {
            stems.put(stem, new Double(0));
          }
        }
      }
    } catch (Exception e) {
      throw new Exception("Problem opening directory " + m_dirName);
    }
    return stems;
  }
Exemple #26
0
 public void receive() throws Exception {
   Object root =
       this.request("http://twitter.com/statuses/friends_timeline.json", false, null, true, true);
   if (!(root instanceof Vector)) throw new Exception("Timeline is not an array");
   Hashtable names = new Hashtable();
   Enumeration en = ((Vector) root).elements();
   while (en.hasMoreElements()) {
     Object status = en.nextElement();
     if (!(status instanceof Hashtable)) throw new Exception("Timeline status is not an object");
     Hashtable statusht = (Hashtable) status;
     Object text = statusht.get("text");
     String textstr = (String) text;
     if (!textstr.startsWith(MESSAGE_PREFIX)) continue;
     textstr = textstr.substring(MESSAGE_PREFIX.length());
     if (!(text instanceof String)) throw new Exception("Status text is not a string");
     Object user = statusht.get("user");
     if (!(user instanceof Hashtable)) throw new Exception("Status user is not an object");
     Object name = ((Hashtable) user).get("name");
     if (!(name instanceof String)) throw new Exception("Status user name is not a string");
     String namestr = (String) name;
     if (names.containsKey(namestr)) continue;
     names.put(namestr, Boolean.TRUE);
     String where = strip(textstr, '|', 0);
     String time = strip(textstr, '|', 1);
     String latlon = strip(textstr, '|', 2);
     if ((where == null) || (time == null) || (latlon == null)) continue;
     int colon = latlon.indexOf(':');
     if (colon < 0) continue;
     double lat, lon;
     try {
       lat = Double.parseDouble(latlon.substring(0, colon));
       lon = Double.parseDouble(latlon.substring(colon + 1));
     } catch (Exception e) {
       continue;
     }
     this.main.updateSignPosition(namestr, lat, lon, where, time);
   }
 }
 public void persistentRequestRemoved(final FcpPersistentGet downloadRequest) {
   if (downloadModelItems.containsKey(downloadRequest.getIdentifier())) {
     final FrostDownloadItem dlItem = downloadModelItems.get(downloadRequest.getIdentifier());
     if (dlItem.isExternal()) {
       SwingUtilities.invokeLater(
           new Runnable() {
             public void run() {
               List<FrostDownloadItem> itemList = new ArrayList<FrostDownloadItem>();
               itemList.add(dlItem);
               downloadModel.removeItems(itemList);
             }
           });
     } else {
       if (dlItem.isInternalRemoveExpected()) {
         dlItem.setInternalRemoveExpected(false); // clear flag
       } else if (dlItem.getState() != FrostDownloadItem.STATE_DONE) {
         dlItem.setEnabled(false);
         dlItem.setState(FrostDownloadItem.STATE_FAILED);
         dlItem.setErrorCodeDescription("Disappeared from global queue");
       }
     }
   }
 }
Exemple #28
0
 sck.Integer getReceivedBW(int ivChIndex) {
   if (videoTable.containsKey(new Integer(ivChIndex))) {
     videoEntry_t auxVideoEntry = (videoEntry_t) videoTable.get(new Integer(ivChIndex));
     return auxVideoEntry.getvideoReceivedBW();
   } else return null;
 }
Exemple #29
0
 sck.OctetString getImageSize(int ivChIndex) {
   if (videoTable.containsKey(new Integer(ivChIndex))) {
     videoEntry_t auxVideoEntry = (videoEntry_t) videoTable.get(new Integer(ivChIndex));
     return auxVideoEntry.getvideoImageSize();
   } else return null;
 }
  public static void main(String[] args) {
    num_users = 0;
    int movie_number = 0;
    MINSUP = Double.parseDouble(args[1]);
    MINCONF = Double.parseDouble(args[3]);
    MAXMOVIES = Integer.parseInt(args[5]);
    String test_raw = args[6];
    test = "";
    test = test_raw.substring(1);
    if (test.equals("comb")) {
      go_to = true;
    }

    if ((MINSUP < 0 || MINSUP > 100)
        || (MINCONF < 0 || MINCONF > 100)
        || MAXMOVIES < 0
        || test == null) {
      System.out.println("Input variables aren't correct!");
      System.exit(0);
    }
    ArrayList<User> users = new ArrayList<User>(Collections.nCopies(945, blank));
    int[] user_exists = new int[945];
    try {
      FileInputStream fstream = new FileInputStream("src/u.data"); // location of file in eclipse
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
      while ((strLine = br.readLine()) != null) {
        StringTokenizer tok = new StringTokenizer(strLine);
        String ID = tok.nextToken();
        int userID = Integer.parseInt(ID);
        String MID = tok.nextToken();
        int movieID = Integer.parseInt(MID);
        String RANK = tok.nextToken();
        int movieRating = Integer.parseInt(RANK);
        Movie current_movie = new Movie(movieID, movieRating);

        if (user_exists[userID] == 0) {
          num_users++;
          users.set(userID, new User(userID, movieID, movieRating));
          user_exists[userID] = 1;
        } else {
          users.get(userID).movies.add(current_movie);
        }
      }

      in.close();
    } catch (Exception e) {
      if (e.getMessage() != null) {
        System.err.println("Error: " + e.getMessage());
      }
    }
    try {
      FileInputStream fstream = new FileInputStream("src/u.item"); // location of file in eclipse
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
      while ((strLine = br.readLine()) != null) {
        movie_number++;
        StringTokenizer tok = new StringTokenizer(strLine, "|");
        String number = tok.nextToken();
        int movieNumber = Integer.parseInt(number);
        String movieName = tok.nextToken();
        for (int i = 0; i < users.size(); i++) {
          for (int j = 0; j < users.get(i).movies.size(); j++) {
            if (users.get(i).movies.get(j).movieID == movieNumber) {
              users.get(i).movies.get(j).setName(movieName);
            }
          }
        }
      }

      in.close();
    } catch (Exception j) {
      System.err.println("Error: " + j.getMessage());
    }

    // System.out.println("Num users is "+num_users);
    if (test.equals("pos")) {
      for (int user_num = 1; user_num < num_users + 1; user_num++) {
        for (int usermovies = 0; usermovies < users.get(user_num).movies.size(); usermovies++) {
          if (users.get(user_num).movies.get(usermovies).ranking <= 3) {
            users.get(user_num).movies.remove(usermovies);
            usermovies--;
          }
        }
      }
      MINSUP *= num_users;
      MINCONF *= 10;
      System.out.println(MINSUP);
      System.out.println(MINCONF);
      ArrayList<Movie> users_movies = new ArrayList<Movie>();
      Hashtable table = new Hashtable();
      Hashtable master_table = new Hashtable();
      for (int i = 1; i <= num_users; i++) {
        for (int k = 0; k < users.get(i).movies.size(); k++) {
          ArrayList<Integer> add = new ArrayList<Integer>();
          add.add(users.get(i).movies.get(k).movieID);
          // System.out.println(users.get(i).movies.get(k).movieID+ " is the current movie from user
          // "+i);

          // if(users.get(i).movies.get(k).ranking>3){
          if (table.containsKey(add)) {
            int table_value = (Integer) table.get(add);
            table_value++;
            table.put(add, table_value);
            // System.out.println("added 1 to the existing");
          } else {
            table.put(add, 1);
            // System.out.println("added a new");
          }
          // }
        }
      }
      System.out.println(table);
      Iterator final_iter = table.keySet().iterator();
      while (final_iter.hasNext()) {
        ArrayList<Integer> next = (ArrayList<Integer>) final_iter.next();
        // System.out.println(t.get(next));
        // System.out.println(MINSUP);
        if ((Integer) table.get(next) < MINSUP) {
          // System.out.println("hi");
          final_iter.remove();
        }
      }
      // System.out.println(table);
      master_table.putAll(table);
      // System.out.println(master_table);
      for (int i = 2; i <= MAXMOVIES; i++) {
        table = find_combos(table, users, i);
        // System.out.println("table generated is "+table);
        if (!table.isEmpty()) {
          master_table.putAll(table);
        }
        // System.out.println(master_table);
      }
      // System.out.println(master_table+" is before print_up");
      printup(master_table);
    }
    if (test.equals("neg")) {
      for (int user_num = 1; user_num < num_users + 1; user_num++) {
        for (int usermovies = 0; usermovies < users.get(user_num).movies.size(); usermovies++) {
          if (users.get(user_num).movies.get(usermovies).ranking >= 3) {
            users.get(user_num).movies.remove(usermovies);
            usermovies--;
          }
        }
      }
      MINSUP *= num_users;
      MINCONF *= 10;
      ArrayList<Movie> users_movies = new ArrayList<Movie>();
      Hashtable table = new Hashtable();
      Hashtable master_table = new Hashtable();
      for (int i = 1; i <= num_users; i++) {
        for (int k = 0; k < users.get(i).movies.size(); k++) {
          ArrayList<Integer> add = new ArrayList<Integer>();
          add.add(users.get(i).movies.get(k).movieID);
          // System.out.println(users.get(i).movies.get(k).movieID+ " is the current movie from user
          // "+i);

          // if(users.get(i).movies.get(k).ranking>3){
          if (table.containsKey(add)) {
            int table_value = (Integer) table.get(add);
            table_value++;
            table.put(add, table_value);
            // System.out.println("added 1 to the existing");
          } else {
            table.put(add, 1);
            // System.out.println("added a new");
          }
          // }
        }
      }
      // System.out.println(table);
      Iterator final_iter = table.keySet().iterator();
      while (final_iter.hasNext()) {
        ArrayList<Integer> next = (ArrayList<Integer>) final_iter.next();
        // System.out.println(t.get(next));
        // System.out.println(MINSUP);
        if ((Integer) table.get(next) < MINSUP) {
          // System.out.println("hi");
          final_iter.remove();
        }
      }
      // System.out.println(table);
      master_table.putAll(table);
      // System.out.println(master_table);
      for (int i = 2; i <= MAXMOVIES; i++) {
        table = find_combos(table, users, i);
        if (!table.isEmpty()) {
          master_table.putAll(table);
        }
      }
      // System.out.println(master_table+" is before print_up");
      printup(master_table);
    }
    if (test.equals("comb")) {
      for (int user_num = 1; user_num < num_users + 1; user_num++) {
        for (int usermovies = 0; usermovies < users.get(user_num).movies.size(); usermovies++) {
          if (users.get(user_num).movies.get(usermovies).ranking >= 3) {
            users.get(user_num).movies.remove(usermovies);
            usermovies--;
          }
        }
      }
      MINSUP *= num_users;
      MINCONF *= 10;
      ArrayList<Movie> users_movies = new ArrayList<Movie>();
      Hashtable table = new Hashtable();
      Hashtable master_table = new Hashtable();
      for (int i = 1; i <= num_users; i++) {
        for (int k = 0; k < users.get(i).movies.size(); k++) {
          ArrayList<Integer> add = new ArrayList<Integer>();
          add.add(users.get(i).movies.get(k).movieID);
          // System.out.println(users.get(i).movies.get(k).movieID+ " is the current movie from user
          // "+i);

          // if(users.get(i).movies.get(k).ranking>3){
          if (table.containsKey(add)) {
            int table_value = (Integer) table.get(add);
            table_value++;
            table.put(add, table_value);
            // System.out.println("added 1 to the existing");
          } else {
            table.put(add, 1);
            // System.out.println("added a new");
          }
          // }
        }
      }
      // System.out.println(table);
      Iterator final_iter = table.keySet().iterator();
      while (final_iter.hasNext()) {
        ArrayList<Integer> next = (ArrayList<Integer>) final_iter.next();
        // System.out.println(t.get(next));
        // System.out.println(MINSUP);
        if ((Integer) table.get(next) < MINSUP) {
          // System.out.println("hi");
          final_iter.remove();
        }
      }
      // System.out.println(table);
      master_table.putAll(table);
      // System.out.println(master_table);
      for (int i = 2; i <= MAXMOVIES; i++) {
        table = find_combos(table, users, i);
        if (!table.isEmpty()) {
          master_table.putAll(table);
        }
      }
      // System.out.println(master_table+" is before print_up");
      test = "neg";
      printup(master_table);
      test = "comb2";
    }
    if (test.equals("comb2")) {

      users = new ArrayList<User>(Collections.nCopies(945, blank));
      user_exists = new int[945];
      num_users = 0;

      try {
        FileInputStream fstream = new FileInputStream("src/u.data"); // location of file in eclipse
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        while ((strLine = br.readLine()) != null) {
          StringTokenizer tok = new StringTokenizer(strLine);
          String ID = tok.nextToken();
          int userID = Integer.parseInt(ID);
          String MID = tok.nextToken();
          int movieID = Integer.parseInt(MID);
          String RANK = tok.nextToken();
          int movieRating = Integer.parseInt(RANK);
          Movie current_movie = new Movie(movieID, movieRating);

          if (user_exists[userID] == 0) {
            num_users++;
            users.set(userID, new User(userID, movieID, movieRating));
            user_exists[userID] = 1;
          } else {
            users.get(userID).movies.add(current_movie);
          }
        }

        in.close();
      } catch (Exception e) {
        if (e.getMessage() != null) {
          System.err.println("Error: " + e.getMessage());
        }
      }
      try {
        FileInputStream fstream = new FileInputStream("src/u.item"); // location of file in eclipse
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        while ((strLine = br.readLine()) != null) {
          movie_number++;
          StringTokenizer tok = new StringTokenizer(strLine, "|");
          String number = tok.nextToken();
          int movieNumber = Integer.parseInt(number);
          String movieName = tok.nextToken();
          for (int i = 0; i < users.size(); i++) {
            for (int j = 0; j < users.get(i).movies.size(); j++) {
              if (users.get(i).movies.get(j).movieID == movieNumber) {
                users.get(i).movies.get(j).setName(movieName);
              }
            }
          }
        }

        in.close();
      } catch (Exception j) {
        System.err.println("Error: " + j.getMessage());
      }
      for (int user_num = 1; user_num < num_users + 1; user_num++) {
        for (int usermovies = 0; usermovies < users.get(user_num).movies.size(); usermovies++) {
          if (users.get(user_num).movies.get(usermovies).ranking <= 3) {
            users.get(user_num).movies.remove(usermovies);
            usermovies--;
          }
        }
      }

      ArrayList<Movie> users_movies = new ArrayList<Movie>();
      Hashtable table = new Hashtable();
      Hashtable master_table = new Hashtable();
      for (int i = 1; i <= num_users; i++) {
        for (int k = 0; k < users.get(i).movies.size(); k++) {
          ArrayList<Integer> add = new ArrayList<Integer>();
          add.add(users.get(i).movies.get(k).movieID);
          // System.out.println(users.get(i).movies.get(k).movieID+ " is the current movie from user
          // "+i);

          if (table.containsKey(add)) {
            int table_value = (Integer) table.get(add);
            table_value++;
            table.put(add, table_value);
            // System.out.println("added 1 to the existing");
          } else {
            table.put(add, 1);
            // System.out.println("added a new");
          }
          // }
        }
      }
      // System.out.println(table);
      Iterator final_iter = table.keySet().iterator();
      while (final_iter.hasNext()) {
        ArrayList<Integer> next = (ArrayList<Integer>) final_iter.next();
        // System.out.println(t.get(next));
        // System.out.println(MINSUP);
        if ((Integer) table.get(next) < MINSUP) {
          // System.out.println("hi");
          final_iter.remove();
        }
      }
      // System.out.println(table);
      master_table.putAll(table);
      // System.out.println(master_table);
      for (int i = 2; i < MAXMOVIES; i++) {
        table = find_combos(table, users, i);
        if (!table.isEmpty()) {
          master_table.putAll(table);
        }
      }
      // System.out.println(master_table+" is before print_up");
      test = "pos";
      printup(master_table);
    }
  }