net.kano.joscar.tlv
Class DefaultMutableTlvChain

java.lang.Object
  extended byAbstractTlvChain
      extended byDefaultMutableTlvChain
All Implemented Interfaces:
LiveWritable, MutableTlvChain, TlvChain, Writable

public class DefaultMutableTlvChain
extends AbstractTlvChain
implements MutableTlvChain

A default implementation of a (thread-safe) mutable TLV chain.


Constructor Summary
protected DefaultMutableTlvChain()
          Creates an empty TLV chain.
protected DefaultMutableTlvChain(TlvChain other)
          Creates a TLV chain containing the same TLV's as the given chain.
 
Method Summary
 void addAll(TlvChain other)
          Adds all TLV's in the given chain to the end of this chain (preserving order).
 void addTlv(Tlv tlv)
          Adds the given TLV to this chain.
protected  java.util.List getTlvList()
          Returns a list of all of the TLV's in this chain.
protected  java.util.Map getTlvMap()
          Returns a map from TLV types (as Integers) to TLV lists (as Lists).
 void removeTlv(Tlv tlv)
          Removes the given TLV from the chain, if it is present.
 void removeTlvs(int type)
          Removes all TLV's in this chain of the given TLV type.
 void removeTlvs(int[] types)
          Removes all TLV's in this chain having any of the given types.
 void replaceAll(TlvChain other)
          Deletes all TLV's currently in this chain having the same type as any of the TLV's in the other chain, and replaces them with their counterparts in the given chain.
 void replaceTlv(Tlv tlv)
          Removes all TLV's of the given type from the chain, and inserts the given TLV at the index of the first TLV removed, or at the end of the chain if no TLV's of the same type were found.
 
Methods inherited from class AbstractTlvChain
addTlvImpl, copy, createSiblingList, getFirstTlv, getLastTlv, getString, getString, getTlvCount, getTlvs, getTlvs, getTotalSize, getUInt, getUShort, getWritableLength, hasTlv, initFromBlock, iterator, toString, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface TlvChain
getFirstTlv, getLastTlv, getString, getString, getTlvCount, getTlvs, getTlvs, getTotalSize, getUInt, getUShort, hasTlv, iterator
 
Methods inherited from interface net.kano.joscar.Writable
getWritableLength, write
 

Constructor Detail

DefaultMutableTlvChain

protected DefaultMutableTlvChain()
Creates an empty TLV chain.


DefaultMutableTlvChain

protected DefaultMutableTlvChain(TlvChain other)
Creates a TLV chain containing the same TLV's as the given chain.

Parameters:
other - a TLV chain to copy
See Also:
addAll(net.kano.joscar.tlv.TlvChain)
Method Detail

addTlv

public final void addTlv(Tlv tlv)
Description copied from interface: MutableTlvChain
Adds the given TLV to this chain.

Specified by:
addTlv in interface MutableTlvChain
Parameters:
tlv - the TLV to add

replaceTlv

public final void replaceTlv(Tlv tlv)
Description copied from interface: MutableTlvChain
Removes all TLV's of the given type from the chain, and inserts the given TLV at the index of the first TLV removed, or at the end of the chain if no TLV's of the same type were found.

Specified by:
replaceTlv in interface MutableTlvChain
Parameters:
tlv - the TLV to replace its "siblings" of the same TLV type

removeTlv

public final void removeTlv(Tlv tlv)
Description copied from interface: MutableTlvChain
Removes the given TLV from the chain, if it is present.

Specified by:
removeTlv in interface MutableTlvChain
Parameters:
tlv - the TLV to remove

removeTlvs

public final void removeTlvs(int type)
Description copied from interface: MutableTlvChain
Removes all TLV's in this chain of the given TLV type.

Specified by:
removeTlvs in interface MutableTlvChain
Parameters:
type - the type of TLV of which to remove all instances

removeTlvs

public final void removeTlvs(int[] types)
Description copied from interface: MutableTlvChain
Removes all TLV's in this chain having any of the given types.

Specified by:
removeTlvs in interface MutableTlvChain
Parameters:
types - the TLV types of which to remove all instances

addAll

public final void addAll(TlvChain other)
Description copied from interface: MutableTlvChain
Adds all TLV's in the given chain to the end of this chain (preserving order).

Specified by:
addAll in interface MutableTlvChain
Parameters:
other - the chain whose TLV's will be appended to this chain

replaceAll

public final void replaceAll(TlvChain other)
Description copied from interface: MutableTlvChain
Deletes all TLV's currently in this chain having the same type as any of the TLV's in the other chain, and replaces them with their counterparts in the given chain. Behavior is undefined if the given chain contains two or more TLV's of the same type. Any TLV's in the given chain without counterparts in this chain will be appended to the end of this chain.

Specified by:
replaceAll in interface MutableTlvChain
Parameters:
other - the TLV whose TLV's will replace and/or add to TLV's in this chain

getTlvList

protected java.util.List getTlvList()
Description copied from class: AbstractTlvChain
Returns a list of all of the TLV's in this chain.

Specified by:
getTlvList in class AbstractTlvChain
Returns:
a list containing each of the TLV's in this chain, in order

getTlvMap

protected java.util.Map getTlvMap()
Description copied from class: AbstractTlvChain
Returns a map from TLV types (as Integers) to TLV lists (as Lists). The list should contain all TLV's of the given TLV type that exist in this TLV chain, in the same order as they appear in the full list.

Specified by:
getTlvMap in class AbstractTlvChain
Returns:
a map from TLV type to