Top Description Inners Fields Constructors Methods
com.thoughtworks.xstream.converters.reflection

public Class SortableFieldKeySorter

extends Object
implements FieldKeySorter, Caching
Class Inheritance
All Implemented Interfaces
com.thoughtworks.xstream.core.Caching, com.thoughtworks.xstream.converters.reflection.FieldKeySorter
Imports
java.util.Arrays, .Comparator, .HashMap, .Map, com.thoughtworks.xstream.converters.ConversionException, com.thoughtworks.xstream.core.Caching, com.thoughtworks.xstream.core.util.OrderRetainingMap

The default implementation for sorting fields. Invoke registerFieldOrder in order to set the field order for an specific type.
Author
Guilherme Silveira
Since
1.2.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private static final FieldKey[]
private final Map<K, V>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
registerFieldOrder(final Class<T>
the type
type
,
final String[]
the field order
fields
)

Registers the field order to use for a specific type.

public Map<K, V>
sort(final Class<T>
the class that contains all the fields
type
,
final Map<K, V>
a Map containing a FieldKey as key element and a java.lang.reflect.Field as value.
keyedByFieldKey
)

Implements com.thoughtworks.xstream.converters.reflection.FieldKeySorter.sort.

Sort the fields of a type.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_FIELD_KEY_ARRAYback to summary
private static final FieldKey[] EMPTY_FIELD_KEY_ARRAY
mapback to summary
private final Map<K, V> map

Constructor Detail

SortableFieldKeySorterback to summary
public SortableFieldKeySorter()

Method Detail

flushCacheback to summary
public void flushCache()

Implements com.thoughtworks.xstream.core.Caching.flushCache.

registerFieldOrderback to summary
public void registerFieldOrder(final Class<T> type, final String[] fields)

Registers the field order to use for a specific type. This will not affect any of the type's super or sub classes. If you skip a field which will be serialized, XStream will thrown a ConversionException during the serialization process.

Parameters
type:Class<T>

the type

fields:String[]

the field order

sortback to summary
public Map<K, V> sort(final Class<T> type, final Map<K, V> keyedByFieldKey)

Implements com.thoughtworks.xstream.converters.reflection.FieldKeySorter.sort.

Doc from com.thoughtworks.xstream.converters.reflection.FieldKeySorter.sort.

Sort the fields of a type. The method will be called with the class type that contains all the fields and a Map that retains the order in which the elements have been added. The sequence in which elements are returned by an iterator defines the processing order of the fields. An implementation may create a different Map with similar semantic, add all elements of the original map and return the new one.

Parameters
type:Class<T>

the class that contains all the fields

keyedByFieldKey:Map<K, V>

a Map containing a FieldKey as key element and a java.lang.reflect.Field as value.

Returns:Map<K, V>

a Map with all the entries of the original Map

com.thoughtworks.xstream.converters.reflection back to summary

private Class SortableFieldKeySorter.FieldComparator

extends Object
implements Comparator
Class Inheritance
  • java.lang.Object
  • com.thoughtworks.xstream.converters.reflection.SortableFieldKeySorter.FieldComparator
All Implemented Interfaces
java.util.Comparator

Field Summary

Modifier and TypeField and Description
private final String[]
private final Class<T>

Constructor Summary

AccessConstructor and Description
public
FieldComparator(final Class<T> type, final String[] fields)

Method Summary

Modifier and TypeMethod and Description
public int
compare(final String
the first object to be compared.
first
,
final String
the second object to be compared.
second
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
public int
compare(final Object
the first object to be compared.
firstObject
,
final Object
the second object to be compared.
secondObject
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fieldOrderback to summary
private final String[] fieldOrder
typeback to summary
private final Class<T> type

Constructor Detail

FieldComparatorback to summary
public FieldComparator(final Class<T> type, final String[] fields)

Method Detail

compareback to summary
public int compare(final String first, final String second)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
first:String

the first object to be compared.

second:String

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(final Object firstObject, final Object secondObject)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
firstObject:Object

the first object to be compared.

secondObject:Object

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.