@ SuppressWarnings ( "unchecked" ) public < T > T getAttribute ( String attrName , Class < T > adaptee ) { if ( attrName == null ) { return null ; } if ( adaptee == null ) { adaptee = ( Class < T > ) String . class ; } Object attribute = feature . getAttribute ( attrName ) ; if ( attribute == null ) { return null ; } if ( attribute instanceof Number ) { Number num = ( Number ) attribute ; if ( adaptee . isAssignableFrom ( Double . class ) ) { return adaptee . cast ( num . doubleValue ( ) ) ; } else if ( adaptee . isAssignableFrom ( Float . class ) ) { return adaptee . cast ( num . floatValue ( ) ) ; } else if ( adaptee . isAssignableFrom ( Integer . class ) ) { return adaptee . cast ( num . intValue ( ) ) ; } else if ( adaptee . isAssignableFrom ( Long . class ) ) { return adaptee . cast ( num . longValue ( ) ) ; } else if ( adaptee . isAssignableFrom ( String . class ) ) { return adaptee . cast ( num . toString ( ) ) ; } else { throw new IllegalArgumentException ( ) ; } } else if ( attribute instanceof String ) { if ( adaptee . isAssignableFrom ( Double . class ) ) { try { Double parsed = Double . parseDouble ( ( String ) attribute ) ; return adaptee . cast ( parsed ) ; } catch ( Exception e ) { return null ; } } else if ( adaptee . isAssignableFrom ( Float . class ) ) { try { Float parsed = Float . parseFloat ( ( String ) attribute ) ; return adaptee . cast ( parsed ) ; } catch ( Exception e ) { return null ; } } else if ( adaptee . isAssignableFrom ( Integer . class ) ) { try { Integer parsed = Integer . parseInt ( ( String ) attribute ) ; return adaptee . cast ( parsed ) ; } catch ( Exception e ) { return null ; } } else if ( adaptee . isAssignableFrom ( String . class ) ) { return adaptee . cast ( attribute ) ; } else { throw new IllegalArgumentException ( ) ; } } else if ( attribute instanceof Geometry ) { return null ; } else { throw new IllegalArgumentException ( "Can't adapt attribute of type: " + attribute . getClass ( ) . getCanonicalName ( ) ) ; } }
Gets an attribute from the feature table adapting to the supplied class .