org.fudgemsg.taxon
Class MapFudgeTaxonomy

java.lang.Object
  extended by org.fudgemsg.taxon.MapFudgeTaxonomy
All Implemented Interfaces:
FudgeTaxonomy
Direct Known Subclasses:
PropertyFileTaxonomy

public class MapFudgeTaxonomy
extends Object
implements FudgeTaxonomy

An immutable taxonomy implementation based on a bidirectional map.

This is the standard implementation.


Field Summary
static FudgeTaxonomy EMPTY
          An empty taxonomy.
 
Constructor Summary
MapFudgeTaxonomy(int[] ordinals, String[] names)
          Creates a new taxonomy initialized by a list of ordinals and corresponding names.
MapFudgeTaxonomy(Map<Integer,String> ordinalToNameMap)
          Creates a new taxonomy initialized by the supplied map.
 
Method Summary
static FudgeTaxonomy fromFudgeMsg(FudgeFieldContainer msg)
          Decodes a taxonomy from a Fudge message as per the specification.
 String getFieldName(short ordinal)
          Looks up the field name for the given ordinal.
 Short getFieldOrdinal(String fieldName)
          Looks up the field ordinal for the given name.
 MutableFudgeFieldContainer toFudgeMsg(FudgeMessageFactory context)
          Encodes the taxonomy as a Fudge message as per the specification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final FudgeTaxonomy EMPTY
An empty taxonomy.

Constructor Detail

MapFudgeTaxonomy

public MapFudgeTaxonomy(Map<Integer,String> ordinalToNameMap)
Creates a new taxonomy initialized by the supplied map.

Parameters:
ordinalToNameMap - the map of ordinal to field names, not null, no nulls

MapFudgeTaxonomy

public MapFudgeTaxonomy(int[] ordinals,
                        String[] names)
Creates a new taxonomy initialized by a list of ordinals and corresponding names. The ordinal and name arrays must be the same length.

Parameters:
ordinals - the array of ordinal values, not null
names - the array of field names, not null, no nulls
Method Detail

getFieldName

public String getFieldName(short ordinal)
Description copied from interface: FudgeTaxonomy
Looks up the field name for the given ordinal.

Not all ordinals will necessarily be mapped to a name. This must be implemented to be bidirectional with FudgeTaxonomy.getFieldOrdinal(String).

Specified by:
getFieldName in interface FudgeTaxonomy
Parameters:
ordinal - the ordinal to lookup
Returns:
the field name, null if the ordinal is not mapped to a name

getFieldOrdinal

public Short getFieldOrdinal(String fieldName)
Description copied from interface: FudgeTaxonomy
Looks up the field ordinal for the given name.

Not all names will necessarily be mapped to an ordinal. This must be implemented to be bidirectional with FudgeTaxonomy.getFieldName(short).

Specified by:
getFieldOrdinal in interface FudgeTaxonomy
Parameters:
fieldName - the name to lookup, null returns null
Returns:
the field ordinal, null if the name is not mapped to a ordinal

toFudgeMsg

public MutableFudgeFieldContainer toFudgeMsg(FudgeMessageFactory context)
Encodes the taxonomy as a Fudge message as per the specification.

An encoded taxonomy can be decoded back to a taxonomy object by the MapFudgeTaxonomy.fromFudgeMsg method on this class or equivalent function in any other language implementation.

Parameters:
context - the message context, not null
Returns:
the created message, not null

fromFudgeMsg

public static FudgeTaxonomy fromFudgeMsg(FudgeFieldContainer msg)
Decodes a taxonomy from a Fudge message as per the specification.

that is backed by a MapFudgeTaxonomy object.

Parameters:
msg - the message to decode, not null
Returns:
the encoded taxonomy, not null


Copyright 2009-Present by OpenGamma Inc. and individual contributors
Released under the Apache License, Version 2.0