Changeset 14:0acba1296069 in rrlib_serialization-java


Ignore:
Timestamp:
22.04.2014 01:17:14 (6 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Added is*Serializable() functions to Serialization class (similar to type traits in C++ rrlib_serialization)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Serialization.java

    r9 r14  
    9393        TO_INT['f'] = 0xF; 
    9494        return 0; 
     95    } 
     96 
     97    /** 
     98     * @param type Type to check 
     99     * @return Returns whether provided type is serializable to binary streams 
     100     */ 
     101    public static boolean isBinarySerializable(Class<?> type) { 
     102        // This needs to be adapted if BinaryOutputStream.writeObect() is extended 
     103        return type != null && (BinarySerializable.class.isAssignableFrom(type) || type.isPrimitive() || type.isEnum() || type.equals(String.class)); 
     104    } 
     105 
     106    /** 
     107     * @param type Type to check 
     108     * @return Returns whether provided type is serializable to string streams 
     109     */ 
     110    public static boolean isStringSerializable(Class<?> type) { 
     111        // This needs to be adapted if StringOutputStream.appendObject() is extended 
     112        return type != null && (StringSerializable.class.isAssignableFrom(type) || type.isPrimitive() || Number.class.isAssignableFrom(type) 
     113                                || Boolean.class.equals(type) || type.isEnum() || type.equals(String.class)); 
     114    } 
     115 
     116    /** 
     117     * @param type Type to check 
     118     * @return Returns whether provided type is serializable to xml nodes 
     119     */ 
     120    public static boolean isXmlSerializable(Class<?> type) { 
     121        return type != null && (XMLSerializable.class.isAssignableFrom(type) || isStringSerializable(type)); 
    95122    } 
    96123 
Note: See TracChangeset for help on using the changeset viewer.