パッケージ org.piax.common.attribs

クラス RowData

java.lang.Object
org.piax.common.attribs.RowData
すべての実装されたインタフェース:
Serializable, Destination, Key

public class RowData
extends Object
implements Key
テーブルrowに相当するデータを管理するクラス。 Id型の識別子(rowId)を持つ。テーブルではこのrowIdによってユニークに識別される。 内部には属性名と属性値のペアを保持する。

属性値のセット(setAttrib)の際には、その属性値をindex化をするかどうかの選択ができる。 index化された属性値は、属性を管理するオブジェクト(Attribute)の持つMap(Comparableな場合は NavigableMap)に登録され、その属性値をsearchする処理が高速になる。 さらに、AttributeにOverlayがbindされた場合には、その属性値がOverlayに 自動的にaddKeyされ、他のピアからの検索対象となる。(index化の主目的はここにある)

但し、index化には次の点に留意する必要がある。

  • setAttribの時点で、Attributeは型を持っている必要がある。
  • 属性値は、Attributeの持つ型と互換(代入可能)でなければいけない。
逆にindex化をしない場合、Attributeの型やbindされているOverlayについて考慮する 必要がなくなり、たとえ、他の誰かによって、意図しないAttributeの型付がされた場合も不整合は生じない。 index化しない属性値は、検索対象に用いると非効率であるが、RowDataをキーとなる属性で検索した後、 別の属性の値として取得することには向いている。

RowData全体をAttributeから一時的に解放することも可能である。このために、bindToAttribute/ unbindToAttributeのメソッドが用意されている。unbindされると、すべての属性値はAttributeの index化から外される。これによって、RowDataは検索対象から外れる。bindによってこの状態は元に戻る。 この機能は、Agentのsleep/wakupの実現を意図した機能となっている。

属性値に対する操作メソッドはすべて同期化されていて、お互いが並行に動作することはない。

特殊なケースであるが、RowDataはCombinedOverlayでは検索対象のKeyとして扱われる。 このため、RowDataはKeyをimplementsしている。 (SkipGraphなどへのaddKeyの対象にはならないところに注意)

関連項目:
直列化された形式
  • フィールド詳細

    • table

      protected transient AttributeTable table
    • rowId

      public Id rowId
    • isBoundToAttribute

      protected boolean isBoundToAttribute
      RowDataがAttributeの管理下(bound)にあるかどうかを保持するための状態フラグ。 主な用途はAgentのsleepとwakeup。 unboundな状態で追加されたvalueは実際にはAttributeのindex化の対象とはならない。 このようにsetAttribされたデータはboundの状態に移行した時に、一括してindex化される。 また、boundからunboundな状態に移行した際には、すべてのindex化対象のvalueが Attributeのindex化から外される。
  • コンストラクタの詳細

    • RowData

      protected RowData​(AttributeTable table, Id rowId, boolean isBoundToAttribute)
      RowDataを生成する。 通常は、AttribTableがRowDataの生成を行う。 このため、protected にしている。
      パラメータ:
      table - a table.
      rowId - a row ID.
      isBoundToAttribute - a flag that indicates the row data is managed by the Attribute.
  • メソッドの詳細

    • fin

      public void fin()
    • isBoundToAttribute

      public boolean isBoundToAttribute()
    • bindToAttribute

      public boolean bindToAttribute()
    • unbindToAttribute

      public boolean unbindToAttribute()
    • setAttrib

      public boolean setAttrib​(String name, Object value) throws IllegalArgumentException, IncompatibleTypeException
      例外:
      IllegalArgumentException
      IncompatibleTypeException
    • setAttrib

      public boolean setAttrib​(String name, Object value, boolean useIndex) throws IllegalArgumentException, IncompatibleTypeException
      指定された属性名で属性値をセットする。 useIndexをtrueで指定した場合は、Attributeがindex可能状態にあるときにのみ、 その属性値はindex化される。index化された場合は返り値にtrueが返される。 index化されなかった場合は、falseが返される。

      Attributeが型を持っていて、属性値が代入不可能な場合はIncompatibleTypeExceptionが throwされて、属性値のセットは失敗する。 RowDataがisBoundToAttributeでない場合は、実際には Attributeのindexには反映されない。 次に、boundな状態になったタイミングで一括登録される。

      パラメータ:
      name - 属性名
      value - 属性値
      useIndex - indexが使える場合に使うときにtrueを指定する
      戻り値:
      index化された場合 true
      例外:
      IllegalArgumentException - 属性名または属性値にnullがセットされた場合
      IncompatibleTypeException - 属性値が代入不可能な場合
    • removeAttrib

      public boolean removeAttrib​(String name) throws IllegalStateException
      setAttribでセットした属性値を削除する。 削除対象の属性値が存在しない(過去にsetAttribでセットされていない)場合は、falseが返される。

      通常は起こらないが、setAttribをした際にindex化された属性値がAttributeの内部ではindex化 されていなかったり、Attribute自体がtypeを持っていない(typeを持っていないとindex化はできない) ことが検知された場合、IllegalStateExceptionがthrowされる。 RowDataがisBoundToAttributeでない場合は、実際には Attributeのindexには反映されない。 次に、boundな状態になったタイミングで一括削除される。

      パラメータ:
      name - 属性名
      戻り値:
      属性値の削除に成功した場合はtrue、削除対象の属性値が存在しない場合はfalse
      例外:
      IllegalStateException - Attributeの状態の中に不整合を検知した場合
    • getAttribValue

      public Object getAttribValue​(String attribName)
      指定されたnameの属性値を返す。 テーブルがsuperRowを持つ場合は、その属性値もチェックする。
      パラメータ:
      attribName - the attribute name
      戻り値:
      the value to be associated with the specified name
    • getAttribValues

      public List<Object> getAttribValues()
    • isIndexed

      public boolean isIndexed​(String attribName) throws IllegalArgumentException
      属性値がindex化されている場合 trueを返す。
      パラメータ:
      attribName - 属性名
      戻り値:
      属性値がindex化されている場合 true
      例外:
      IllegalArgumentException - 属性名が存在しない場合
    • getAttribNames

      public List<String> getAttribNames()
      Returns a list of attribute names. The returned list is a snapshot at the time the function is called.
      戻り値:
      a list of attribute names.
    • getIndexedAttribNames

      public List<String> getIndexedAttribNames()
      Returns an indexed list of attribute names. The returned list is a snapshot at the time the function is called.
      戻り値:
      a list of indexed attribute names.
    • getUnindexedAttribNames

      public List<String> getUnindexedAttribNames()
      Returns an not-indexed attribute names. The returned list is a snapshot at the time the function is called.
      戻り値:
      an not-indexed list of attribute names.
    • satisfies

      public boolean satisfies​(List<VarDestinationPair> conds)
      RowDataがリストの要素であるVarSubsetPairをすべて満たすかどうかを判定する。
      パラメータ:
      conds - VarSubsetPairのリスト
      戻り値:
      リストの要素であるVarSubsetPairをすべて満たした場合true
    • toString

      public String toString()
      オーバーライド:
      toString クラス内 Object