{Aggregate-of t:Type} (クラス)
public abstract Aggregate-of {inherits Serializable}
パッケージ: CURL.LANGUAGE.CONTAINERS
直接継承しているサブクラス: WeakSet-of, Association-of, Set-of, Array-2-of

コレクションの抽象パラメータ化クラス。

t: コレクション内の要素のデータ型。

説明

Curl言語には、以下のようなコレクション タイプが組み込まれています。



このクラスは、これらの多くのコレクション タイプのスーパークラスです。つまり、Aggregate-of は、Curl における多くのコレクション クラスの基礎となるアクセッサおよびメソッドを備えています。

Aggregate-of は抽象クラスなので、インスタンス化することはできません。コレクション オブジェクトを作成するには、Aggregate-of からコードを継承するコレクション クラスのいずれかをインスタンス化します。

注意事項

Curl のコレクションクラスの部分階層は次のようになります。
Curl のコレクションの詳細は、Curl 開発者ガイド: コレクション を参照してください。

プロパティ
element-type:要素のデータ型を返します。
アクセサ public final inline Aggregate-of.element-type:Type
empty?:コレクションが空かどうかを調べます。
アクセサ public abstract Aggregate-of.empty?:bool

メソッド
clear:すべての要素を削除します。
public {Aggregate-of.clear}:void
clone:コレクションのクローンを返します。
public abstract {Aggregate-of.clone}:{Aggregate-of t}
filter:要素をフィルタリングします。
public abstract {Aggregate-of.filter p:{proc-type {t}:bool}}:void
filter-clone:要素が選別された、コレクションのクローンを返します。
public abstract {Aggregate-of.filter-clone
p:{proc-type {t}:bool}
}:{Aggregate-of t}
to-Iterator:コレクションの各要素を含む Iterator-of を返します。
public abstract {Aggregate-of.to-Iterator}:{Iterator-of t}
メソッド 継承 Object: object-describe, object-describe-for-debugging, object-serialize




プロパティ詳細
element-type (アクセサ)
アクセサ public final inline Aggregate-of.element-type:Type

要素のデータ型を返します。

戻り値

self 内の要素の Type。データ型は、プリミティブ データ型またはクラス データ型になります。


{value
    || Declare and initialize my-set (a set of strings).
    let my-set:{Set-of String} =
        {new {Set-of String}, "apple"}

    || Display the data type of the elements in my-set.
    {value my-set.element-type}
}


empty? (アクセサ)
アクセサ public abstract Aggregate-of.empty?:bool

コレクションが空かどうかを調べます。

戻り値

bool 値。self に要素がない場合、true を返します。それ以外の場合は、false を返します。

次の例は、要素を持たないセットを示しています。


{value
    || Declare and initialize an empty set.
    let my-set:{Set-of String} =
        {new {Set-of String}}

    || Check if the set is empty and display an
    || appropriate message.
    {if my-set.empty? then
        {text The set is empty!}
     else
        {text The set has elements!}
    }
}


次の例は、要素を持つセットを示しています。


{value
    || Declare and initialize a set with elements.
    let my-set:{Set-of String} =
        {new {Set-of String}, "apple"}

    || Check if the set is empty and display an
    || appropriate message.
    {if my-set.empty? then
        {text The set is empty!}
     else
        {text The set has elements!}
    }
}

注意事項

これは Aggregate-of の抽象メソッドで、Aggregate-of のサブクラス内で実装されます。





メソッド詳細
clear (メソッド)
public {Aggregate-of.clear}:void

すべての要素を削除します。

説明

このメソッドは、filter を使用した場合のように、一度に 1 つの要素を削除します。Aggregate-of をサブクラス化すると、このメソッドをオーバーライドし、効率的な実装が可能になります。たとえば、コレクションに書き込み可能な size プロパティがある場合、要素をフィルタリングするよりも size をリセットする方が効率的です。


{value
    || Declare and initialize my-set (a set of strings).
    let my-set:{Set-of String} =
        {new {Set-of String}, "apple", "banana", "cherry"}

    || Clear the set.
    {my-set.clear}

    || Check if the set is empty.
    {text The assertion that the set is empty is...
        {value my-set.empty?}}
}

注意事項

このメソッドは一般的なケースに対応しているため、このメソッドの実装には比較的時間がかかります。Aggregate-of から継承するクラスを作成する場合、パフォーマンスを向上させるためにこのメソッドをオーバーライドすることを検討してください。


clone (メソッド)
public abstract {Aggregate-of.clone}:{Aggregate-of t}

コレクションのクローンを返します。

戻り値

Aggregate-of のサブクラスのインスタンス。オブジェクトは、self と同じデータ型およびデータを持ちます。

説明

クローンは、self と同じデータ型を持つ新しいオブジェクトです。クローンには、self の要素の簡易コピー(shallow copy) が含まれます。つまり、どちらかのコレクションの要素に新しいオブジェクトを代入すると、もう一方の一致した要素は元のオブジェクトを参照します。ただし、要素のオブジェクトを変更すると、両方のコレクションは変更したオブジェクトを参照します。


{value
    || Declare and initialize set-1 (the original set).
    let set-1:{Set-of String} =
        {new {Set-of String}, "apple", "banana", "cherry"}

    || Initialize set-2 with a clone of the contents of
    || set-1.
    let set-2:{Set-of String} = {set-1.clone}

    || Use a VBox to display the contents of set-2.
    || Iterate over the contents of set-2, adding them
    || to the VBox.  Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:String in set-2 do
        {message.add each-element}
    }
    message
}

注意事項

これは Aggregate-of の抽象メソッドで、Aggregate-of のサブクラス内で実装されます。

注意事項

クローンの詳細については、『Curl 開発者ガイド』の「コレクション」で、使用しているコレクションのクローンに関するセクションを参照してください。


filter (メソッド)
public abstract {Aggregate-of.filter p:{proc-type {t}:bool}}:void

要素をフィルタリングします。

p: 要素をフィルタリングするプロシージャ。このメソッドは、self の各要素に対して p を呼び出します。プロシージャには、self の要素と同じデータ型を持つ 1 つの引数を指定する必要があります。プロシージャは、このメソッドが要素をフィルタリングするかどうかを示す bool 値を返す必要があります。pfalse を返す場合、このメソッドは self からその要素をフィルタリング (削除) します。ptrue を返す場合、要素は、self 内に残ります。

戻り値

このメソッドは値を返しません。

説明

p への呼び出しが false を返すコレクションの要素を削除します。

次の例では、コレクションから要素をフィルタリングします。


{value
    || Declare and initialize my-set (a set of strings).
    let my-set:{Set-of String} =
        {new {Set-of String}, "apple", "banana", "cherry"}

    || Filter elements that begin with the
    || letter 'a'.
    {my-set.filter
        {proc {str:String}:bool
            {return str[0] != 'a'}
        }
    }

    || Use a VBox to display the contents of my-set.
    || Iterate over the contents of my-set, adding them
    || to the VBox.  Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-set do
        {message.add each-element}
    }
    message
}

注意事項

これは Aggregate-of の抽象メソッドで、Aggregate-of のサブクラス内で実装されます。


filter-clone (メソッド)
public abstract {Aggregate-of.filter-clone
p:{proc-type {t}:bool}
}:{Aggregate-of t}

要素が選別された、コレクションのクローンを返します。

p: 要素をフィルタリングするプロシージャ。このメソッドは、self の各要素に対して p を呼び出します。プロシージャには、self の要素と同じデータ型を持つ 1 つの引数を指定する必要があります。プロシージャは、このメソッドが要素をフィルタリングするかどうかを示す bool 値を返す必要があります。pfalse を返す場合、このメソッドはその要素をフィルタリング(削除)します。ptrue を返す場合、要素は残ります。

戻り値

Aggregate-of のサブクラスのインスタンス。オブジェクトは、self と同じデータ型を持ちます。オブジェクトには、いくつかの要素がフィルタリングされた、コレクションのクローンが含まれます。

説明

このメソッドは、self のクローンを返します。クローンでは、p プロシージャへの呼び出しが false を返す要素が削除されます。クローンとは、self と同じデータ型を持つ新しいオブジェクトです。クローンには、self の浅い要素のコピー(shallow copy) が含まれます。つまり、どちらかの集合の要素に新しいオブジェクトを代入すると、もう一方の一致した要素は元のオブジェクトを参照します。ただし、要素のオブジェクトを変更すると、両方の集合は変更したオブジェクトを参照します。

次の例は、先頭に文字 a が付くすべての要素が選別されたセットのクローンを作成します。


{value
    || Declare and initialize set-1 (a set).
    let set-1:{Set-of String} =
        {new {Set-of String}, "apple", "banana", "cherry"}

    || Create a clone set-2 that contains the elements
    || of set-1 with strings that begin with the letter
    || 'a' filtered out.
    let set-2:{Set-of String} =
        {set-1.filter-clone
            {proc {str:String}:bool
                {return str[0] != 'a'}
            }
        }

    || Use a VBox to display the contents of set-2.
    || Iterate over the contents of set-2, adding them
    || to the VBox.  Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:String in set-2 do
        {message.add each-element}
    }
    {value message}
}

注意事項

これは Aggregate-of の抽象メソッドで、Aggregate-of のサブクラス内で実装されます。

注意事項

クローンの詳細については、『Curl 開発者ガイド』の「コレクション」で、使用しているコレクションのクローンに関するセクションを参照してください。


to-Iterator (メソッド)
public abstract {Aggregate-of.to-Iterator}:{Iterator-of t}

コレクションの各要素を含む Iterator-of を返します。

戻り値

self 内の要素と同じパラメータ化データ型を持つ Iterator-of。つまり、self{Aggregate-of int} の場合、このメソッドは {Iterator-of int} を返します。

説明

Iterator-of の要素の順序は、コレクション型に依存します。配列などの順序付けられたコレクションの場合、このメソッドはその順序を保存します。ハッシュ テーブルやセットなどの順序づけられていないコレクションの場合、要素の順序は任意に指定できます。


{value
    || Create a new set.
    let my-set:{Set-of String} =
        {new {Set-of String}, "apple", "banana", "cherry"}

    || Create an Iterator-of from the set.
    let my-iterator:{Iterator-of String} = {my-set.to-Iterator}

    || Use a VBox to display the contents of my-iterator.
    || Iterate over the contents of my-iterator, adding
    || them to the VBox.  Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-iterator do
        {message.add each-element}
    }
    message
}

注意事項

for コンテナ ループを使って同じ結果を得ることもできます。ただし、この反復処理メカニズムをオーバーライドすると、予期外の結果が生じる可能性があるので、可能な限り for ループを使用してください。

注意事項

これは Aggregate-of の抽象メソッドで、Aggregate-of のサブクラス内で実装されます。