idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
400 | void writeString ( String value ) throws IOException { output . append ( '"' ) ; for ( int i = 0 ; i < value . length ( ) ; i ++ ) { char ch = value . charAt ( i ) ; if ( ch < 128 ) { String replace = REPLACE [ ch ] ; if ( replace != null ) { output . append ( replace ) ; } else { output . append ( ch ) ; } } else if ( ch == '\u2028' ) { output . append ( "\\u2028" ) ; } else if ( ch == '\u2029' ) { output . append ( "\\u2029" ) ; } else { output . append ( ch ) ; } } output . append ( '"' ) ; } | Writes a JSON string . |
401 | void writeArrayItemStart ( ) throws IOException { if ( commaState . get ( commaDepth ) ) { output . append ( ',' ) ; if ( newLine . length ( ) > 0 ) { output . append ( ' ' ) ; } } else { commaState . set ( commaDepth ) ; } } | Writes a JSON array item start . |
402 | void writeObjectStart ( ) throws IOException { output . append ( '{' ) ; currentIndent = currentIndent + indent ; commaDepth ++ ; commaState . set ( commaDepth , false ) ; } | Writes a JSON object start . |
403 | void writeObjectKeyValue ( String key , String value ) throws IOException { writeObjectKey ( key ) ; writeString ( value ) ; } | Writes a JSON object key and value . |
404 | void writeObjectEnd ( ) throws IOException { currentIndent = currentIndent . substring ( 0 , currentIndent . length ( ) - indent . length ( ) ) ; if ( commaState . get ( commaDepth ) ) { output . append ( newLine ) ; output . append ( currentIndent ) ; } output . append ( '}' ) ; commaDepth -- ; } | Writes a JSON object end . |
405 | public static Object wrapValue ( MetaProperty < ? > metaProp , Class < ? > beanType , Object value ) { Object [ ] helpers = OPTIONALS . get ( metaProp . propertyType ( ) ) ; if ( helpers != null ) { try { if ( value != null ) { value = ( ( Method ) helpers [ 0 ] ) . invoke ( null , value ) ; } else { value = helpers [ 1 ] ; } } catch ( Exception ex ) { throw new RuntimeException ( ex ) ; } } return value ; } | Wraps the value of a property if it is an optional . |
406 | public SerDeserializers register ( Class < ? > type , SerDeserializer deserializer ) { deserializers . put ( type , deserializer ) ; return this ; } | Adds the deserializer to be used for the specified type . |
407 | public Class < ? > decodeType ( String typeStr , JodaBeanSer settings , String basePackage , Map < String , Class < ? > > knownTypes , Class < ? > defaultType ) throws ClassNotFoundException { if ( lenient ) { return SerTypeMapper . decodeType ( typeStr , settings , basePackage , knownTypes , defaultType == Object . class ? String . class : defaultType ) ; } return SerTypeMapper . decodeType ( typeStr , settings , basePackage , knownTypes ) ; } | Decodes the type |
408 | private static void registerFromClasspath ( String beanName , String deserName , Map < Class < ? > , SerDeserializer > map ) throws Exception { Class < ? extends Bean > beanClass = Class . forName ( beanName ) . asSubclass ( Bean . class ) ; Class < ? > deserClass = Class . forName ( deserName ) ; Field field = null ; SerDeserializer deser ; try { field = deserClass . getDeclaredField ( "DESERIALIZER" ) ; if ( ! Modifier . isStatic ( field . getModifiers ( ) ) ) { throw new IllegalStateException ( "Field " + field + " must be static" ) ; } deser = SerDeserializer . class . cast ( field . get ( null ) ) ; } catch ( NoSuchFieldException ex ) { Constructor < ? > cons = null ; try { cons = deserClass . getConstructor ( ) ; deser = SerDeserializer . class . cast ( cons . newInstance ( ) ) ; } catch ( NoSuchMethodException ex2 ) { throw new IllegalStateException ( "Class " + deserClass . getName ( ) + " must have field DESERIALIZER or a no-arg constructor" ) ; } catch ( IllegalAccessException ex2 ) { cons . setAccessible ( true ) ; deser = SerDeserializer . class . cast ( cons . newInstance ( ) ) ; } } catch ( IllegalAccessException ex ) { field . setAccessible ( true ) ; deser = SerDeserializer . class . cast ( field . get ( null ) ) ; } map . put ( beanClass , deser ) ; } | parses and registers the classes |
409 | private static SerDeserializer toLenient ( SerDeserializer underlying ) { return new SerDeserializer ( ) { public MetaBean findMetaBean ( Class < ? > beanType ) { return underlying . findMetaBean ( beanType ) ; } public BeanBuilder < ? > createBuilder ( Class < ? > beanType , MetaBean metaBean ) { return underlying . createBuilder ( beanType , metaBean ) ; } public MetaProperty < ? > findMetaProperty ( Class < ? > beanType , MetaBean metaBean , String propertyName ) { try { return underlying . findMetaProperty ( beanType , metaBean , propertyName ) ; } catch ( NoSuchElementException ex ) { return null ; } } public void setValue ( BeanBuilder < ? > builder , MetaProperty < ? > metaProp , Object value ) { underlying . setValue ( builder , metaProp , value ) ; } public Object build ( Class < ? > beanType , BeanBuilder < ? > builder ) { return underlying . build ( beanType , builder ) ; } } ; } | makes the deserializer lenient |
410 | private Map < String , Object > dataWritable ( ) { if ( data == Collections . EMPTY_MAP ) { data = new LinkedHashMap < > ( ) ; } return data ; } | Gets the internal data map . |
411 | public Map < String , Object > toMap ( ) { if ( size ( ) == 0 ) { return Collections . emptyMap ( ) ; } return Collections . unmodifiableMap ( new LinkedHashMap < > ( data ) ) ; } | Returns a map representing the contents of the bean . |
412 | private T build ( Constructor < T > constructor , Object [ ] args ) { try { return constructor . newInstance ( args ) ; } catch ( IllegalArgumentException | IllegalAccessException | InstantiationException ex ) { throw new IllegalArgumentException ( "Bean cannot be created: " + beanName ( ) + " from " + Arrays . toString ( args ) , ex ) ; } catch ( InvocationTargetException ex ) { if ( ex . getCause ( ) instanceof RuntimeException ) { throw ( RuntimeException ) ex . getCause ( ) ; } throw new RuntimeException ( ex ) ; } } | Creates an instance of the bean . |
413 | private static String [ ] fieldNames ( Class < ? > beanType ) { Field [ ] fields = Stream . of ( beanType . getDeclaredFields ( ) ) . filter ( f -> ! Modifier . isStatic ( f . getModifiers ( ) ) && f . getAnnotation ( PropertyDefinition . class ) != null ) . toArray ( Field [ ] :: new ) ; List < String > fieldNames = new ArrayList < > ( ) ; for ( int i = 0 ; i < fields . length ; i ++ ) { fieldNames . add ( fields [ i ] . getName ( ) ) ; } return fieldNames . toArray ( new String [ fieldNames . size ( ) ] ) ; } | determine the field names by reflection |
414 | JsonEvent readEvent ( ) throws IOException { char next = readNext ( ) ; while ( next == ' ' || next == '\t' || next == '\n' || next == '\r' ) { next = readNext ( ) ; } switch ( next ) { case '{' : return JsonEvent . OBJECT ; case '}' : return JsonEvent . OBJECT_END ; case '[' : return JsonEvent . ARRAY ; case ']' : return JsonEvent . ARRAY_END ; case '"' : return JsonEvent . STRING ; case '-' : case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : return acceptNumber ( next ) ; case 'n' : return acceptNull ( ) ; case 't' : return acceptTrue ( ) ; case 'f' : return acceptFalse ( ) ; case ',' : return JsonEvent . COMMA ; case ':' : return JsonEvent . COLON ; default : throw new IllegalArgumentException ( "Invalid JSON data: Expected JSON character but found '" + next + "'" ) ; } } | Writes a JSON null . |
415 | String acceptObjectKey ( JsonEvent event ) throws IOException { ensureEvent ( event , JsonEvent . STRING ) ; return parseObjectKey ( ) ; } | expect object key and parse it |
416 | JsonEvent acceptObjectSeparator ( ) throws IOException { JsonEvent event = readEvent ( ) ; if ( event == JsonEvent . COMMA ) { return readEvent ( ) ; } else { return ensureEvent ( event , JsonEvent . OBJECT_END ) ; } } | accepts a comma or object end |
417 | JsonEvent acceptArraySeparator ( ) throws IOException { JsonEvent event = readEvent ( ) ; if ( event == JsonEvent . COMMA ) { return readEvent ( ) ; } else { return ensureEvent ( event , JsonEvent . ARRAY_END ) ; } } | accepts a comma or array end |
418 | public void ensureImport ( Class < ? > cls ) { if ( currentImports . contains ( cls . getName ( ) ) == false ) { newImports . add ( cls . getName ( ) ) ; } } | Ensures an import is present . |
419 | public String getEffectiveMetaScope ( ) { String scope = beanMetaScope ; if ( "smart" . equals ( scope ) ) { scope = typeScope ; } return "package" . equals ( scope ) ? "" : scope + " " ; } | Gets the effective scope to use in the meta . |
420 | public String getEffectiveBuilderScope ( ) { String scope = beanBuilderScope ; if ( "smart" . equals ( scope ) ) { scope = typeScope ; } return "package" . equals ( scope ) ? "" : scope + " " ; } | Gets the effective scope to use in the builder . |
421 | public boolean isConstructorScopeValid ( ) { return "smart" . equals ( constructorScope ) || "private" . equals ( constructorScope ) || "package" . equals ( constructorScope ) || "protected" . equals ( constructorScope ) || "public" . equals ( constructorScope ) || "public@ConstructorProperties" . equals ( constructorScope ) ; } | Is the constructor scope valid . |
422 | public String getEffectiveConstructorScope ( ) { if ( "smart" . equals ( constructorScope ) ) { return isTypeFinal ( ) ? "private " : "protected " ; } else if ( "package" . equals ( constructorScope ) ) { return "" ; } else if ( "public@ConstructorProperties" . equals ( constructorScope ) ) { return "public " ; } return constructorScope + " " ; } | Gets the effective scope to use in the constructor . |
423 | public void setTypeParts ( String [ ] parts ) { this . typeFinal = parts [ 0 ] != null ; this . typeScope = parts [ 1 ] ; this . typeFull = parts [ 2 ] ; this . typeRaw = parts [ 3 ] ; if ( parts [ 8 ] != null ) { this . typeGenericName = new String [ ] { parts [ 4 ] , parts [ 6 ] , parts [ 8 ] } ; this . typeGenericExtends = new String [ 3 ] ; this . typeGenericExtends [ 0 ] = parts [ 5 ] != null ? parts [ 5 ] : "" ; this . typeGenericExtends [ 1 ] = parts [ 7 ] != null ? parts [ 7 ] : "" ; this . typeGenericExtends [ 2 ] = parts [ 9 ] != null ? parts [ 9 ] : "" ; } else if ( parts [ 6 ] != null ) { this . typeGenericName = new String [ ] { parts [ 4 ] , parts [ 6 ] } ; this . typeGenericExtends = new String [ 2 ] ; this . typeGenericExtends [ 0 ] = parts [ 5 ] != null ? parts [ 5 ] : "" ; this . typeGenericExtends [ 1 ] = parts [ 7 ] != null ? parts [ 7 ] : "" ; } else if ( parts [ 4 ] != null ) { this . typeGenericName = new String [ ] { parts [ 4 ] } ; this . typeGenericExtends = new String [ 1 ] ; this . typeGenericExtends [ 0 ] = parts [ 5 ] != null ? parts [ 5 ] : "" ; } else { this . typeGenericName = new String [ 0 ] ; this . typeGenericExtends = new String [ 0 ] ; } } | Sets the bean type . |
424 | public void setSuperTypeParts ( String [ ] parts ) { if ( parts . length == 1 ) { this . root = true ; this . immutable = "ImmutableBean" . equals ( parts [ 0 ] ) ; this . superTypeFull = "" ; this . superTypeRaw = "" ; this . superTypeGeneric = "" ; } else { this . root = "DirectBean" . equals ( parts [ 0 ] ) ; this . immutable = false ; this . superTypeFull = parts [ 0 ] ; this . superTypeRaw = parts [ 1 ] ; if ( parts [ 4 ] != null ) { this . superTypeGeneric = parts [ 2 ] + ", " + parts [ 3 ] + ", " + parts [ 4 ] ; } else if ( parts [ 3 ] != null ) { this . superTypeGeneric = parts [ 2 ] + ", " + parts [ 3 ] ; } else if ( parts [ 2 ] != null ) { this . superTypeGeneric = parts [ 2 ] ; } else { this . superTypeGeneric = "" ; } } } | Sets the bean superclass type . |
425 | public boolean isTypeGenerifiedBy ( String type ) { if ( typeGenericName . length > 2 && typeGenericName [ 2 ] . equals ( type ) ) { return true ; } if ( typeGenericName . length > 1 && typeGenericName [ 1 ] . equals ( type ) ) { return true ; } if ( typeGenericName . length > 0 && typeGenericName [ 0 ] . equals ( type ) ) { return true ; } return false ; } | Checks if the type specified is one of the bean s type parameters . |
426 | public static < P > DirectMetaProperty < P > ofReadWrite ( MetaBean metaBean , String propertyName , Class < ? > declaringType , Class < P > propertyType ) { Field field = findField ( metaBean , propertyName ) ; return new DirectMetaProperty < > ( metaBean , propertyName , declaringType , propertyType , PropertyStyle . READ_WRITE , field ) ; } | Factory to create a read - write meta - property avoiding duplicate generics . |
427 | public static < P > DirectMetaProperty < P > ofReadOnly ( MetaBean metaBean , String propertyName , Class < ? > declaringType , Class < P > propertyType ) { Field field = findField ( metaBean , propertyName ) ; return new DirectMetaProperty < > ( metaBean , propertyName , declaringType , propertyType , PropertyStyle . READ_ONLY , field ) ; } | Factory to create a read - only meta - property avoiding duplicate generics . |
428 | public static < P > DirectMetaProperty < P > ofWriteOnly ( MetaBean metaBean , String propertyName , Class < ? > declaringType , Class < P > propertyType ) { Field field = findField ( metaBean , propertyName ) ; return new DirectMetaProperty < > ( metaBean , propertyName , declaringType , propertyType , PropertyStyle . WRITE_ONLY , field ) ; } | Factory to create a write - only meta - property avoiding duplicate generics . |
429 | public static < P > DirectMetaProperty < P > ofReadOnlyBuildable ( MetaBean metaBean , String propertyName , Class < ? > declaringType , Class < P > propertyType ) { Field field = findField ( metaBean , propertyName ) ; return new DirectMetaProperty < > ( metaBean , propertyName , declaringType , propertyType , PropertyStyle . READ_ONLY_BUILDABLE , field ) ; } | Factory to create a buildable read - only meta - property avoiding duplicate generics . |
430 | public static < P > DirectMetaProperty < P > ofDerived ( MetaBean metaBean , String propertyName , Class < ? > declaringType , Class < P > propertyType ) { Field field = findField ( metaBean , propertyName ) ; return new DirectMetaProperty < > ( metaBean , propertyName , declaringType , propertyType , PropertyStyle . DERIVED , field ) ; } | Factory to create a derived read - only meta - property avoiding duplicate generics . |
431 | public static < P > DirectMetaProperty < P > ofImmutable ( MetaBean metaBean , String propertyName , Class < ? > declaringType , Class < P > propertyType ) { Field field = findField ( metaBean , propertyName ) ; return new DirectMetaProperty < > ( metaBean , propertyName , declaringType , propertyType , PropertyStyle . IMMUTABLE , field ) ; } | Factory to create an imutable meta - property avoiding duplicate generics . |
432 | public String write ( Bean bean , boolean rootType ) { StringBuilder buf = new StringBuilder ( 1024 ) ; try { write ( bean , rootType , buf ) ; } catch ( IOException ex ) { throw new IllegalStateException ( ex ) ; } return buf . toString ( ) ; } | Writes the bean to a string specifying whether to include the type at the root . |
433 | void readAll ( ) { try { try { int b = input . read ( ) ; while ( b >= 0 ) { readObject ( b ) ; b = input . read ( ) ; } } finally { input . close ( ) ; } } catch ( IOException ex ) { throw new IllegalStateException ( ex ) ; } } | Reads all the data in the stream closing the stream . |
434 | public void resolveType ( ) { if ( getTypeStyle ( ) == null ) { setTypeStyle ( "" ) ; } final String fieldType = getFieldType ( ) ; String generics = "" ; if ( fieldType . contains ( "<" ) ) { generics = fieldType . substring ( fieldType . indexOf ( '<' ) ) ; } if ( getTypeStyle ( ) . equals ( "smart" ) ) { setType ( fieldType ) ; } else if ( getTypeStyle ( ) . length ( ) > 0 ) { if ( getTypeStyle ( ) . contains ( "<>" ) ) { setType ( getTypeStyle ( ) . replace ( "<>" , generics ) ) ; } else if ( getTypeStyle ( ) . contains ( "<" ) ) { setType ( getTypeStyle ( ) ) ; } else { setType ( getTypeStyle ( ) + generics ) ; } } else { setType ( fieldType ) ; } } | Resolves the field type . |
435 | public void resolveBuilderType ( ) { if ( getBuilderTypeStyle ( ) == null ) { setBuilderTypeStyle ( "" ) ; } final String fieldType = getFieldType ( ) ; String generics = "" ; if ( fieldType . contains ( "<" ) ) { generics = fieldType . substring ( fieldType . indexOf ( '<' ) ) ; } if ( getBuilderTypeStyle ( ) . equals ( "smart" ) ) { setBuilderType ( fieldType ) ; } else if ( getBuilderTypeStyle ( ) . length ( ) > 0 ) { if ( getBuilderTypeStyle ( ) . contains ( "<>" ) ) { setBuilderType ( getBuilderTypeStyle ( ) . replace ( "<>" , generics ) ) ; } else if ( getBuilderTypeStyle ( ) . contains ( "<" ) ) { setBuilderType ( getBuilderTypeStyle ( ) ) ; } else { setBuilderType ( getBuilderTypeStyle ( ) + generics ) ; } } else { setBuilderType ( fieldType ) ; } } | Resolves the field builder type . |
436 | public void resolveEqualsHashCodeStyle ( File file , int lineIndex ) { if ( equalsHashCodeStyle . equals ( "smart" ) ) { equalsHashCodeStyle = ( bean . isImmutable ( ) ? "field" : "getter" ) ; } if ( equalsHashCodeStyle . equals ( "omit" ) || equalsHashCodeStyle . equals ( "getter" ) || equalsHashCodeStyle . equals ( "field" ) ) { return ; } throw new BeanCodeGenException ( "Invalid equals/hashCode style: " + equalsHashCodeStyle + " in " + getBean ( ) . getTypeRaw ( ) + "." + getPropertyName ( ) , file , lineIndex ) ; } | Resolves the equals hashCode generator . |
437 | public void resolveToStringStyle ( File file , int lineIndex ) { if ( toStringStyle . equals ( "smart" ) ) { toStringStyle = ( bean . isImmutable ( ) ? "field" : "getter" ) ; } if ( toStringStyle . equals ( "omit" ) || toStringStyle . equals ( "getter" ) || toStringStyle . equals ( "field" ) ) { return ; } throw new BeanCodeGenException ( "Invalid toString style: " + toStringStyle + " in " + getBean ( ) . getTypeRaw ( ) + "." + getPropertyName ( ) , file , lineIndex ) ; } | Resolves the toString generator . |
438 | public String getFieldTypeRaw ( ) { int pos = fieldType . indexOf ( "<" ) ; return ( pos < 0 ? fieldType : fieldType . substring ( 0 , pos ) ) ; } | Gets the raw type of the property . |
439 | public void resolveSetterGen ( File file , int lineIndex ) { if ( getSetStyle ( ) == null ) { setSetStyle ( "" ) ; } String style = getSetStyle ( ) . replace ( "\\n" , "\n" ) ; String access = "public" ; if ( style . equals ( "private" ) ) { style = "smart" ; access = "private" ; } else if ( style . equals ( "package" ) ) { style = "smart" ; access = "package" ; } else if ( style . equals ( "protected" ) ) { style = "smart" ; access = "protected" ; } if ( style . equals ( "set" ) ) { setterGen = SetterGen . SetSetterGen . PUBLIC ; } else if ( style . equals ( "setClearAddAll" ) ) { setterGen = new SetterGen . PatternSetterGen ( "$field.clear();\n$field.addAll($value);" ) ; } else if ( style . equals ( "setClearPutAll" ) ) { setterGen = new SetterGen . PatternSetterGen ( "$field.clear();\n$field.putAll($value);" ) ; } else if ( style . equals ( "bound" ) ) { if ( isFinal ( ) ) { throw new IllegalArgumentException ( "Final field must not have a bound setter" ) ; } else { setterGen = SetterGen . ObservableSetterGen . PUBLIC ; bound = true ; } } else if ( style . equals ( "smart" ) ) { if ( isDerived ( ) ) { setterGen = SetterGen . NoSetterGen . INSTANCE ; } else if ( isFinal ( ) ) { if ( isCollectionType ( ) ) { setterGen = new SetterGen . PatternSetterGen ( "$field.clear();\n$field.addAll($value);" , access ) ; } else if ( isMapType ( ) ) { setterGen = new SetterGen . PatternSetterGen ( "$field.clear();\n$field.putAll($value);" , access ) ; } else { setterGen = SetterGen . NoSetterGen . INSTANCE ; } } else { setterGen = SetterGen . SetSetterGen . of ( access ) ; } } else if ( style . equals ( "" ) ) { setterGen = SetterGen . NoSetterGen . INSTANCE ; } else if ( style . equals ( "field" ) ) { setterGen = SetterGen . FieldSetterGen . INSTANCE ; } else if ( style . equals ( "manual" ) ) { setterGen = SetterGen . NoSetterGen . INSTANCE ; } else if ( style . contains ( "$field" ) || style . contains ( "$value" ) ) { if ( style . contains ( "$field" ) || style . contains ( "\n" ) ) { setterGen = new SetterGen . PatternSetterGen ( style ) ; } else { setterGen = new SetterGen . PatternSetterGen ( "$field = " + style ) ; } } else { throw new BeanCodeGenException ( "Unable to locate setter generator '" + style + "'" + " in " + getBean ( ) . getTypeRaw ( ) + "." + getPropertyName ( ) , file , lineIndex ) ; } } | Resolves the setter generator . |
440 | public PropertyStyle getStyle ( ) { if ( isDerived ( ) ) { return PropertyStyle . DERIVED ; } if ( getBean ( ) . isImmutable ( ) ) { return PropertyStyle . IMMUTABLE ; } if ( getGetStyle ( ) . length ( ) > 0 && getSetStyle ( ) . length ( ) > 0 && ( getSetterGen ( ) . isSetterGenerated ( this ) || getSetStyle ( ) . equals ( "manual" ) ) ) { return PropertyStyle . READ_WRITE ; } if ( getGetStyle ( ) . length ( ) > 0 ) { if ( bean . isBuilderScopeVisible ( ) ) { return PropertyStyle . READ_ONLY_BUILDABLE ; } else { return PropertyStyle . READ_ONLY ; } } if ( getSetStyle ( ) . length ( ) > 0 ) { return PropertyStyle . WRITE_ONLY ; } throw new RuntimeException ( "Property must have a getter or setter: " + getBean ( ) . getTypeRaw ( ) + "." + getPropertyName ( ) ) ; } | Gets the read - write flag . |
441 | public String getValidationMethodName ( ) { if ( isValidated ( ) == false ) { throw new IllegalStateException ( ) ; } if ( getValidation ( ) . equals ( "notNull" ) || getValidation ( ) . equals ( "notEmpty" ) || getValidation ( ) . equals ( "notBlank" ) ) { return "JodaBeanUtils." + getValidation ( ) ; } return getValidation ( ) ; } | Gets the validation method name . |
442 | public static boolean equal ( Object obj1 , Object obj2 ) { if ( obj1 == obj2 ) { return true ; } if ( obj1 == null || obj2 == null ) { return false ; } if ( obj1 . getClass ( ) . isArray ( ) ) { return equalsArray ( obj1 , obj2 ) ; } return obj1 . equals ( obj2 ) ; } | Checks if two objects are equal handling null . |
443 | @ SuppressWarnings ( "unchecked" ) public < P > P get ( MetaProperty < P > metaProperty ) { return ( P ) getBuffer ( ) . get ( metaProperty ) ; } | Gets the buffered value associated with the specified property name . |
444 | private static Class < ? > decodeType0 ( String className , JodaBeanSer settings , String basePackage , Map < String , Class < ? > > knownTypes , Class < ? > defaultType ) throws ClassNotFoundException { Class < ? > result = BASIC_TYPES_REVERSED . get ( className ) ; if ( result != null ) { return result ; } if ( knownTypes != null ) { result = knownTypes . get ( className ) ; if ( result != null ) { return result ; } } String fullName = className ; boolean expanded = false ; if ( basePackage != null && className . length ( ) > 0 && Character . isUpperCase ( className . charAt ( 0 ) ) ) { fullName = basePackage + className ; expanded = true ; } try { result = RenameHandler . INSTANCE . lookupType ( fullName ) ; if ( knownTypes != null ) { knownTypes . put ( fullName , result ) ; if ( expanded ) { knownTypes . put ( className , result ) ; } else { String simpleName = result . getSimpleName ( ) ; if ( fullName . equals ( result . getName ( ) ) == false && RenameHandler . INSTANCE . getTypeRenames ( ) . containsKey ( fullName ) && result . getEnclosingClass ( ) == null ) { simpleName = fullName . substring ( fullName . lastIndexOf ( "." ) + 1 ) ; } if ( Character . isUpperCase ( simpleName . charAt ( 0 ) ) && BASIC_TYPES_REVERSED . containsKey ( simpleName ) == false && knownTypes . containsKey ( simpleName ) == false ) { knownTypes . put ( simpleName , result ) ; } } } return result ; } catch ( ClassNotFoundException ex ) { if ( fullName . equals ( className ) == false ) { try { result = RenameHandler . INSTANCE . lookupType ( className ) ; if ( knownTypes != null ) { knownTypes . put ( className , result ) ; } return result ; } catch ( ClassNotFoundException ignored ) { } } if ( defaultType == null ) { throw ex ; } return defaultType ; } } | internal type decode |
445 | public Map < String , Object > write ( Bean bean ) { JodaBeanUtils . notNull ( bean , "bean" ) ; return writeBean ( bean , bean . getClass ( ) ) ; } | Writes the bean to a string . |
446 | void writeBoolean ( boolean value ) throws IOException { if ( value ) { output . writeByte ( TRUE ) ; } else { output . writeByte ( FALSE ) ; } } | Writes a MessagePack boolean . |
447 | void writeInt ( int value ) throws IOException { if ( value < MIN_FIX_INT ) { if ( value >= Byte . MIN_VALUE ) { output . writeByte ( SINT_8 ) ; output . writeByte ( ( byte ) value ) ; } else if ( value >= Short . MIN_VALUE ) { output . writeByte ( SINT_16 ) ; output . writeShort ( ( short ) value ) ; } else { output . writeByte ( SINT_32 ) ; output . writeInt ( value ) ; } } else if ( value < MAX_FIX_INT ) { output . writeByte ( value ) ; } else { if ( value < 0xFF ) { output . writeByte ( UINT_8 ) ; output . writeByte ( ( byte ) value ) ; } else if ( value < 0xFFFF ) { output . writeByte ( UINT_16 ) ; output . writeShort ( ( short ) value ) ; } else { output . writeByte ( UINT_32 ) ; output . writeInt ( value ) ; } } } | Writes a MessagePack int . |
448 | void writeLong ( long value ) throws IOException { if ( value < MIN_FIX_INT ) { if ( value >= Byte . MIN_VALUE ) { output . writeByte ( SINT_8 ) ; output . writeByte ( ( byte ) value ) ; } else if ( value >= Short . MIN_VALUE ) { output . writeByte ( SINT_16 ) ; output . writeShort ( ( short ) value ) ; } else if ( value >= Integer . MIN_VALUE ) { output . writeByte ( SINT_32 ) ; output . writeInt ( ( int ) value ) ; } else { output . writeByte ( SINT_64 ) ; output . writeLong ( value ) ; } } else if ( value < MAX_FIX_INT ) { output . writeByte ( ( byte ) value ) ; } else { if ( value < 0xFF ) { output . writeByte ( UINT_8 ) ; output . writeByte ( ( byte ) value ) ; } else if ( value < 0xFFFF ) { output . writeByte ( UINT_16 ) ; output . writeShort ( ( short ) value ) ; } else if ( value < 0xFFFFFFFFL ) { output . writeByte ( UINT_32 ) ; output . writeInt ( ( int ) value ) ; } else { output . writeByte ( UINT_64 ) ; output . writeLong ( value ) ; } } } | Writes a MessagePack long . |
449 | void writeBytes ( byte [ ] bytes ) throws IOException { int size = bytes . length ; if ( size < 256 ) { output . writeByte ( BIN_8 ) ; output . writeByte ( size ) ; } else if ( size < 65536 ) { output . writeByte ( BIN_16 ) ; output . writeShort ( size ) ; } else { output . writeByte ( BIN_32 ) ; output . writeInt ( size ) ; } output . write ( bytes ) ; } | Writes a MessagePack byte block . |
450 | void writeString ( String value ) throws IOException { byte [ ] bytes = toUTF8 ( value ) ; int size = bytes . length ; if ( size < 32 ) { output . writeByte ( MIN_FIX_STR + size ) ; } else if ( size < 256 ) { output . writeByte ( STR_8 ) ; output . writeByte ( size ) ; } else if ( size < 65536 ) { output . writeByte ( STR_16 ) ; output . writeShort ( size ) ; } else { output . writeByte ( STR_32 ) ; output . writeInt ( size ) ; } output . write ( bytes ) ; } | Writes a MessagePack string . |
451 | void writeArrayHeader ( int size ) throws IOException { if ( size < 16 ) { output . writeByte ( MIN_FIX_ARRAY + size ) ; } else if ( size < 65536 ) { output . writeByte ( ARRAY_16 ) ; output . writeShort ( size ) ; } else { output . writeByte ( ARRAY_32 ) ; output . writeInt ( size ) ; } } | Writes a MessagePack array header . |
452 | void writeMapHeader ( int size ) throws IOException { if ( size < 16 ) { output . writeByte ( MIN_FIX_MAP + size ) ; } else if ( size < 65536 ) { output . writeByte ( MAP_16 ) ; output . writeShort ( size ) ; } else { output . writeByte ( MAP_32 ) ; output . writeInt ( size ) ; } } | Writes a MessagePack map header . |
453 | void writeExtensionByte ( int extensionType , int value ) throws IOException { output . write ( FIX_EXT_1 ) ; output . write ( extensionType ) ; output . write ( value ) ; } | Writes an extension string using FIX_EXT_1 . |
454 | void writeExtensionString ( int extensionType , String str ) throws IOException { byte [ ] bytes = str . getBytes ( UTF_8 ) ; if ( bytes . length > 256 ) { throw new IllegalArgumentException ( "String too long" ) ; } output . write ( EXT_8 ) ; output . write ( bytes . length ) ; output . write ( extensionType ) ; output . write ( bytes ) ; } | Writes an extension string using EXT_8 . |
455 | void writePositiveExtensionInt ( int extensionType , int reference ) throws IOException { if ( reference < 0 ) { throw new IllegalArgumentException ( "Can only serialize positive references: " + reference ) ; } if ( reference < 0xFF ) { output . write ( FIX_EXT_1 ) ; output . write ( extensionType ) ; output . writeByte ( ( byte ) reference ) ; } else if ( reference < 0xFFFF ) { output . writeByte ( FIX_EXT_2 ) ; output . write ( extensionType ) ; output . writeShort ( ( short ) reference ) ; } else { output . writeByte ( FIX_EXT_4 ) ; output . write ( extensionType ) ; output . writeInt ( reference ) ; } } | Writes an extension reference of a positive integer using FIX_EXT data types . |
456 | private void parseClassDescriptions ( ) throws Exception { int refCount = acceptInteger ( input . readByte ( ) ) ; if ( refCount < 0 ) { throw new IllegalArgumentException ( "Invalid binary data: Expected count of references, but was: " + refCount ) ; } refs = new Object [ refCount ] ; int classMapSize = acceptMap ( input . readByte ( ) ) ; classes = new ClassInfo [ classMapSize ] ; classMap = new HashMap < > ( classMapSize ) ; for ( int position = 0 ; position < classMapSize ; position ++ ) { ClassInfo classInfo = parseClassInfo ( ) ; classes [ position ] = classInfo ; classMap . put ( classInfo . type , classInfo ) ; } } | parses the references |
457 | private ClassInfo parseClassInfo ( ) throws Exception { String className = acceptString ( input . readByte ( ) ) ; Class < ? > type = SerTypeMapper . decodeType ( className , settings , overrideBasePackage , null ) ; int propertyCount = acceptArray ( input . readByte ( ) ) ; if ( propertyCount < 0 ) { throw new IllegalArgumentException ( "Invalid binary data: Expected array with 0 to many elements, but was: " + propertyCount ) ; } MetaProperty < ? > [ ] metaProperties = new MetaProperty < ? > [ propertyCount ] ; if ( ImmutableBean . class . isAssignableFrom ( type ) ) { SerDeserializer deser = settings . getDeserializers ( ) . findDeserializer ( type ) ; MetaBean metaBean = deser . findMetaBean ( type ) ; for ( int i = 0 ; i < propertyCount ; i ++ ) { String propertyName = acceptString ( input . readByte ( ) ) ; metaProperties [ i ] = deser . findMetaProperty ( type , metaBean , propertyName ) ; } } else if ( propertyCount != 0 ) { throw new IllegalArgumentException ( "Invalid binary data: Found non immutable bean class that has meta properties defined: " + type . getName ( ) + ", " + propertyCount + " properties" ) ; } return new ClassInfo ( type , metaProperties ) ; } | parses the class information |
458 | private Object parseBean ( int propertyCount , ClassInfo classInfo ) { String propName = "" ; if ( classInfo . metaProperties . length != propertyCount ) { throw new IllegalArgumentException ( "Invalid binary data: Expected " + classInfo . metaProperties . length + " properties but was: " + propertyCount ) ; } try { SerDeserializer deser = settings . getDeserializers ( ) . findDeserializer ( classInfo . type ) ; MetaBean metaBean = deser . findMetaBean ( classInfo . type ) ; BeanBuilder < ? > builder = deser . createBuilder ( classInfo . type , metaBean ) ; for ( MetaProperty < ? > metaProp : classInfo . metaProperties ) { if ( metaProp == null ) { MsgPackInput . skipObject ( input ) ; } else { propName = metaProp . name ( ) ; Object value = parseObject ( SerOptional . extractType ( metaProp , classInfo . type ) , metaProp , classInfo . type , null , false ) ; deser . setValue ( builder , metaProp , SerOptional . wrapValue ( metaProp , classInfo . type , value ) ) ; } propName = "" ; } return deser . build ( classInfo . type , builder ) ; } catch ( Exception ex ) { throw new RuntimeException ( "Error parsing bean: " + classInfo . type . getName ( ) + "::" + propName + ", " + ex . getMessage ( ) , ex ) ; } } | parses the bean using the class information |
459 | Class < ? > getAndSerializeEffectiveTypeIfRequired ( Object value , Class < ? > declaredType ) throws IOException { Class < ? > realType = value . getClass ( ) ; Class < ? > effectiveType = declaredType ; if ( declaredType == Object . class ) { if ( realType != String . class ) { effectiveType = settings . getConverter ( ) . findTypedConverter ( realType ) . getEffectiveType ( ) ; output . writeMapHeader ( 1 ) ; String type = SerTypeMapper . encodeType ( effectiveType , settings , basePackage , knownTypes ) ; output . writeExtensionString ( MsgPack . JODA_TYPE_DATA , type ) ; } else { effectiveType = realType ; } } else if ( settings . getConverter ( ) . isConvertible ( declaredType ) == false ) { effectiveType = settings . getConverter ( ) . findTypedConverter ( realType ) . getEffectiveType ( ) ; output . writeMapHeader ( 1 ) ; String type = SerTypeMapper . encodeType ( effectiveType , settings , basePackage , knownTypes ) ; output . writeExtensionString ( MsgPack . JODA_TYPE_DATA , type ) ; } return effectiveType ; } | needs to handle no declared type and subclass instances |
460 | void writeObjectAsString ( Object value , Class < ? > effectiveType ) throws IOException { String converted = settings . getConverter ( ) . convertToString ( effectiveType , value ) ; if ( converted == null ) { throw new IllegalArgumentException ( "Unable to write because converter returned a null string: " + value ) ; } output . writeString ( converted ) ; } | called after discerning that the value is not a simple type |
461 | private static MetaBean metaBeanLookup ( Class < ? > cls ) { if ( cls == FlexiBean . class ) { return new FlexiBean ( ) . metaBean ( ) ; } else if ( cls == MapBean . class ) { return new MapBean ( ) . metaBean ( ) ; } else if ( DynamicBean . class . isAssignableFrom ( cls ) ) { try { return cls . asSubclass ( DynamicBean . class ) . getDeclaredConstructor ( ) . newInstance ( ) . metaBean ( ) ; } catch ( NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ex ) { throw new IllegalArgumentException ( "Unable to find meta-bean for a DynamicBean: " + cls . getName ( ) , ex ) ; } } try { cls = Class . forName ( cls . getName ( ) , true , cls . getClassLoader ( ) ) ; } catch ( ClassNotFoundException | Error ex ) { throw new IllegalArgumentException ( "Unable to find meta-bean: " + cls . getName ( ) , ex ) ; } MetaBean meta = META_BEANS . get ( cls ) ; if ( meta == null ) { throw new IllegalArgumentException ( "Unable to find meta-bean: " + cls . getName ( ) ) ; } return meta ; } | lookup the MetaBean outside the fast path aiding hotspot inlining |
462 | private static List < File > findFiles ( final File parent , boolean recurse ) { final List < File > result = new ArrayList < > ( ) ; if ( parent . isDirectory ( ) ) { File [ ] files = parent . listFiles ( ) ; files = ( files != null ? files : new File [ 0 ] ) ; for ( File child : files ) { if ( child . isFile ( ) && child . getName ( ) . endsWith ( ".java" ) ) { result . add ( child ) ; } } if ( recurse ) { for ( File child : files ) { if ( child . isDirectory ( ) && child . getName ( ) . startsWith ( "." ) == false ) { result . addAll ( findFiles ( child , recurse ) ) ; } } } } else { if ( parent . getName ( ) . endsWith ( ".java" ) ) { result . add ( parent ) ; } } return result ; } | Finds the set of files to process . |
463 | private File processFile ( File file ) throws Exception { List < String > original = readFile ( file ) ; List < String > content = new ArrayList < > ( original ) ; BeanGen gen ; try { BeanParser parser = new BeanParser ( file , content , config ) ; gen = parser . parse ( ) ; } catch ( BeanCodeGenException ex ) { throw ex ; } catch ( Exception ex ) { throw new BeanCodeGenException ( ex . getMessage ( ) , ex , file ) ; } if ( gen . isBean ( ) ) { if ( verbosity >= 2 ) { System . out . print ( file + " [processing]" ) ; } gen . process ( ) ; if ( content . equals ( original ) == false ) { if ( write ) { if ( verbosity >= 2 ) { System . out . println ( " [writing]" ) ; } else if ( verbosity == 1 ) { System . out . println ( file + " [writing]" ) ; } writeFile ( file , content ) ; } else { if ( verbosity >= 2 ) { System . out . println ( " [changed not written]" ) ; } else if ( verbosity == 1 ) { System . out . println ( file + " [changed not written]" ) ; } } return file ; } else { if ( verbosity >= 2 ) { System . out . println ( " [no change]" ) ; } } } else { gen . processNonBean ( ) ; if ( ! content . equals ( original ) ) { if ( write ) { if ( verbosity >= 2 ) { System . out . println ( " [writing]" ) ; } else if ( verbosity == 1 ) { System . out . println ( file + " [writing]" ) ; } writeFile ( file , content ) ; } else { if ( verbosity >= 2 ) { System . out . println ( " [changed not written]" ) ; } else if ( verbosity == 1 ) { System . out . println ( file + " [changed not written]" ) ; } } return file ; } else { if ( verbosity == 3 ) { System . out . println ( file + " [ignored]" ) ; } } } return null ; } | Processes the bean generating the code . |
464 | private void writeClassDescriptions ( BeanReferences references ) throws IOException { output . writeInt ( references . getReferences ( ) . size ( ) ) ; List < ClassInfo > classInfos = references . getClassInfoList ( ) ; output . writeMapHeader ( classInfos . size ( ) ) ; for ( ClassInfo classInfo : classInfos ) { String className = SerTypeMapper . encodeType ( classInfo . type , settings , null , null ) ; output . writeString ( className ) ; output . writeArrayHeader ( classInfo . metaProperties . length ) ; for ( MetaProperty < ? > property : classInfo . metaProperties ) { output . writeString ( property . name ( ) ) ; } } } | determines what beans occur more than once and setup references |
465 | public static < R > StandaloneMetaProperty < R > of ( String propertyName , MetaBean metaBean , Class < R > clazz ) { return new StandaloneMetaProperty < > ( propertyName , metaBean , clazz , clazz ) ; } | Creates a non - generified property . |
466 | public byte [ ] write ( Bean bean , boolean rootType ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( 1024 ) ; try { write ( bean , rootType , baos ) ; } catch ( IOException ex ) { throw new IllegalStateException ( ex ) ; } return baos . toByteArray ( ) ; } | Writes the bean to an array of bytes . |
467 | protected void propertySet ( Bean bean , String propertyName , Object value , boolean quiet ) { if ( quiet ) { return ; } throw new NoSuchElementException ( "Unknown property: " + propertyName ) ; } | Sets the value of the property . |
468 | private void findChildBeans ( Object obj , MetaProperty < ? > mp , Class < ? > beanClass , Deque < Bean > temp ) { if ( obj != null ) { if ( obj instanceof Bean ) { temp . addFirst ( ( Bean ) obj ) ; } else { SerIterator it = SerIteratorFactory . INSTANCE . create ( obj , mp , beanClass ) ; if ( it != null ) { while ( it . hasNext ( ) ) { it . next ( ) ; findChildBeans ( it . key ( ) , mp , Object . class , temp ) ; findChildBeans ( it . value ( ) , mp , Object . class , temp ) ; findChildBeans ( it . column ( ) , mp , Object . class , temp ) ; } } } } } | find child beans including those in collections |
469 | private void findReferences ( ImmutableBean root ) { classes . put ( root . getClass ( ) , classInfoFromMetaBean ( root . metaBean ( ) , root . getClass ( ) ) ) ; classSerializationCount . put ( root . getClass ( ) , 1 ) ; Map < Object , Integer > objects = new LinkedHashMap < > ( ) ; findReferencesBean ( root , root . getClass ( ) , objects , null ) ; List < Map . Entry < Object , Integer > > refEntries = objects . entrySet ( ) . stream ( ) . sorted ( reverseOrder ( comparingInt ( Map . Entry :: getValue ) ) ) . filter ( entry -> entry . getValue ( ) > 1 ) . collect ( toList ( ) ) ; for ( Map . Entry < Object , Integer > entry : refEntries ) { Object value = entry . getKey ( ) ; Class < ? > realType = value . getClass ( ) ; if ( realType != Integer . class && realType != Double . class && realType != Float . class && realType != Boolean . class && realType != Long . class && realType != Short . class && realType != Byte . class && realType != byte [ ] . class ) { refs . put ( value , new Ref ( false , refs . size ( ) ) ) ; } } this . classInfoList . addAll ( classSerializationCount . entrySet ( ) . stream ( ) . sorted ( reverseOrder ( comparingInt ( Map . Entry :: getValue ) ) ) . map ( entry -> classes . get ( entry . getKey ( ) ) ) . collect ( toList ( ) ) ) ; for ( int position = 0 ; position < classInfoList . size ( ) ; position ++ ) { ClassInfo classInfo = classInfoList . get ( position ) ; classInfo . position = position ; } } | finds classes and references within the bean |
470 | private void findReferencesBean ( Object base , Class < ? > declaredClass , Map < Object , Integer > objects , SerIterator parentIterator ) { if ( base == null ) { return ; } int result = objects . compute ( base , BeanReferences :: incrementOrOne ) ; if ( result > 1 ) { return ; } if ( base instanceof Bean ) { addClassInfo ( base , declaredClass ) ; Bean bean = ( Bean ) base ; if ( settings . getConverter ( ) . isConvertible ( bean . getClass ( ) ) ) { return ; } for ( MetaProperty < ? > prop : bean . metaBean ( ) . metaPropertyIterable ( ) ) { if ( settings . isSerialized ( prop ) ) { Object value = prop . get ( bean ) ; Class < ? > type = SerOptional . extractType ( prop , base . getClass ( ) ) ; if ( value != null ) { SerIterator itemIterator = settings . getIteratorFactory ( ) . create ( value , prop , bean . getClass ( ) ) ; if ( itemIterator != null ) { if ( itemIterator . metaTypeRequired ( ) ) { objects . compute ( itemIterator . metaTypeName ( ) , BeanReferences :: incrementOrOne ) ; } findReferencesIterable ( itemIterator , objects ) ; } else { findReferencesBean ( value , type , objects , null ) ; } } else { addClassInfo ( type , type ) ; } } } } else if ( parentIterator != null ) { SerIterator childIterator = settings . getIteratorFactory ( ) . createChild ( base , parentIterator ) ; if ( childIterator != null ) { findReferencesIterable ( childIterator , objects ) ; } else { addClassInfo ( base , declaredClass ) ; } } else { addClassInfo ( base , declaredClass ) ; } } | recursively find the references |
471 | private void findReferencesIterable ( SerIterator itemIterator , Map < Object , Integer > objects ) { if ( itemIterator . category ( ) == SerCategory . MAP ) { while ( itemIterator . hasNext ( ) ) { itemIterator . next ( ) ; findReferencesBean ( itemIterator . key ( ) , itemIterator . keyType ( ) , objects , null ) ; findReferencesBean ( itemIterator . value ( ) , itemIterator . valueType ( ) , objects , itemIterator ) ; } } else if ( itemIterator . category ( ) == SerCategory . COUNTED ) { while ( itemIterator . hasNext ( ) ) { itemIterator . next ( ) ; findReferencesBean ( itemIterator . value ( ) , itemIterator . valueType ( ) , objects , itemIterator ) ; } } else if ( itemIterator . category ( ) == SerCategory . TABLE ) { while ( itemIterator . hasNext ( ) ) { itemIterator . next ( ) ; findReferencesBean ( itemIterator . key ( ) , itemIterator . keyType ( ) , objects , null ) ; findReferencesBean ( itemIterator . column ( ) , itemIterator . columnType ( ) , objects , null ) ; findReferencesBean ( itemIterator . value ( ) , itemIterator . valueType ( ) , objects , itemIterator ) ; } } else if ( itemIterator . category ( ) == SerCategory . GRID ) { while ( itemIterator . hasNext ( ) ) { itemIterator . next ( ) ; findReferencesBean ( itemIterator . value ( ) , itemIterator . valueType ( ) , objects , itemIterator ) ; } } else { while ( itemIterator . hasNext ( ) ) { itemIterator . next ( ) ; findReferencesBean ( itemIterator . value ( ) , itemIterator . valueType ( ) , objects , itemIterator ) ; } } } | recursively find the references in an iterable |
472 | private void addClassInfoAndIncrementCount ( Class < ? > type , ClassInfo classInfo ) { classes . putIfAbsent ( type , classInfo ) ; classSerializationCount . compute ( type , BeanReferences :: incrementOrOne ) ; } | adds the class incrementing the number of times it is used |
473 | private ClassInfo classInfoFromMetaBean ( MetaBean metaBean , Class < ? > aClass ) { MetaProperty < ? > [ ] metaProperties = StreamSupport . stream ( metaBean . metaPropertyIterable ( ) . spliterator ( ) , false ) . filter ( metaProp -> settings . isSerialized ( metaProp ) ) . toArray ( MetaProperty < ? > [ ] :: new ) ; return new ClassInfo ( aClass , metaProperties ) ; } | converts a meta - bean to a ClassInfo |
474 | ClassInfo getClassInfo ( Class < ? > effectiveType ) { ClassInfo classInfo = classes . get ( effectiveType ) ; if ( classInfo == null ) { throw new IllegalStateException ( "Tried to serialise class that wasn't present in bean on first pass: " + effectiveType . getName ( ) ) ; } return classInfo ; } | lookup the class info by type |
475 | private void writeObject ( Class < ? > declaredType , Object obj , SerIterator parentIterator ) throws IOException { if ( obj == null ) { output . writeNull ( ) ; } else if ( settings . getConverter ( ) . isConvertible ( obj . getClass ( ) ) ) { writeSimple ( declaredType , obj ) ; } else if ( obj instanceof Bean ) { writeBean ( ( Bean ) obj , declaredType ) ; } else if ( parentIterator != null ) { SerIterator childIterator = settings . getIteratorFactory ( ) . createChild ( obj , parentIterator ) ; if ( childIterator != null ) { writeElements ( childIterator ) ; } else { writeSimple ( declaredType , obj ) ; } } else { writeSimple ( declaredType , obj ) ; } } | write collection object |
476 | private < T > T parseVersion ( DataInputStream input , Class < T > declaredType ) throws Exception { int arrayByte = input . readByte ( ) ; int versionByte = input . readByte ( ) ; switch ( versionByte ) { case 1 : if ( arrayByte != MIN_FIX_ARRAY + 2 ) { throw new IllegalArgumentException ( "Invalid binary data: Expected array with 2 elements, but was: 0x" + toHex ( arrayByte ) ) ; } return new JodaBeanStandardBinReader ( settings , input ) . read ( declaredType ) ; case 2 : if ( arrayByte != MIN_FIX_ARRAY + 4 ) { throw new IllegalArgumentException ( "Invalid binary data: Expected array with 4 elements, but was: 0x" + toHex ( arrayByte ) ) ; } return new JodaBeanReferencingBinReader ( settings , input ) . read ( declaredType ) ; default : throw new IllegalArgumentException ( "Invalid binary data: Expected version 1 or 2, but was: 0x" + toHex ( versionByte ) ) ; } } | parses the version |
477 | public static CacheFrame [ ] get ( Throwable throwable ) { if ( throwable == null ) { return null ; } Map < Throwable , CacheFrame [ ] > weakMap = cache . get ( ) ; return weakMap . get ( throwable ) ; } | Get the cached frames associated with the given throwable . |
478 | public void setPersonData ( final String id , final String username , final String email ) { this . rollbar . configure ( new ConfigProvider ( ) { public Config provide ( ConfigBuilder builder ) { return builder . person ( new PersonProvider ( id , username , email ) ) . build ( ) ; } } ) ; } | Set the person data to include with future items . |
479 | public void clearPersonData ( ) { this . rollbar . configure ( new ConfigProvider ( ) { public Config provide ( ConfigBuilder builder ) { return builder . person ( null ) . build ( ) ; } } ) ; } | Remove any person data that might be set . |
480 | public void setIncludeLogcat ( final boolean includeLogcat ) { final int versionCode = this . versionCode ; final String versionName = this . versionName ; this . rollbar . configure ( new ConfigProvider ( ) { public Config provide ( ConfigBuilder builder ) { ClientProvider clientProvider = new ClientProvider . Builder ( ) . versionCode ( versionCode ) . versionName ( versionName ) . includeLogcat ( includeLogcat ) . build ( ) ; return builder . client ( clientProvider ) . build ( ) ; } } ) ; } | Toggle whether to include logcat output in items . |
481 | public void critical ( Throwable error , Map < String , Object > custom ) { critical ( error , custom , null ) ; } | Record a critical error with extra information attached . |
482 | public void critical ( Throwable error , Map < String , Object > custom , String description ) { log ( error , custom , description , Level . CRITICAL ) ; } | Record a critical error with custom parameters and human readable description . |
483 | public void warning ( Throwable error , Map < String , Object > custom ) { warning ( error , custom , null ) ; } | Record a warning error with extra information attached . |
484 | public void warning ( Throwable error , Map < String , Object > custom , String description ) { log ( error , custom , description , Level . WARNING ) ; } | Record a warning error with custom parameters and human readable description . |
485 | public void info ( Throwable error , Map < String , Object > custom ) { info ( error , custom , null ) ; } | Record an info error with extra information attached . |
486 | public void info ( Throwable error , Map < String , Object > custom , String description ) { log ( error , custom , description , Level . INFO ) ; } | Record an info error with custom parameters and human readable description . |
487 | public void debug ( Throwable error , Map < String , Object > custom ) { debug ( error , custom , null ) ; } | Record a debug error with extra information attached . |
488 | public void debug ( Throwable error , Map < String , Object > custom , String description ) { log ( error , custom , description , Level . DEBUG ) ; } | Record a debug error with custom parameters and human readable description . |
489 | public void log ( Throwable error , Level level ) { log ( error , null , null , level ) ; } | Log an error at level specified . |
490 | public void log ( Throwable error , String description , Level level ) { log ( error , null , description , level ) ; } | Record a debug error with human readable description at the specified level . |
491 | public void log ( String message , Level level ) { log ( null , null , message , level ) ; } | Record a message at the level specified . |
492 | public void log ( String message , Map < String , Object > custom , Level level ) { log ( null , custom , message , level ) ; } | Record a message with extra information attached at the specified level . |
493 | public static void reportException ( final Throwable throwable , final String level ) { reportException ( throwable , level , null , null ) ; } | report an exception to Rollbar specifying the level . |
494 | public static void reportException ( final Throwable throwable , final String level , final String description , final Map < String , String > params ) { ensureInit ( new Runnable ( ) { public void run ( ) { notifier . log ( throwable , params != null ? Collections . < String , Object > unmodifiableMap ( params ) : null , description , Level . lookupByName ( level ) ) ; } } ) ; } | report an exception to Rollbar specifying the level adding a custom description and including extra data . |
495 | public static void reportMessage ( final String message , final String level ) { reportMessage ( message , level , null ) ; } | Report a message to Rollbar specifying the level . |
496 | public static void reportMessage ( final String message , final String level , final Map < String , String > params ) { ensureInit ( new Runnable ( ) { public void run ( ) { notifier . log ( message , params != null ? Collections . < String , Object > unmodifiableMap ( params ) : null , Level . lookupByName ( level ) ) ; } } ) ; } | Report a message to Rollbar specifying the level and including extra data . |
497 | public String greeting ( ) { int current = counter . getAndAdd ( 1 ) ; if ( current % 2 != 0 ) { return format ( "Hello Rollbar number %d" , current ) ; } throw new RuntimeException ( "Fatal error at greeting number: " + current ) ; } | Get the greeting message . |
498 | public static ConfigProvider getConfigProvider ( String configProviderClassName ) { ConfigProvider configProvider = null ; if ( configProviderClassName != null && ! "" . equals ( configProviderClassName ) ) { Class userConfigProviderClass = null ; try { userConfigProviderClass = Class . forName ( configProviderClassName ) ; } catch ( Exception e ) { thisLogger . error ( "Could not get the config provider class: {}." , configProviderClassName , e . getMessage ( ) ) ; } if ( userConfigProviderClass != null ) { try { Constructor < ConfigProvider > constructor = userConfigProviderClass . getConstructor ( ) ; configProvider = constructor . newInstance ( ) ; } catch ( Exception e ) { thisLogger . error ( "Could not create the config provider." , e ) ; } } } return configProvider ; } | Instantiate a ConfigProvider object based on the class name given as parameter . |
499 | public void critical ( Throwable error , String description ) { log ( error , null , description , Level . CRITICAL ) ; } | Record a critical error with human readable description . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.