Java Type Coerce coerceTagValueInt(String tag, Object val)

Here you can find the source of coerceTagValueInt(String tag, Object val)

Description

coerce Tag Value Int

License

Open Source License

Declaration

private static Integer coerceTagValueInt(String tag, Object val) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static Integer coerceTagValueInt(String tag, Object val) {
        // from HTSJDK: https://github.com/samtools/htsjdk/blob/master/src/java/htsjdk/samtools/SAMRecord.java

        if (val == null)
            return null;
        if (val instanceof Integer) {
            return (Integer) val;
        }// w w  w. jav a2  s  .  c  o  m
        if (!(val instanceof Number)) {
            throw new RuntimeException("Value for tag " + tag
                    + " is not Number: " + val.getClass());
        }
        final long longVal = ((Number) val).longValue();
        if (longVal < Integer.MIN_VALUE || longVal > Integer.MAX_VALUE) {
            throw new RuntimeException("Value for tag " + tag
                    + " is not in Integer range: " + longVal);
        }
        return (int) longVal;

    }
}

Related

  1. coerce(Object value, Class clazz)
  2. coerceBool(Object obj)
  3. coerceBool(Object val)
  4. coerceIntoComboId(Long entityId)
  5. coerceIntoEntityId(Long comboId)
  6. coerceToDouble(Object o)
  7. coerceToEntrySize(String s)
  8. coerceToString(Object object)
  9. coerceToType(Object objectIn, Class clazz)