Пример #1
2
  void removeTaskEntry(String taskid) {
    // taskid --> tracker
    String tracker = (String) taskidToTrackerMap.remove(taskid);

    // tracker --> taskid
    TreeSet trackerSet = (TreeSet) trackerToTaskMap.get(tracker);
    if (trackerSet != null) {
      trackerSet.remove(taskid);
    }

    // taskid --> TIP
    taskidToTIPMap.remove(taskid);
  }
Пример #2
1
  /**
   * When looking at a result set that consists of a Map/HashTable we cannot rely on the output
   * order, as the hashing algorithm or other aspects of the implementation may be different on
   * differnt JDKs or platforms. Hence we take the Map, convert the keys to a List, sort them and
   * Stringify the Map, which is a bit of a hack, but guarantees that we get the same order on all
   * systems. We assume that the keys are strings.
   *
   * @param m The Map that contains keys we wish to return in sorted order
   * @return A string that represents all the keys in sorted order.
   */
  public String sortMapToString(Map m) {

    System.out.println("Map toString looks like: " + m.toString());
    // Pass in crap, and get nothing back
    //
    if (m == null) {
      return null;
    }

    // Sort the keys in the Map
    //
    TreeMap nset = new TreeMap(m);

    System.out.println("Tree map looks like: " + nset.toString());
    return nset.toString();
  }
Пример #3
0
 /*public String itemWithNthHighestPeak(int n){
     TreeMap peaks = peakResults();
     peakResult next = new peakResult();
     for(int i=0;peaks.size()>0&&i<n;i++){
         next=(peakResult)(peaks.remove(peaks.firstKey()));
     }
     return next.name;
 } */
 public String decisionResult(double thresh) {
   TreeMap decisions = decisionResults(thresh);
   String result;
   if (decisions.size() > 0) result = ((decisResult) decisions.firstKey()).name;
   else result = "(null)";
   return result;
 }
  private void loadLanguageList() {
    TreeMap treemap = new TreeMap();

    try {
      BufferedReader bufferedreader =
          new BufferedReader(
              new InputStreamReader(
                  (net.minecraft.src.StringTranslate.class)
                      .getResourceAsStream("/lang/languages.txt"),
                  "UTF-8"));

      for (String s = bufferedreader.readLine(); s != null; s = bufferedreader.readLine()) {
        String as[] = s.split("=");

        if (as != null && as.length == 2) {
          treemap.put(as[0], as[1]);
        }
      }
    } catch (IOException ioexception) {
      ioexception.printStackTrace();
      return;
    }

    languageList = treemap;
  }
Пример #5
0
 private static final Client getClient(File indexDirectory) throws SearchLibException {
   clientsLock.r.lock();
   try {
     Client client = CLIENTS.get(indexDirectory);
     if (client != null) return client;
   } finally {
     clientsLock.r.unlock();
   }
   int i = 60;
   while (isOldClient(indexDirectory) && i > 0) {
     ThreadUtils.sleepMs(500);
     i--;
   }
   if (i == 0) throw new SearchLibException("Time out while getting " + indexDirectory);
   clientsLock.w.lock();
   try {
     Client client = CLIENTS.get(indexDirectory);
     if (client != null) return client;
     client =
         ClientFactory.INSTANCE.newClient(
             indexDirectory, true, false, ClientFactory.INSTANCE.properties.getSilentBackupUrl());
     CLIENTS.put(indexDirectory, client);
     return client;
   } finally {
     clientsLock.w.unlock();
   }
 }
Пример #6
0
 public static void eraseIndex(User user, String indexName)
     throws SearchLibException, NamingException, IOException {
   if (user != null && !user.isAdmin()) throw new SearchLibException("Operation not permitted");
   File indexDir = getIndexDirectory(indexName);
   Client client = null;
   synchronized (ClientCatalog.class) {
     clientsLock.r.lock();
     try {
       client = CLIENTS.get(indexDir);
     } finally {
       clientsLock.r.unlock();
     }
     if (client != null) {
       client.close();
       client.delete();
     } else FileUtils.deleteDirectory(indexDir);
     if (client != null) {
       clientsLock.w.lock();
       try {
         CLIENTS.remove(client.getDirectory());
       } finally {
         clientsLock.w.unlock();
       }
       PushEvent.eventClientSwitch.publish(client);
     }
   }
 }
  private void exportParameters() {
    synchronized (exported_parameters) {
      if (!exported_parameters_dirty) {

        return;
      }

      exported_parameters_dirty = false;

      try {
        TreeMap<String, String> tm = new TreeMap<String, String>();

        Set<String> exported_keys = new HashSet<String>();

        for (String[] entry : exported_parameters.values()) {

          String key = entry[0];
          String value = entry[1];

          exported_keys.add(key);

          if (value != null) {

            tm.put(key, value);
          }
        }

        for (Map.Entry<String, String> entry : imported_parameters.entrySet()) {

          String key = entry.getKey();

          if (!exported_keys.contains(key)) {

            tm.put(key, entry.getValue());
          }
        }

        File parent_dir = new File(SystemProperties.getUserPath());

        File props = new File(parent_dir, "exported_params.properties");

        PrintWriter pw =
            new PrintWriter(new OutputStreamWriter(new FileOutputStream(props), "UTF-8"));

        try {
          for (Map.Entry<String, String> entry : tm.entrySet()) {

            pw.println(entry.getKey() + "=" + entry.getValue());
          }

        } finally {

          pw.close();
        }
      } catch (Throwable e) {

        e.printStackTrace();
      }
    }
  }
Пример #8
0
  private void ListSubDirectorySizes(File file) {
    File[] files;
    files =
        file.listFiles(
            new FileFilter() {
              @Override
              public boolean accept(File file) {
                //                if (!file.isDirectory()){
                //                    return false;  //To change body of implemented methods use
                // File | Settings | File Templates.
                //                }else{
                //                    return true;
                //                }
                return true;
              }
            });
    Map<String, Long> dirListing = new HashMap<String, Long>();
    for (File dir : files) {
      DiskUsage diskUsage = new DiskUsage();
      diskUsage.accept(dir);
      //            long size = diskUsage.getSize() / (1024 * 1024);
      long size = diskUsage.getSize();
      dirListing.put(dir.getName(), size);
    }

    ValueComparator bvc = new ValueComparator(dirListing);
    TreeMap<String, Long> sorted_map = new TreeMap<String, Long>(bvc);
    sorted_map.putAll(dirListing);

    PrettyPrint(file, sorted_map);
  }
Пример #9
0
 /** Print a full description of all elements in the Tdb */
 public void prettyPrint(PrintStream ps) {
   ps.println("Tdb");
   TreeMap<String, TdbPublisher> sorted =
       new TreeMap<String, TdbPublisher>(CatalogueOrderComparator.SINGLETON);
   sorted.putAll(getAllTdbPublishers());
   for (TdbPublisher tdbPublisher : sorted.values()) {
     tdbPublisher.prettyPrint(ps, 2);
   }
 }
Пример #10
0
 /**
  * @param type
  * @return
  */
 private Collection<String> getCorrectList(String type) {
   if (type.equals("prop")) {
     return propsList.keySet();
   } else if (type.equals("set")) {
     return setsList.keySet();
   } else {
     return charList.keySet();
   }
 }
 /**
  * Returns a map that associates probe names to floating point measurement values, all from a
  * single experiment. Any probes with missing values in this experiment are omitted from the map.
  *
  * @param i the index of the experiment to retrieve
  * @return
  */
 public Map<String, Float> exptValues(int i) {
   TreeMap<String, Float> map = new TreeMap<String, Float>();
   for (String k : table.keySet()) {
     Float v = table.get(k)[i];
     if (v != null) {
       map.put(k, v);
     }
   }
   return map;
 }
Пример #12
0
 public Map<String, Rxn> getReactions(String compartment) {
   TreeMap<String, Rxn> crxns = new TreeMap<String, Rxn>();
   for (String rn : reactions.keySet()) {
     Rxn r = reactions.get(rn);
     if (r.getLocation().equals(compartment)) {
       crxns.put(rn, r);
     }
   }
   return crxns;
 }
Пример #13
0
 // -------------------------------------------
 // check lifetime and remove expired entries
 // -------------------------------------------
 public synchronized void rmExpiredEntry() {
   long currtime = System.currentTimeMillis();
   Iterator keys = table.keySet().iterator();
   while (keys.hasNext()) {
     String k = (String) keys.next();
     Entry e = (Entry) table.get(k);
     if (currtime > (e.getArrivalTS() + e.getLifetime() * 1000)) {
       keys.remove();
     }
   }
 }
Пример #14
0
 public static void sortAndPrintMap(Map<String, Double> map) throws FileNotFoundException {
   // pr = new PrintStream(new FileOutputStream("/semplest/lluis/keywordExp/wordmap.txt"));
   pr = System.out;
   ValueComparator bvc = new ValueComparator(map);
   TreeMap<String, Double> sorted = new TreeMap<String, Double>(bvc);
   sorted.putAll(map);
   for (String key : sorted.keySet()) {
     pr.println(key + " : " + map.get(key));
   }
   System.out.println("Number of words : " + map.size());
 }
Пример #15
0
  /** Get an initial set of action parameters associated with an upstream node. */
  public TreeMap<String, ActionParam> getInitialSourceParams() {
    TreeMap<String, ActionParam> params = new TreeMap<String, ActionParam>();

    {
      ActionParam param =
          new IntegerActionParam("Order", "Evaluates the MEL script in this order.", 100);
      params.put(param.getName(), param);
    }

    return params;
  }
Пример #16
0
 public int releaseLock(UTF8 src, UTF8 holder) {
   TreeSet holders = (TreeSet) activeLocks.get(src);
   if (holders != null && holders.contains(holder)) {
     holders.remove(holder);
     if (holders.size() == 0) {
       activeLocks.remove(src);
     }
     return COMPLETE_SUCCESS;
   } else {
     return OPERATION_FAILED;
   }
 }
Пример #17
0
 // ------------------------------------------------------
 // for "AttrRqst"
 // Return: attrbute list for the URL/"service type"
 //         format: (attr1=value1),(attr2=value2)
 // if tag != "", return ONLY those attributes in tag
 // ------------------------------------------------------
 public synchronized String getAttrList(String url, String scope, String tag, String ltag) {
   if (table.containsKey(ltag + url)) {
     Entry e = (Entry) table.get(ltag + url);
     if (!e.getDeleted() && scope.equalsIgnoreCase(e.getScope())) {
       return e.getAttr(tag);
     } else {
       return "";
     }
   } else { // Not URL, try servive type
     return typeAttrList(url, scope, tag, ltag);
   }
 }
Пример #18
0
  /** Replace working files with the selected checked-in files. */
  @Override
  public void doApply() {
    super.doApply();

    if (pIsFrozen) return;

    TreeMap<String, VersionID> files = new TreeMap<String, VersionID>();
    for (JFileSeqPanel panel : pFileSeqPanels.values()) files.putAll(panel.getFilesToRevert());

    RevertTask task = new RevertTask(files);
    task.start();
  }
  public void save(String filename) {
    if (propertiesMap == null) {

      // nothing to save, initialisation not complete

      return;
    }

    /**
     * Note - propertiesMap isn't synchronised! We'll clone the map now, because we need to modify
     * it. The BEncoding code will create a new map object (TreeMap) because it needs to be sorted,
     * so we might as well do it here too.
     */
    TreeMap<String, Object> properties_clone = propertiesMap.toTreeMap();

    // Remove any transient parameters.
    if (!this.transient_properties.isEmpty()) {
      properties_clone.keySet().removeAll(this.transient_properties);
    }

    FileUtil.writeResilientConfigFile(filename, properties_clone);

    List<COConfigurationListener> listeners_copy;

    synchronized (listenerz) {
      listeners_copy = new ArrayList<COConfigurationListener>(listenerz);
    }

    for (int i = 0; i < listeners_copy.size(); i++) {

      COConfigurationListener l = (COConfigurationListener) listeners_copy.get(i);

      if (l != null) {

        try {
          l.configurationSaved();

        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      } else {

        Debug.out("COConfigurationListener is null");
      }
    }

    if (exported_parameters_dirty) {

      exportParameters();
    }
  }
Пример #20
0
 /**
  * Clear the entire contents of the cache and delete the backing files. This should only be used
  * when the server is reinitializing, because the users are going to lose their files.
  */
 public static void purgeCache(Configuration conf, MRAsyncDiskService service) throws IOException {
   synchronized (cachedArchives) {
     LocalFileSystem localFs = FileSystem.getLocal(conf);
     for (Map.Entry<String, CacheStatus> f : cachedArchives.entrySet()) {
       try {
         deleteLocalPath(service, localFs, f.getValue().localizedLoadPath);
       } catch (IOException ie) {
         LOG.debug("Error cleaning up cache", ie);
       }
     }
     cachedArchives.clear();
   }
 }
Пример #21
0
 public int obtainLock(UTF8 src, UTF8 holder, boolean exclusive) {
   TreeSet holders = (TreeSet) activeLocks.get(src);
   if (holders == null) {
     holders = new TreeSet();
     activeLocks.put(src, holders);
   }
   if (exclusive && holders.size() > 0) {
     return STILL_WAITING;
   } else {
     holders.add(holder);
     return COMPLETE_SUCCESS;
   }
 }
Пример #22
0
  public void parseCode() {

    // Parse all <code> and <parameter> elements
    List codeList = ParseUtils.parseDescendants(root, "code", idMap);
    Iterator i = codeList.iterator();
    while (i.hasNext()) {
      Element codeElt = (Element) i.next();
      String codeId = codeElt.getAttributeValue("id");
      if (objects.containsKey(codeId)) {
        System.out.println("Note: Shadowing definition of <code id=\"" + codeId + "\">");
      }
      objects.put(codeId, new Code(codeElt, idMap));
    }
  }
Пример #23
0
 public static final void closeIndex(String indexName) throws SearchLibException {
   Client client = null;
   clientsLock.w.lock();
   try {
     File indexDirectory = getIndexDirectory(indexName);
     client = CLIENTS.get(indexDirectory);
     if (client == null) return;
     Logging.info("Closing client " + indexName);
     client.close();
     CLIENTS.remove(indexDirectory);
   } finally {
     clientsLock.w.unlock();
   }
   if (client != null) PushEvent.eventClientSwitch.publish(client);
 }
Пример #24
0
 /** Map com a copia dos seguros de um cliente */
 public Map<String, Seguro> copiaSeg() {
   Map<String, Seguro> segs = new TreeMap<String, Seguro>();
   for (Seguro s : seguros.values()) {
     segs.put(s.getCodigo(), s.clone());
   }
   return segs;
 }
Пример #25
0
 // ------------------------------------------------
 // save database to either the stdout or the file
 // ------------------------------------------------
 public synchronized void saveDatabase(BufferedWriter o) {
   Iterator values = table.values().iterator();
   while (values.hasNext()) {
     Entry e = (Entry) values.next();
     e.prtEntry(daf, o);
   }
 }
Пример #26
0
 // -----------------------------------------------------------
 // for "SrvRqst"
 // find the matched URLs with (type, scope, predicate, ltag)
 // return: error code (short)
 //         number of matched URLs (short)
 //         URL blocks (decided bt previous #URL)
 // -----------------------------------------------------------
 public synchronized byte[] getMatchedURL(String type, String scope, String pred, String ltag) {
   byte[] buf = null;
   int ecode = Const.OK;
   if (!Util.shareString(daf.getScope(), scope, ",")) {
     ecode = Const.SCOPE_NOT_SUPPORTED;
   }
   b.reset();
   try {
     int count = 0;
     d.writeShort(ecode); // error code
     d.writeShort(count); // URL count, place holder
     if (ecode == Const.OK) { // no error, find matched URLs
       Iterator values = table.values().iterator();
       while (values.hasNext()) {
         Entry e = (Entry) values.next();
         if (e.match(type, scope, pred, ltag)) {
           count++;
           d.writeByte(0);
           d.writeShort(e.getLifetime());
           d.writeShort(e.getURL().length());
           d.writeBytes(e.getURL());
           d.writeByte(0);
         }
       }
     }
     buf = b.toByteArray();
     if (count > 0) Util.writeInt(buf, 2, count, 2); // update count
   } catch (Exception e) {
     if (ServiceLocationManager.displayMSLPTrace) e.printStackTrace();
   }
   return buf;
 }
Пример #27
0
 // ----------------------------------------------------------------------
 // for "SrvTypeRqst"
 // get the list of service types for specified scope & naming authority
 // ----------------------------------------------------------------------
 public synchronized String getServiceTypeList(String na, String scope) {
   Vector typelist = new Vector(5);
   Iterator values = table.values().iterator();
   while (values.hasNext()) {
     Entry e = (Entry) values.next();
     if (!e.getDeleted()
         && // nor deleted
         scope.equalsIgnoreCase(e.getScope())
         && // match scope
         (na.equals("*")
             || // NA wildcard
             na.equalsIgnoreCase(e.getNA()))
         && // match NA
         !typelist.contains(e.getType())) {
       typelist.addElement(e.getType());
     }
   }
   StringBuffer tl = new StringBuffer();
   for (int i = 0; i < typelist.size(); i++) {
     String s = (String) typelist.elementAt(i);
     if (tl.length() > 0) tl.append(",");
     tl.append(s);
   }
   return tl.toString();
 }
Пример #28
0
  /**
   * Retrieves Strings corresponding to all valid _transition paths from a given node that satisfy a
   * given condition.
   *
   * @param strHashSet a HashSet of Strings to contain all those in the MDAG satisfying {@code
   *     searchCondition} with {@code conditionString}
   * @param searchCondition the SearchCondition enum field describing the type of relationship that
   *     Strings contained in the MDAG must have with {@code conditionString} in order to be
   *     included in the result set
   * @param searchConditionString the String that all Strings in the MDAG must be related with in
   *     the fashion denoted by {@code searchCondition} in order to be included in the result set
   * @param prefixString the String corresponding to the currently traversed _transition path
   * @param transitionTreeMap a TreeMap of Characters to MDAGNodes collectively representing an
   *     MDAGNode's _transition set
   */
  private void getStrings(
      HashSet<String> strHashSet,
      SearchCondition searchCondition,
      String searchConditionString,
      String prefixString,
      TreeMap<Character, MDAGNode> transitionTreeMap) {
    // Traverse all the valid _transition paths beginning from each _transition in
    // transitionTreeMap, inserting the
    // corresponding Strings in to strHashSet that have the relationship with conditionString
    // denoted by searchCondition
    for (Entry<Character, MDAGNode> transitionKeyValuePair : transitionTreeMap.entrySet()) {
      String newPrefixString = prefixString + transitionKeyValuePair.getKey();
      MDAGNode currentNode = transitionKeyValuePair.getValue();

      if (currentNode.isAcceptNode()
          && searchCondition.satisfiesCondition(newPrefixString, searchConditionString))
        strHashSet.add(newPrefixString);

      // Recursively call this to traverse all the valid _transition paths from currentNode
      getStrings(
          strHashSet,
          searchCondition,
          searchConditionString,
          newPrefixString,
          currentNode.getOutgoingTransitions());
    }
    /////
  }
Пример #29
0
  /** @return A Box for selecting an asset type, the old asset and its replacement asset. */
  private Box assetChoiceBox() {
    TreeSet<String> types = new TreeSet<String>();

    types.add(AssetType.CHARACTER.toString());
    types.add(AssetType.PROP.toString());
    types.add(AssetType.SET.toString());

    // JDrawer toReturn;
    Box hbox = new Box(BoxLayout.X_AXIS);
    {
      JCollectionField assetType = UIFactory.createCollectionField(types, diag, sTSize);
      assetType.setActionCommand("type");
      assetType.addActionListener(this);

      JCollectionField oldAsset = UIFactory.createCollectionField(charList.keySet(), diag, sVSize);
      JCollectionField newAsset = UIFactory.createCollectionField(charList.keySet(), diag, sVSize);
      hbox.add(assetType);
      hbox.add(Box.createHorizontalStrut(10));
      hbox.add(oldAsset);
      hbox.add(Box.createHorizontalStrut(5));
      hbox.add(newAsset);

      // pPotentials.put(oldAsset, newAsset);
    }
    list.add(Box.createVerticalStrut(5));

    return hbox; // toReturn;
  } // return assetChoiceBox
 public synchronized void disconnect(Peer p) {
   DownloadTask dt = task.remove(p.toString());
   if (dt != null) {
     dt.end();
     dt = null;
   }
 }