private int maxTagLength() {
   int tl = 0;
   for (String tag : gappedAlignments.keySet()) {
     tl = Math.max(tl, tag.length());
   }
   return tl;
 }
  private void putMap(String name, Map m) {
    _put(OBJECT, name);
    final int sizePos = _buf.position();
    _buf.putInt(0);

    for (Object key : m.keySet()) _putObjectField(key.toString(), m.get(key));

    _buf.put(EOO);
    _buf.putInt(sizePos, _buf.position() - sizePos);
  }
Exemple #3
0
 static boolean isComposite(String name, Map<String, String[]> params) {
   for (String pName : params.keySet()) {
     if (pName.startsWith(name + ".")
         && params.get(pName) != null
         && params.get(pName).length > 0) {
       return true;
     }
   }
   return false;
 }
 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);
     }
   }
 }
Exemple #6
0
 public Set /*<PCNode>*/ matchSpecific(Pattern simple_name_pattern) {
   Set matches = new HashSet();
   Iterator ii = inners.keySet().iterator();
   while (ii.hasNext()) {
     String inner = (String) ii.next();
     // System.out.print("Matching "+inner+" against "+simple_name_pattern.pattern()+": ");
     if (simple_name_pattern.matcher(inner).matches()) {
       // System.out.println("true");
       matches.add(inners.get(inner));
     } else {
       // System.out.println("false");
     }
   }
   return matches;
 }
 /**
  * returns the multiple alignment as a string in a fashion identical to that in a file of
  * ALN/CLUSTALW format (except from the fact that info about residues' match is missing. Aka, the
  * 3rd line of a file of ALN/CLUSTALW ('*', '.', ':' chars) is missing).
  *
  * <p>(Note: CLUSTALW doesn't necessarily have the match characters... -Tim)
  */
 public String toString() {
   StringBuilder sb = new StringBuilder();
   int tl = maxTagLength();
   int i = 0, last = gappedAlignments.keySet().size() - 1;
   for (String tag : gappedAlignments.keySet()) {
     sb.append(StringUtils.padString(tag, tl));
     sb.append("  ");
     sb.append(gappedAlignments.get(tag).gappedString());
     if (i < last) {
       sb.append("\n");
     }
     i += 1;
   }
   return sb.toString();
 }
  /** Method to dump debugging information */
  private void dumpAll(Map map, int lvmid) {
    if (DEBUG) {
      Set keys = map.keySet();

      System.err.println("Dump for " + lvmid);
      int j = 0;
      for (Iterator i = keys.iterator(); i.hasNext(); j++) {
        Monitor monitor = (Monitor) map.get(i.next());
        System.err.println(j + "\t" + monitor.getName() + "=" + monitor.getValue());
      }
      System.err.println("nextEntry = " + nextEntry + " pollForEntry = " + pollForEntry);
      System.err.println("Buffer info:");
      System.err.println("buffer = " + buffer);
    }
  }
 private List<String> computeOverallSurvivalStatus(Map<String, SurvivalData> survivalData) {
   List<String> osStatus = initializeList(canonicalPatientList.size());
   for (String patientId : survivalData.keySet()) {
     int osStatusIndex = canonicalPatientList.indexOf(patientId);
     SurvivalData sd = survivalData.get(patientId);
     if (VitalStatusAlive.has(sd.vitalStatus)) {
       osStatus.set(osStatusIndex, VitalStatusAlive.LIVING.toString());
     } else if (VitalStatusDead.has(sd.vitalStatus)) {
       osStatus.set(osStatusIndex, VitalStatusDead.DECEASED.toString());
     } else {
       osStatus.set(osStatusIndex, ClinicalAttribute.NA);
     }
   }
   return osStatus;
 }
  private List<String> computeOverallSurvivalMonths(Map<String, SurvivalData> survivalData) {
    List<String> osStatusMonths = initializeList(canonicalPatientList.size());
    for (String patientId : survivalData.keySet()) {
      int osStatusMonthsIndex = canonicalPatientList.indexOf(patientId);
      SurvivalData sd = survivalData.get(patientId);
      if (VitalStatusAlive.has(sd.vitalStatus)) {
        osStatusMonths.set(
            osStatusMonthsIndex, convertDaysToMonths(sd.lastFollowUp, sd.lastKnownAlive));
      } else if (VitalStatusDead.has(sd.vitalStatus)) {
        osStatusMonths.set(osStatusMonthsIndex, convertDaysToMonths(sd.daysToDeath));
      } else {
        osStatusMonths.set(osStatusMonthsIndex, ClinicalAttribute.NA);
      }
    }

    return osStatusMonths;
  }
 private List<String> computeDiseaseFreeStatus(Map<String, DiseaseFreeData> diseaseFreeData) {
   List<String> dfStatus = initializeList(canonicalPatientList.size());
   for (String patientId : diseaseFreeData.keySet()) {
     int dfStatusIndex = canonicalPatientList.indexOf(patientId);
     DiseaseFreeData df = diseaseFreeData.get(patientId);
     if (patientIsDiseaseFree(df)) {
       dfStatus.set(dfStatusIndex, DiseaseFreeStatus.DISEASE_FREE.toString());
     } else {
       try {
         Integer.parseInt(df.daysToNewTumorEventAfterInitialTreatment);
         dfStatus.set(dfStatusIndex, DiseaseFreeStatus.DISEASED.toString());
       } catch (NumberFormatException e) {
         dfStatus.set(dfStatusIndex, ClinicalAttribute.NA);
       }
     }
   }
   return dfStatus;
 }
  private List<String> computeDiseaseFreeMonths(Map<String, DiseaseFreeData> diseaseFreeData) {
    List<String> dfStatusMonths = initializeList(canonicalPatientList.size());
    for (String patientId : diseaseFreeData.keySet()) {
      int dfStatusMonthsIndex = canonicalPatientList.indexOf(patientId);
      DiseaseFreeData df = diseaseFreeData.get(patientId);
      try {
        if (patientIsDiseaseFree(df)) {
          dfStatusMonths.set(
              dfStatusMonthsIndex, convertDaysToMonths(df.lastFollowUp, df.lastKnownAlive));
        } else {
          int dfStatusDays = Integer.parseInt(df.daysToNewTumorEventAfterInitialTreatment);
          dfStatusMonths.set(
              dfStatusMonthsIndex, convertDaysToMonths(Integer.toString(dfStatusDays)));
        }
      } catch (NumberFormatException e) {
        dfStatusMonths.set(dfStatusMonthsIndex, ClinicalAttribute.NA);
      }
    }

    return dfStatusMonths;
  }
  private void discoverAndRunProcs(
      Context context,
      Set<TypeElement> annotationsPresent,
      List<ClassSymbol> topLevelClasses,
      List<PackageSymbol> packageInfoFiles) {
    Map<String, TypeElement> unmatchedAnnotations =
        new HashMap<String, TypeElement>(annotationsPresent.size());

    for (TypeElement a : annotationsPresent) {
      unmatchedAnnotations.put(a.getQualifiedName().toString(), a);
    }

    // Give "*" processors a chance to match
    if (unmatchedAnnotations.size() == 0) unmatchedAnnotations.put("", null);

    DiscoveredProcessors.ProcessorStateIterator psi = discoveredProcs.iterator();
    // TODO: Create proper argument values; need past round
    // information to fill in this constructor.  Note that the 1
    // st round of processing could be the last round if there
    // were parse errors on the initial source files; however, we
    // are not doing processing in that case.

    Set<Element> rootElements = new LinkedHashSet<Element>();
    rootElements.addAll(topLevelClasses);
    rootElements.addAll(packageInfoFiles);
    rootElements = Collections.unmodifiableSet(rootElements);

    RoundEnvironment renv =
        new JavacRoundEnvironment(false, false, rootElements, JavacProcessingEnvironment.this);

    while (unmatchedAnnotations.size() > 0 && psi.hasNext()) {
      ProcessorState ps = psi.next();
      Set<String> matchedNames = new HashSet<String>();
      Set<TypeElement> typeElements = new LinkedHashSet<TypeElement>();

      for (Map.Entry<String, TypeElement> entry : unmatchedAnnotations.entrySet()) {
        String unmatchedAnnotationName = entry.getKey();
        if (ps.annotationSupported(unmatchedAnnotationName)) {
          matchedNames.add(unmatchedAnnotationName);
          TypeElement te = entry.getValue();
          if (te != null) typeElements.add(te);
        }
      }

      if (matchedNames.size() > 0 || ps.contributed) {
        boolean processingResult = callProcessor(ps.processor, typeElements, renv);
        ps.contributed = true;
        ps.removeSupportedOptions(unmatchedProcessorOptions);

        if (printProcessorInfo || verbose) {
          log.printNoteLines(
              "x.print.processor.info",
              ps.processor.getClass().getName(),
              matchedNames.toString(),
              processingResult);
        }

        if (processingResult) {
          unmatchedAnnotations.keySet().removeAll(matchedNames);
        }
      }
    }
    unmatchedAnnotations.remove("");

    if (lint && unmatchedAnnotations.size() > 0) {
      // Remove annotations processed by javac
      unmatchedAnnotations.keySet().removeAll(platformAnnotations);
      if (unmatchedAnnotations.size() > 0) {
        log = Log.instance(context);
        log.warning("proc.annotations.without.processors", unmatchedAnnotations.keySet());
      }
    }

    // Run contributing processors that haven't run yet
    psi.runContributingProcs(renv);

    // Debugging
    if (options.isSet("displayFilerState")) filer.displayState();
  }
 private Set<String> initUnmatchedProcessorOptions() {
   Set<String> unmatchedProcessorOptions = new HashSet<String>();
   unmatchedProcessorOptions.addAll(processorOptions.keySet());
   return unmatchedProcessorOptions;
 }
Exemple #15
0
  @SuppressWarnings("unchecked")
  static Object bindInternal(
      String name,
      Class clazz,
      Type type,
      Annotation[] annotations,
      Map<String, String[]> params,
      String suffix,
      String[] profiles) {
    try {
      Logger.trace("bindInternal: name [" + name + "] suffix [" + suffix + "]");

      String[] value = params.get(name + suffix);
      Logger.trace("bindInternal: value [" + value + "]");
      Logger.trace("bindInternal: profile [" + Utils.join(profiles, ",") + "]");
      // Let see if we have a BindAs annotation and a separator. If so, we need to split the values
      // Look up for the BindAs annotation. Extract the profile if there is any.
      // TODO: Move me somewhere else?
      if (annotations != null) {
        for (Annotation annotation : annotations) {
          if ((clazz.isArray() || Collection.class.isAssignableFrom(clazz))
              && value != null
              && value.length > 0
              && annotation.annotationType().equals(As.class)) {
            As as = ((As) annotation);
            final String separator = as.value()[0];
            value = value[0].split(separator);
          }
          if (annotation.annotationType().equals(NoBinding.class)) {
            NoBinding bind = ((NoBinding) annotation);
            String[] localUnbindProfiles = bind.value();
            Logger.trace(
                "bindInternal: localUnbindProfiles [" + Utils.join(localUnbindProfiles, ",") + "]");

            if (localUnbindProfiles != null && contains(profiles, localUnbindProfiles)) {
              return NO_BINDING;
            }
          }
        }
      }

      // Arrays types
      // The array condition is not so nice... We should find another way of doing this....
      if (clazz.isArray()
          && (clazz != byte[].class
              && clazz != byte[][].class
              && clazz != File[].class
              && clazz != Upload[].class)) {
        if (value == null) {
          value = params.get(name + suffix + "[]");
        }
        if (value == null) {
          return MISSING;
        }
        Object r = Array.newInstance(clazz.getComponentType(), value.length);
        for (int i = 0; i <= value.length; i++) {
          try {
            Array.set(r, i, directBind(name, annotations, value[i], clazz.getComponentType()));
          } catch (Exception e) {
            // ?? One item was bad
          }
        }
        return r;
      }
      // Enums
      if (Enum.class.isAssignableFrom(clazz)) {
        if (value == null || value.length == 0) {
          return MISSING;
        } else if (StringUtils.isEmpty(value[0])) {
          return null;
        }
        return Enum.valueOf(clazz, value[0]);
      }
      // Map
      if (Map.class.isAssignableFrom(clazz)) {
        Class keyClass = String.class;
        Class valueClass = String.class;
        if (type instanceof ParameterizedType) {
          keyClass = (Class) ((ParameterizedType) type).getActualTypeArguments()[0];
          valueClass = (Class) ((ParameterizedType) type).getActualTypeArguments()[1];
        }

        // Special case Map<String, String>
        // Multivalues composite params are binded to a Map<String, String>
        // see http://play.lighthouseapp.com/projects/57987/tickets/443
        if (keyClass == String.class && valueClass == String.class && isComposite(name, params)) {
          Map<String, String> stringMap = Utils.filterParams(params, name);
          if (stringMap.size() > 0) return stringMap;
        }

        // Search for all params
        Map<Object, Object> r = new HashMap<Object, Object>();
        for (String param : params.keySet()) {
          Pattern p = Pattern.compile("^" + name + suffix + "\\[([^\\]]+)\\](.*)$");
          Matcher m = p.matcher(param);
          if (m.matches()) {
            String key = m.group(1);
            value = params.get(param);
            Map<String, String[]> tP = new HashMap<String, String[]>();
            tP.put("key", new String[] {key});
            Object oKey = bindInternal("key", keyClass, keyClass, annotations, tP, "", value);
            if (oKey != MISSING) {
              if (isComposite(name + suffix + "[" + key + "]", params)) {
                BeanWrapper beanWrapper = getBeanWrapper(valueClass);
                Object oValue =
                    beanWrapper.bind(
                        "", type, params, name + suffix + "[" + key + "]", annotations);
                r.put(oKey, oValue);
              } else {
                tP = new HashMap<String, String[]>();
                tP.put("value", params.get(name + suffix + "[" + key + "]"));
                Object oValue =
                    bindInternal("value", valueClass, valueClass, annotations, tP, "", value);
                if (oValue != MISSING) {
                  r.put(oKey, oValue);
                } else {
                  r.put(oKey, null);
                }
              }
            }
          }
        }
        return r;
      }
      // Collections types
      if (Collection.class.isAssignableFrom(clazz)) {
        if (clazz.isInterface()) {
          if (clazz.equals(List.class)) {
            clazz = ArrayList.class;
          }
          if (clazz.equals(Set.class)) {
            clazz = HashSet.class;
          }
          if (clazz.equals(SortedSet.class)) {
            clazz = TreeSet.class;
          }
        }
        Collection r = (Collection) clazz.newInstance();
        Class componentClass = String.class;
        if (type instanceof ParameterizedType) {
          componentClass = (Class) ((ParameterizedType) type).getActualTypeArguments()[0];
        }
        // Create a an array of the component class
        if (value != null) {
          Object customArray = Array.newInstance(componentClass, value.length);
          // custom types
          for (Class<?> c : supportedTypes.keySet()) {
            if (c.isAssignableFrom(customArray.getClass())) {
              Object[] ar =
                  (Object[])
                      supportedTypes
                          .get(c)
                          .bind("value", annotations, name, customArray.getClass(), null);
              List l = Arrays.asList(ar);
              if (clazz.equals(HashSet.class)) {
                return new HashSet(l);
              } else if (clazz.equals(TreeSet.class)) {
                return new TreeSet(l);
              }
              return l;
            }
          }
        }
        if (value == null) {
          value = params.get(name + suffix + "[]");
          if (value == null && r instanceof List) {
            for (String param : params.keySet()) {
              Pattern p = Pattern.compile("^" + escape(name + suffix) + "\\[([0-9]+)\\](.*)$");
              Matcher m = p.matcher(param);
              if (m.matches()) {
                int key = Integer.parseInt(m.group(1));
                while (((List<?>) r).size() <= key) {
                  ((List<?>) r).add(null);
                }
                if (isComposite(name + suffix + "[" + key + "]", params)) {
                  BeanWrapper beanWrapper = getBeanWrapper(componentClass);
                  Object oValue =
                      beanWrapper.bind(
                          "", type, params, name + suffix + "[" + key + "]", annotations);
                  ((List) r).set(key, oValue);
                } else {
                  Map<String, String[]> tP = new HashMap<String, String[]>();
                  tP.put("value", params.get(name + suffix + "[" + key + "]"));
                  Object oValue =
                      bindInternal(
                          "value", componentClass, componentClass, annotations, tP, "", value);
                  if (oValue != MISSING) {
                    ((List) r).set(key, oValue);
                  }
                }
              }
            }
            return r.isEmpty() ? MISSING : r;
          }
        }
        if (value == null) {
          return MISSING;
        }
        for (String v : value) {
          try {
            r.add(directBind(name, annotations, v, componentClass));
          } catch (Exception e) {
            // ?? One item was bad
            Logger.debug(e, "error:");
          }
        }
        return r;
      }

      // Assume a Bean if isComposite
      Logger.trace(
          "bindInternal: class ["
              + clazz
              + "] name ["
              + name
              + "] annotation ["
              + Utils.join(annotations, " ")
              + "] isComposite ["
              + isComposite(name + suffix, params)
              + "]");
      if (isComposite(name + suffix, params)) {
        BeanWrapper beanWrapper = getBeanWrapper(clazz);
        return beanWrapper.bind(name, type, params, suffix, annotations);
      }

      // Simple types
      if (value == null || value.length == 0) {
        return MISSING;
      }

      return directBind(name, annotations, value[0], clazz, type);
    } catch (Exception e) {
      Validation.addError(name + suffix, "validation.invalid");
      return MISSING;
    }
  }