예제 #1
0
 Record rdataFromString(Name name, short dclass, int ttl, MyStringTokenizer st, Name origin)
     throws TextParseException {
   SIGRecord rec = new SIGRecord(name, dclass, ttl);
   rec.covered = Type.value(st.nextToken());
   rec.alg = Byte.parseByte(st.nextToken());
   rec.labels = Byte.parseByte(st.nextToken());
   rec.origttl = TTL.parseTTL(st.nextToken());
   rec.expire = parseDate(st.nextToken());
   rec.timeSigned = parseDate(st.nextToken());
   rec.footprint = (short) Integer.parseInt(st.nextToken());
   rec.signer = Name.fromString(st.nextToken(), origin);
   if (st.hasMoreTokens()) rec.signature = base64.fromString(st.remainingTokens());
   return rec;
 }
예제 #2
0
  // Gets a property and converts it into byte.
  static byte getByteProperty(String propName, byte defaultValue) {

    String temp = getConfigValue(propName);
    byte result = defaultValue;
    if (temp != null) {
      result = Byte.parseByte(temp);
      Logger.info("{DB}-" + propName + ":" + result);
    } else {

      result = Byte.parseByte(properties.getProperty(propName, Byte.toString(defaultValue)).trim());
      Logger.info("{FILE}-" + propName + ":" + result);
    }

    return result;
  }
  /**
   * Parses the arguments table from the GATK Report and creates a RAC object with the proper
   * initialization values
   *
   * @param table the GATKReportTable containing the arguments and its corresponding values
   * @return a RAC object properly initialized with all the objects in the table
   */
  private RecalibrationArgumentCollection initializeArgumentCollectionTable(GATKReportTable table) {
    final RecalibrationArgumentCollection RAC = new RecalibrationArgumentCollection();

    for (int i = 0; i < table.getNumRows(); i++) {
      final String argument = table.get(i, "Argument").toString();
      Object value = table.get(i, RecalUtils.ARGUMENT_VALUE_COLUMN_NAME);
      if (value.equals("null"))
        value =
            null; // generic translation of null values that were printed out as strings | todo --
                  // add this capability to the GATKReport

      if (argument.equals("covariate") && value != null)
        RAC.COVARIATES = value.toString().split(",");
      else if (argument.equals("standard_covs"))
        RAC.DO_NOT_USE_STANDARD_COVARIATES = Boolean.parseBoolean((String) value);
      else if (argument.equals("solid_recal_mode"))
        RAC.SOLID_RECAL_MODE = RecalUtils.SOLID_RECAL_MODE.recalModeFromString((String) value);
      else if (argument.equals("solid_nocall_strategy"))
        RAC.SOLID_NOCALL_STRATEGY =
            RecalUtils.SOLID_NOCALL_STRATEGY.nocallStrategyFromString((String) value);
      else if (argument.equals("mismatches_context_size"))
        RAC.MISMATCHES_CONTEXT_SIZE = Integer.parseInt((String) value);
      else if (argument.equals("indels_context_size"))
        RAC.INDELS_CONTEXT_SIZE = Integer.parseInt((String) value);
      else if (argument.equals("mismatches_default_quality"))
        RAC.MISMATCHES_DEFAULT_QUALITY = Byte.parseByte((String) value);
      else if (argument.equals("insertions_default_quality"))
        RAC.INSERTIONS_DEFAULT_QUALITY = Byte.parseByte((String) value);
      else if (argument.equals("deletions_default_quality"))
        RAC.DELETIONS_DEFAULT_QUALITY = Byte.parseByte((String) value);
      else if (argument.equals("maximum_cycle_value"))
        RAC.MAXIMUM_CYCLE_VALUE = Integer.parseInt((String) value);
      else if (argument.equals("low_quality_tail"))
        RAC.LOW_QUAL_TAIL = Byte.parseByte((String) value);
      else if (argument.equals("default_platform")) RAC.DEFAULT_PLATFORM = (String) value;
      else if (argument.equals("force_platform")) RAC.FORCE_PLATFORM = (String) value;
      else if (argument.equals("quantizing_levels"))
        RAC.QUANTIZING_LEVELS = Integer.parseInt((String) value);
      else if (argument.equals("recalibration_report"))
        RAC.existingRecalibrationReport = (value == null) ? null : new File((String) value);
      else if (argument.equals("binary_tag_name"))
        RAC.BINARY_TAG_NAME = (value == null) ? null : (String) value;
      else if (argument.equals("sort_by_all_columns"))
        RAC.SORT_BY_ALL_COLUMNS = Boolean.parseBoolean((String) value);
    }

    return RAC;
  }
예제 #4
0
  /**
   * Applies a list of transformation on a block, if the block is not protected.
   *
   * @param toTransform the Bukkit block object to transform
   * @param transformations the list if transformations to apply
   */
  public static void transform(Block toTransform, List<List<String>> transformations) {
    if (isBlockProtected(toTransform)) {
      return;
    }

    for (List<String> toCheck : transformations) {
      ArrayList<String[]> stateIndex = new ArrayList<String[]>();

      for (int i = 0; i != 2; ++i) {
        String got = toCheck.get(i);

        if (got.contains(":")) { // Check for data _ appended.
          stateIndex.add(got.split(":"));
        } else {
          stateIndex.add(new String[] {got, "0"});
        }
      }

      String[] curState = stateIndex.get(0), toState = stateIndex.get(1);

      if (Integer.valueOf(curState[0]) == toTransform.getTypeId()
          && Integer.valueOf(curState[1]) == toTransform.getData()) {
        toTransform.setTypeIdAndData(Integer.valueOf(toState[0]), Byte.parseByte(toState[1]), true);
        return;
      }
    }
  }
  private RecalDatum getRecalDatum(
      final GATKReportTable reportTable, final int row, final boolean hasEstimatedQReportedColumn) {
    final long nObservations =
        asLong(reportTable.get(row, RecalUtils.NUMBER_OBSERVATIONS_COLUMN_NAME));
    final double nErrors = asDouble(reportTable.get(row, RecalUtils.NUMBER_ERRORS_COLUMN_NAME));
    // final double empiricalQuality = asDouble(reportTable.get(row,
    // RecalUtils.EMPIRICAL_QUALITY_COLUMN_NAME));

    // the estimatedQreported column only exists in the ReadGroup table
    final double estimatedQReported =
        hasEstimatedQReportedColumn
            ? (Double) reportTable.get(row, RecalUtils.ESTIMATED_Q_REPORTED_COLUMN_NAME)
            : // we get it if we are in the read group table
            Byte.parseByte(
                (String)
                    reportTable.get(
                        row,
                        RecalUtils
                            .QUALITY_SCORE_COLUMN_NAME)); // or we use the reported quality if we
                                                          // are in any other table

    final RecalDatum datum = new RecalDatum(nObservations, nErrors, (byte) 1);
    datum.setEstimatedQReported(estimatedQReported);
    // datum.setEmpiricalQuality(empiricalQuality); // don't set the value here because we will want
    // to recompute with a different conditional Q score prior value
    return datum;
  }
예제 #6
0
  private boolean compare_Byte(int operation, byte byteval, Object value2) {
    if (operation == SUBSTRING) {
      return false;
    }
    byte byteval2;
    try {
      byteval2 = Byte.parseByte(((String) value2).trim());
    } catch (IllegalArgumentException e) {
      return false;
    }

    switch (operation) {
      case APPROX:
      case EQUAL:
        {
          return byteval == byteval2;
        }
      case GREATER:
        {
          return byteval >= byteval2;
        }
      case LESS:
        {
          return byteval <= byteval2;
        }
    }
    return false;
  }
예제 #7
0
 /**
  * Check for byte
  *
  * @param input
  * @return
  */
 public static boolean isByte(String input) {
   try {
     Byte.parseByte(input);
     return true;
   } catch (Exception ex) {
     return false;
   }
 }
예제 #8
0
  private static byte getByteData(String byte1Str) throws Exception {
    byte data_LC;
    byte byte1 = Byte.parseByte(byte1Str);
    // byte byte2 =  Byte.parseByte(byte2Str);
    data_LC = byte1;
    // data_LC[1] = byte2;

    return data_LC;
  }
예제 #9
0
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // For each test
    StringBuffer sb = new StringBuffer();
    for (byte T = Byte.parseByte(br.readLine()); T > 0; --T) {

      // INPUT
      byte N = Byte.parseByte(br.readLine());
      int[] A = new int[N];
      N = 0;
      for (String s : br.readLine().split(" ")) {
        A[N++] = Integer.parseInt(s);
      }

      sb.append(solve(A, N) ? YES : NO);
    }
    System.out.print(sb);
  }
예제 #10
0
  /** Loads dependencies and initializes data structures. */
  @Override
  public void init(FloodlightModuleContext context) throws FloodlightModuleException {
    log.info(String.format("Initializing %s...", MODULE_NAME));
    Map<String, String> config = context.getConfigParams(this);
    table = Byte.parseByte(config.get("table"));

    this.floodlightProv = context.getServiceImpl(IFloodlightProviderService.class);
    this.linkDiscProv = context.getServiceImpl(ILinkDiscoveryService.class);
    this.deviceProv = context.getServiceImpl(IDeviceService.class);

    this.knownHosts = new ConcurrentHashMap<IDevice, Host>();
  }
예제 #11
0
파일: URL.java 프로젝트: yungoo/apple-qos
 public byte getParameter(String key, byte defaultValue) {
   Number n = getNumbers().get(key);
   if (n != null) {
     return n.byteValue();
   }
   String value = getParameter(key);
   if (value == null || value.length() == 0) {
     return defaultValue;
   }
   byte b = Byte.parseByte(value);
   getNumbers().put(key, b);
   return b;
 }
예제 #12
0
파일: URL.java 프로젝트: yungoo/apple-qos
 public byte getMethodParameter(String method, String key, byte defaultValue) {
   String methodKey = method + "." + key;
   Number n = getNumbers().get(methodKey);
   if (n != null) {
     return n.byteValue();
   }
   String value = getMethodParameter(method, key);
   if (value == null || value.length() == 0) {
     return defaultValue;
   }
   byte b = Byte.parseByte(value);
   getNumbers().put(methodKey, b);
   return b;
 }
 /**
  * Parses the quantization table from the GATK Report and turns it into a map of original =>
  * quantized quality scores
  *
  * @param table the GATKReportTable containing the quantization mappings
  * @return an ArrayList with the quantization mappings from 0 to MAX_SAM_QUAL_SCORE
  */
 private QuantizationInfo initializeQuantizationTable(GATKReportTable table) {
   final Byte[] quals = new Byte[QualityUtils.MAX_SAM_QUAL_SCORE + 1];
   final Long[] counts = new Long[QualityUtils.MAX_SAM_QUAL_SCORE + 1];
   for (int i = 0; i < table.getNumRows(); i++) {
     final byte originalQual = (byte) i;
     final Object quantizedObject = table.get(i, RecalUtils.QUANTIZED_VALUE_COLUMN_NAME);
     final Object countObject = table.get(i, RecalUtils.QUANTIZED_COUNT_COLUMN_NAME);
     final byte quantizedQual = Byte.parseByte(quantizedObject.toString());
     final long quantizedCount = Long.parseLong(countObject.toString());
     quals[originalQual] = quantizedQual;
     counts[originalQual] = quantizedCount;
   }
   return new QuantizationInfo(Arrays.asList(quals), Arrays.asList(counts));
 }
예제 #14
0
  @Override
  public Response debug(Debug debug) throws TException {
    Set<Byte> partitions;
    if (debug.getType() == DebugCommands.POPULATE_FILE.getId()) {
      partitions = oracle.partitionsOf("/");
    } else {
      partitions = new HashSet<>();
      partitions.add(Byte.valueOf(Byte.parseByte(debug.getData().get("partition"))));
    }

    Command cmd = newCommand(CommandType.DEBUG, partitions, null);
    cmd.setDebug(debug);
    replica.submitCommand(cmd);
    Response r = new Response(replica.getInstanceMap());
    return r;
  }
  // Deserialize object into a row for the table
  @Override
  public Object deserialize(Writable blob) throws SerDeException {
    Text rowText = (Text) blob;
    String[] values = rowText.toString().split("\t");
    String queryString = values[1];

    if (LOG.isDebugEnabled()) {
      LOG.debug("Deserialize row: " + queryString);
    }

    // create a map from log string
    Map<String, String> map = getQueryMap(queryString);
    map.put("key", values[0]);

    // Loop over columns in table and set values
    String colName;
    Object value;
    for (int c = 0; c < numColumns; c++) {
      colName = columnNames.get(c).toLowerCase();
      TypeInfo ti = columnTypes.get(c);

      if (!map.containsKey(colName)) {
        value = null;
      } else if (ti.getTypeName().equalsIgnoreCase(serdeConstants.DOUBLE_TYPE_NAME)) {
        value = Double.parseDouble(map.get(colName));
      } else if (ti.getTypeName().equalsIgnoreCase(serdeConstants.BIGINT_TYPE_NAME)) {
        value = Long.parseLong(map.get(colName));
      } else if (ti.getTypeName().equalsIgnoreCase(serdeConstants.INT_TYPE_NAME)) {
        value = Integer.parseInt(map.get(colName));
      } else if (ti.getTypeName().equalsIgnoreCase(serdeConstants.TINYINT_TYPE_NAME)) {
        value = Byte.parseByte(map.get(colName));
      } else if (ti.getTypeName().equalsIgnoreCase(serdeConstants.FLOAT_TYPE_NAME)) {
        value = Float.parseFloat(map.get(colName));
      } else if (ti.getTypeName().equalsIgnoreCase(serdeConstants.BOOLEAN_TYPE_NAME)) {
        value = Boolean.parseBoolean(map.get(colName));
      } else {
        value = decode(map.get(colName));
      }
      row.set(c, value);
    }

    return row;
  }
예제 #16
0
  /**
   * Notifies this instance that the dynamic payload types of the associated {@link MediaStream}
   * have changed.
   */
  public void onDynamicPayloadTypesChanged() {
    rtxPayloadType = -1;
    rtxAssociatedPayloadType = -1;

    MediaStream mediaStream = channel.getStream();

    Map<Byte, MediaFormat> mediaFormatMap = mediaStream.getDynamicRTPPayloadTypes();

    Iterator<Map.Entry<Byte, MediaFormat>> it = mediaFormatMap.entrySet().iterator();

    while (it.hasNext() && rtxPayloadType == -1) {
      Map.Entry<Byte, MediaFormat> entry = it.next();
      MediaFormat format = entry.getValue();
      if (!Constants.RTX.equalsIgnoreCase(format.getEncoding())) {
        continue;
      }

      // XXX(gp) we freak out if multiple codecs with RTX support are
      // present.
      rtxPayloadType = entry.getKey();
      rtxAssociatedPayloadType = Byte.parseByte(format.getFormatParameters().get("apt"));
    }
  }
예제 #17
0
  @SuppressWarnings("unchecked")
  public static Object directBind(
      String name, Annotation[] annotations, String value, Class<?> clazz, Type type)
      throws Exception {
    Logger.trace(
        "directBind: value ["
            + value
            + "] annotation ["
            + Utils.join(annotations, " ")
            + "] Class ["
            + clazz
            + "]");

    boolean nullOrEmpty = value == null || value.trim().length() == 0;

    if (annotations != null) {
      for (Annotation annotation : annotations) {
        if (annotation.annotationType().equals(As.class)) {
          Class<? extends TypeBinder<?>> toInstanciate = ((As) annotation).binder();
          if (!(toInstanciate.equals(As.DEFAULT.class))) {
            // Instantiate the binder
            TypeBinder<?> myInstance = toInstanciate.newInstance();
            return myInstance.bind(name, annotations, value, clazz, type);
          }
        }
      }
    }

    // custom types
    for (Class<?> c : supportedTypes.keySet()) {
      Logger.trace("directBind: value [" + value + "] c [" + c + "] Class [" + clazz + "]");
      if (c.isAssignableFrom(clazz)) {
        Logger.trace("directBind: isAssignableFrom is true");
        return supportedTypes.get(c).bind(name, annotations, value, clazz, type);
      }
    }

    // application custom types
    for (Class<TypeBinder<?>> c : Play.classloader.getAssignableClasses(TypeBinder.class)) {
      if (c.isAnnotationPresent(Global.class)) {
        Class<?> forType =
            (Class) ((ParameterizedType) c.getGenericInterfaces()[0]).getActualTypeArguments()[0];
        if (forType.isAssignableFrom(clazz)) {
          return c.newInstance().bind(name, annotations, value, clazz, type);
        }
      }
    }

    // raw String
    if (clazz.equals(String.class)) {
      return value;
    }

    // Enums
    if (Enum.class.isAssignableFrom(clazz)) {
      if (nullOrEmpty) {
        return null;
      }
      return Enum.valueOf((Class<Enum>) clazz, value);
    }

    // int or Integer binding
    if (clazz.getName().equals("int") || clazz.equals(Integer.class)) {
      if (nullOrEmpty) {
        return clazz.isPrimitive() ? 0 : null;
      }

      return Integer.parseInt(value.contains(".") ? value.substring(0, value.indexOf(".")) : value);
    }

    // long or Long binding
    if (clazz.getName().equals("long") || clazz.equals(Long.class)) {
      if (nullOrEmpty) {
        return clazz.isPrimitive() ? 0l : null;
      }

      return Long.parseLong(value.contains(".") ? value.substring(0, value.indexOf(".")) : value);
    }

    // byte or Byte binding
    if (clazz.getName().equals("byte") || clazz.equals(Byte.class)) {
      if (nullOrEmpty) {
        return clazz.isPrimitive() ? (byte) 0 : null;
      }

      return Byte.parseByte(value.contains(".") ? value.substring(0, value.indexOf(".")) : value);
    }

    // short or Short binding
    if (clazz.getName().equals("short") || clazz.equals(Short.class)) {
      if (nullOrEmpty) {
        return clazz.isPrimitive() ? (short) 0 : null;
      }

      return Short.parseShort(value.contains(".") ? value.substring(0, value.indexOf(".")) : value);
    }

    // float or Float binding
    if (clazz.getName().equals("float") || clazz.equals(Float.class)) {
      if (nullOrEmpty) {
        return clazz.isPrimitive() ? 0f : null;
      }

      return Float.parseFloat(value);
    }

    // double or Double binding
    if (clazz.getName().equals("double") || clazz.equals(Double.class)) {
      if (nullOrEmpty) {
        return clazz.isPrimitive() ? 0d : null;
      }

      return Double.parseDouble(value);
    }

    // BigDecimal binding
    if (clazz.equals(BigDecimal.class)) {
      if (nullOrEmpty) {
        return null;
      }

      return new BigDecimal(value);
    }

    // boolean or Boolean binding
    if (clazz.getName().equals("boolean") || clazz.equals(Boolean.class)) {
      if (nullOrEmpty) {
        return clazz.isPrimitive() ? false : null;
      }

      if (value.equals("1")
          || value.toLowerCase().equals("on")
          || value.toLowerCase().equals("yes")) {
        return true;
      }

      return Boolean.parseBoolean(value);
    }

    return null;
  }
예제 #18
0
 // Get property value as a byte
 public byte getByte(String key) {
   return (properties.containsKey(key)) ? Byte.parseByte(properties.get(key).toString()) : 0;
 }