/** {@inheritDoc} */
  protected void getNewMonitors(Map<String, Monitor> map) throws MonitorException {
    assert Thread.holdsLock(this);

    int used = prologue.getUsed();
    long modificationTime = prologue.getModificationTimeStamp();

    if ((used > lastUsed) || (lastModificationTime > modificationTime)) {

      lastUsed = used;
      lastModificationTime = modificationTime;

      Monitor monitor = getNextMonitorEntry();
      while (monitor != null) {
        String name = monitor.getName();

        // guard against duplicate entries
        if (!map.containsKey(name)) {
          map.put(name, monitor);

          /*
           * insertedMonitors is null when called from pollFor()
           * via buildMonitorMap(). Since we update insertedMonitors
           * at the end of buildMonitorMap(), it's ok to skip the
           * add here.
           */
          if (insertedMonitors != null) {
            insertedMonitors.add(monitor);
          }
        }
        monitor = getNextMonitorEntry();
      }
    }
  }
Example #2
0
 PCNode insertFullName(String full_name, boolean cl, boolean weavable) {
   int dotpos = full_name.indexOf('.');
   String head;
   String rest;
   if (dotpos == -1) {
     head = full_name;
     rest = null;
   } else {
     head = full_name.substring(0, dotpos);
     rest = full_name.substring(dotpos + 1);
   }
   PCNode child;
   if (!inners.containsKey(head)) {
     child = new PCNode(head, this, root);
     inners.put(head, child);
   } else {
     child = (PCNode) inners.get(head);
   }
   if (rest != null) {
     return child.insertFullName(rest, cl, weavable);
   } else {
     child.is_class |= cl;
     child.is_weavable |= weavable;
     return child;
   }
 }
  // Store the invariant for later printing. Ignore duplicate
  // invariants at the same program point.
  private static boolean store_invariant(
      String predicate, String index, HashedConsequent consequent, String pptname) {
    if (!pptname_to_conditions.containsKey(pptname)) {
      pptname_to_conditions.put(pptname, new HashMap<String, Map<String, HashedConsequent>>());
    }

    Map<String, Map<String, HashedConsequent>> cluster_to_conditions =
        pptname_to_conditions.get(pptname);
    if (!cluster_to_conditions.containsKey(predicate)) {
      cluster_to_conditions.put(predicate, new HashMap<String, HashedConsequent>());
    }

    Map<String, HashedConsequent> conditions = cluster_to_conditions.get(predicate);
    if (conditions.containsKey(index)) {
      HashedConsequent old = conditions.get(index);
      if (old.fakeFor != null && consequent.fakeFor == null) {
        // We already saw (say) "x != y", but we're "x == y", so replace it.
        conditions.remove(index);
        conditions.remove(old.fakeFor);
        conditions.put(index, consequent);
        return true;
      }
      return false;
    } else {
      conditions.put(index, consequent);
      return true;
    }
  }
Example #4
0
 @Override
 public Node execute(ExecutionContext ec, Template tmpl) throws IOException { // {{{
   Map<String, StartNamedBlock> blocks = tmpl.getBlocks();
   Node n = blocks.get(this.blockName);
   if (blocks.containsKey(this.blockName)) {
     return blocks.get(this.blockName).getExecuteNode();
   } else {
     return this.executeNode;
   }
   // return this.getNextNode();
 } // }}}
 private void mergeDiseaseFreeData(
     Map<String, DiseaseFreeData> sourceMap, Map<String, DiseaseFreeData> destMap) {
   for (String patientId : sourceMap.keySet()) {
     DiseaseFreeData diseaseFreeData = sourceMap.get(patientId);
     if (destMap.containsKey(patientId)) {
       destMap.put(patientId, mergeDiseaseFreeData(destMap.get(patientId), diseaseFreeData));
     } else {
       destMap.put(patientId, diseaseFreeData);
     }
   }
 }
 private void mergeSurvivalData(
     Map<String, SurvivalData> sourceMap, Map<String, SurvivalData> destMap) {
   for (String patientId : sourceMap.keySet()) {
     SurvivalData survivalData = sourceMap.get(patientId);
     if (destMap.containsKey(patientId)) {
       destMap.put(patientId, mergeSurvivalData(destMap.get(patientId), survivalData));
     } else {
       destMap.put(patientId, survivalData);
     }
   }
 }
Example #7
0
  /**
   * The convert method translates a String input to a specified outbound level of the same coding
   * scheme. For example, the input string value may be a tag-encoding URI and the outbound level
   * specified by string outboundlevel may be BINARY, in which case the return value is a binary
   * representation expressed as a string.
   *
   * @param input the identifier to be converted.
   * @param inputParameters additional parameters which need to be provided because they cannot
   *     always be determined from the input value alone. Examples include the taglength,
   *     companyprefixlength and filter values.
   * @param outputLevel the outbound level required for the ouput. Permitted values include BINARY,
   *     TAG_ENCODING, PURE_IDENTITY, LEGACY and ONS_HOSTNAME.
   * @return the identifier converted to the output level.
   */
  public String convert(
      String input, Map<String, String> inputParameters, LevelTypeList outputLevel) {

    TagLengthList tagLength = null;
    if (inputParameters.containsKey("taglength")) {
      // in principle, the user should provide a
      // TagLengthList object in the parameter list.
      String s = inputParameters.get("taglength");
      tagLength = TagLengthList.valueOf(s);
    }

    PrefixMatch match = findPrefixMatch(input, tagLength);

    return convertLevel(match.getScheme(), match.getLevel(), input, inputParameters, outputLevel);
  }
  private Map<String, DiseaseFreeData> getDiseaseFreeDataForMatrix(DataMatrix dataMatrix) {
    Map<String, DiseaseFreeData> diseaseFreeDataMap = new HashMap<String, DiseaseFreeData>();

    List<String> patientIds = getPatientIds(dataMatrix);
    for (int lc = 0; lc < patientIds.size(); lc++) {
      String patientId = patientIds.get(lc);
      DiseaseFreeData df = getDiseaseFreeDataForPatient(lc, dataMatrix);
      if (diseaseFreeDataMap.containsKey(patientId)) {
        df = mergeDiseaseFreeData(diseaseFreeDataMap.get(patientId), df);
      }
      diseaseFreeDataMap.put(patientId, df);
    }

    return diseaseFreeDataMap;
  }
  private Map<String, SurvivalData> getSurvivalDataForMatrix(DataMatrix dataMatrix) {
    Map<String, SurvivalData> survivalDataMap = new HashMap<String, SurvivalData>();

    List<String> patientIds = getPatientIds(dataMatrix);
    for (int lc = 0; lc < patientIds.size(); lc++) {
      String patientId = patientIds.get(lc);
      SurvivalData sd = getSurvivalDataForPatient(lc, dataMatrix);
      if (survivalDataMap.containsKey(patientId)) {
        sd = mergeSurvivalData(survivalDataMap.get(patientId), sd);
      }
      survivalDataMap.put(patientId, sd);
    }

    return survivalDataMap;
  }
Example #10
0
 /**
  * Returns the value of a specified fieldname from the specified hashmap and returns an integer
  * value or throws an exception if the value is not an integer
  */
 private int getIntValue(String fieldname, Map<String, String> extraparams) {
   Matcher checkint = Pattern.compile("^\\d+$").matcher(fieldname);
   int rv;
   if (checkint.matches()) {
     rv = Integer.parseInt(fieldname);
   } else {
     if (extraparams.containsKey(fieldname)) {
       rv = Integer.parseInt(extraparams.get(fieldname));
     } else {
       rv = -1;
       throw new TDTException(
           "No integer value for " + fieldname + " can be found - check extraparams");
     }
   }
   return rv;
 }
Example #11
0
  static int lonelyInteger(int[] arr) {
    Map<Integer, Integer> occurrences = new HashMap<>();
    for (int value : arr) {
      boolean alreadyExist = occurrences.containsKey(value);
      if (!alreadyExist) {
        occurrences.put(value, 0);
      }
      occurrences.put(value, occurrences.get(value) + 1);
    }

    int result = 0;

    for (java.util.Map.Entry<Integer, Integer> entry : occurrences.entrySet()) {
      if (entry.getValue().equals(1)) {
        result = entry.getKey();
      }
    }

    return result;
  }