com.thoughtworks.xstream.converters.reflection
Class SortableFieldKeySorter

java.lang.Object
  extended by com.thoughtworks.xstream.converters.reflection.SortableFieldKeySorter
All Implemented Interfaces:
FieldKeySorter

public class SortableFieldKeySorter
extends java.lang.Object
implements FieldKeySorter

The default implementation for sorting fields. Invoke registerFieldOrder in order to set the field order for an specific type.

Since:
1.2.2
Author:
Guilherme Silveira

Constructor Summary
SortableFieldKeySorter()
           
 
Method Summary
 void registerFieldOrder(java.lang.Class type, java.lang.String[] fields)
          Registers the field order to use for a specific type.
 java.util.Map sort(java.lang.Class type, java.util.Map keyedByFieldKey)
          Sort the fields of a type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortableFieldKeySorter

public SortableFieldKeySorter()
Method Detail

sort

public java.util.Map sort(java.lang.Class type,
                          java.util.Map keyedByFieldKey)
Description copied from interface: FieldKeySorter
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.

Specified by:
sort in interface FieldKeySorter
Parameters:
type - the class that contains all the fields
keyedByFieldKey - a Map containing a FieldKey as key element and a Field as value.
Returns:
a Map with all the entries of the original Map

registerFieldOrder

public void registerFieldOrder(java.lang.Class type,
                               java.lang.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 an StreamException during the serialization process.

Parameters:
type - the type
fields - the field order


Copyright © 2004-2012 XStream. All Rights Reserved.