{Array-of t:Type} (クラス)
public serializable Array-of {inherits {Sequence-of t}}
パッケージ: CURL.LANGUAGE.CONTAINERS
直接継承しているサブクラス: OutputStreamArray-of, HttpFormData

1 次元配列のパラメータ化クラス。

t: 配列内の要素のデータ型。

説明

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



Array-of を使用すると、拡張可能な 1 次元配列を作成できます。Array-of などの Curl に組み込まれている順序付けられたコレクション クラスは、Sequence-of から継承されます。このようなコレクション内の要素は、0 から始まる連続する整数でインデックス付けされます。

注意事項

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

注意事項

コレクションを反復処理中にコレクションの内容を変更することは出来ません。

注意事項

配列がいっぱいになるたびに、元となる FastArray-of のサイズを約 2 倍に拡張します。新しく、より大きな FastArray-of を割り当て、すべての古い要素をそこにコピーする必要があります。
非常に大きな配列のスペースを節約するには、配列が特定のサイズ (現在は 1 MB) に達したら、増加要素を 4 分の1に減らします。
このアルゴリズムは将来のリリースで変更されることがあります。表示サイズのより正確な制御には、Array-of.efficient-size を使用します。

コンストラクタ
clone-from:要素の 1 次元配列を初期化します。
コンストラクタ public {Array-of.clone-from from:{Array-of t}}
default:要素の 1 次元配列を初期化します。
コンストラクタ public {Array-of.default efficient-size:int = -1, ...:t}
from-FastArray:要素の 1 次元配列を初期化します。
コンストラクタ public {Array-of.from-FastArray underlying-FastArray:{FastArray-of t}}
from-size:要素の 1 次元配列を初期化します。
コンストラクタ public {Array-of.from-size
size:int,
initial-value:t,
efficient-size:int = size
}
object-deserialize:
コンストラクタ public {Array-of.object-deserialize in:SerializeInputStream}

プロパティ
efficient-size:selfefficient-size を取得または設定します。
アクセサ public final inline Array-of.efficient-size:int
セッター public Array-of.efficient-size:int
for-loop-count:for ループを使った反復処理をサポートします。本来、直接使用するものではありません。
アクセサ public final inline Array-of.for-loop-count:int
size:self の (要素数など) サイズを取得します。
アクセサ public final inline Array-of.size:int
underlying-FastArray:データを格納する基本 FastArray-of。ただし、配列サイズが FastArray-of の制限を超えて変更された場合、これは置き換えられます。
アクセサ public final Array-of.underlying-FastArray:{FastArray-of t}
セッター public final Array-of.underlying-FastArray:{FastArray-of t}
プロパティ 継承 Association-of: empty?, key-type
プロパティ 継承 Aggregate-of: element-type

メソッド
append:self の最後に e を追加します。
public {Array-of.append e:t}:void
clear:self からすべての要素を削除します。
public {Array-of.clear}:void
clone:self のクローンを返します。
public {Array-of.clone}:{Array-of t}
clone-range:start で始まる length 要素を使って、self から新しい Sequence を作成します。
public {Array-of.clone-range start:int, length:int}:{Array-of t}
concat:self の最後に s1 を連結します。
public {Array-of.concat s:{Sequence-of t}}:void
equal?:構造的に等価であるかを調べるために、メソッドの引数と Self を比較します。
public {Array-of.equal? s2:{Sequence-of t}}:bool
filter-clone:いくつかの要素が選別された、self のクローンを返します。
public {Array-of.filter-clone p:{proc-type {t}:bool}}:{Array-of t}
filter-keys-clone:要素のキー (インデックス) を基に要素が選別された、self のクローンを返します。
public {Array-of.filter-keys-clone
p:{proc-type {int}:bool}
}:{Array-of t}
get:特定の要素を返します。
public final inline {Array-of.get index:int}:t
get-if-exists:特定の値、および示された要素が発見されたかどうかを示す bool を返します。
public final {Array-of.get-if-exists index:int}:(value:t, found?:bool)
in-bounds?:メソッドの引数が self の有効なインデックスであるかどうかを示します。
public {Array-of.in-bounds? index:int}:bool
insert:self 内の index で指定された位置の直前に e を挿入します。
public {Array-of.insert e:t, index:int}:void
object-serialize:クラス インスタンスが書き込まれるときに、シリアル化コードで呼び出されます。
public {Array-of.object-serialize out:SerializeOutputStream}:void
pop:self の最後から要素を削除して返します。
public {Array-of.pop}:t
push:self の最後に e をプッシュします。
public {Array-of.push e:t}:void
remove:self から 1 つまたは複数の連続する要素を削除します。
public {Array-of.remove
index:int,
length:int = 1,
error-if-missing?:bool = true
}:void
reverse:self 内の要素の順序を逆にします。
public {Array-of.reverse}:void
set:特定のインデックスの要素を設定します。
public final inline {Array-of.set index:int, element:t}:void
set-size:self のサイズを設定します。
public {Array-of.set-size new-size:int, new-val:t}:void
sort:self の要素をソートします。採用されているのは、安定なソート アルゴリズムです。つまり、同等の要素の相対的な順序は変更しません。
public {Array-of.sort
comparison-proc:#{proc-type {t, t}:bool} = null
}:void
splice:index で指定された位置の直前で s1self にスプライスします。
public {Array-of.splice s:{Sequence-of t}, index:int}:void
top-of-stack:スタックとして見たときに self の最上位にある要素を、self を変更しないで返します。これはシーケンスの最後の要素です。
public {Array-of.top-of-stack}:t
メソッド 継承 Sequence-of: filter, filter-keys, find, key-exists?, keys-to-Iterator, to-Iterator
メソッド 継承 Association-of: get-key, get-key-if-exists
メソッド 継承 Object: object-describe, object-describe-for-debugging



コンストラクタ詳細
clone-from (コンストラクタ)
public {Array-of.clone-from from:{Array-of t}}

要素の 1 次元配列を初期化します。

from: self の初期の内容は from からコピーされます。


default (コンストラクタ)
public {Array-of.default efficient-size:int = -1, ...:t}

要素の 1 次元配列を初期化します。

efficient-size: 配列を内部的に表す FastArray-of の推奨最大サイズ。この値は、配列のタイプおよびその他の内部的なセマンティクスに基づいて、最終的に調整されます。この値を少しでも変更すると、より大きい値に合わせて調整されます。 efficient-size を指定せず、要素が存在する場合、 efficient-size は、残余引数の数に基づいた適切な値に設定されます。 efficient-size を指定せず、要素が存在しない場合、 efficient-size は小さい値に設定されます(この値は「一般的な」使用パターンに基づいて選択されています)。
...: 残余引数は、配列内の最初の要素を指定します。残余引数は、配列に左から右に挿入され、一番左の引数は 0 インデックスに挿入されます。

次のコードは、初期要素を持たない配列のインスタンスを作成します。

{let my-array:{Array-of String} = {new {Array-of String}}}


次のコードは、3 つの初期要素を持つ配列のインスタンスを作成します。

{let my-array:{Array-of String} =
    {new {Array-of String}, "apple", "banana", "cherry"}}


from-FastArray (コンストラクタ)
public {Array-of.from-FastArray underlying-FastArray:{FastArray-of t}}

要素の 1 次元配列を初期化します。

underlying-FastArray: 配列を内部的に表す FastArray-of


from-size (コンストラクタ)
public {Array-of.from-size
size:int,
initial-value:t,
efficient-size:int = size
}

要素の 1 次元配列を初期化します。

size: 配列を内部的に表す FastArray-of の初期サイズを示します。
initial-value: すべての配列要素の初期値として使用する既定値。
efficient-size: 配列に含まれると予想されるアイテム数のヒント。このパラメータは、配列を内部的に表す FastArray-of の初期サイズを設定する場合に使用されます。この値は、self のタイプおよびその他の内部的な要素に基づいて調整されます。この値を少しでも変更すると、より大きい値に合わせて調整されます。 efficient-size を指定せず、要素が存在すると、 efficient-size は、要素のデータ型およびコードを実行するプラットフォームに対して最適なサイズに設定されます。


object-deserialize (コンストラクタ)
public {Array-of.object-deserialize in:SerializeInputStream}
この項目はサポートされていません。内部使用限定となっています。



プロパティ詳細
efficient-size (アクセサ)
アクセサ public final inline Array-of.efficient-size:int
セッター public Array-of.efficient-size:int

selfefficient-size を取得または設定します。

説明

これは Association-of.efficient-size で定義された有効なサイズを実装したものです。


for-loop-count (アクセサ)
アクセサ public final inline Array-of.for-loop-count:int

for ループを使った反復処理をサポートします。本来、直接使用するものではありません。

説明

Curl コンパイラで、self を反復処理するループのコンテナが検出されたときに使用されるゲッター。


size (アクセサ)
アクセサ public final inline Array-of.size:int

self の (要素数など) サイズを取得します。



underlying-FastArray (アクセサ)
アクセサ public final Array-of.underlying-FastArray:{FastArray-of t}
セッター public final Array-of.underlying-FastArray:{FastArray-of t}

データを格納する基本 FastArray-of。ただし、配列サイズが FastArray-of の制限を超えて変更された場合、これは置き換えられます。






メソッド詳細
append (メソッド)
public {Array-of.append e:t}:void

self の最後に e を追加します。

e: 追加する要素。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Append an element to the end of the array.
    {my-array.append "Sally"}

    || Use a VBox to display the contents of price.
    || Add each element to the VBox, then display
    || the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-array do
        {message.add each-element}
    }
    message
}

注意事項

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


clear (メソッド)
public {Array-of.clear}:void

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


{value
    || Declare and initialize my-array (an array
    || of String).
    let my-array:{Array-of String} =
        {new {Array-of String}, "apple", "banana", "cherry"}

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

    || Check if the array is empty.
    {text The array is empty is...
        {value my-array.empty?}}
}


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

self のクローンを返します。

戻り値

Sequence-ofのサブクラスのインスタンス。返されたオブジェクトは self と同じタイプです。

説明

クローンは、self と同じデータ型を持つ新しいオブジェクトで、クローンには self と同様、同じ要素が同じ順序で格納されます。


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

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

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

注意事項

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


clone-range (メソッド)
public {Array-of.clone-range start:int, length:int}:{Array-of t}

start で始まる length 要素を使って、self から新しい Sequence を作成します。

start: 新しいSequence にコピーされる最初の要素のインデックス。
length: コピーする要素の数。


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

    || Declare and initialize array-2 with a clone of the
    || two elements starting at index 1 of array-1.
    let array-2:{Array-of String} = {array-1.clone-range 1, 2}

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

注意事項

指定した範囲の一部が範囲外である場合、このメソッドは KeyNotFoundException をスローします。

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

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


concat (メソッド)
public {Array-of.concat s:{Sequence-of t}}:void

self の最後に s1 を連結します。

s1: 連結される要素の Sequence


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Declare and initialize another array with
    || String elements.
    let your-array:{Array-of String} =
        {new {Array-of String}, "Mary", "Sally"}

    || Concatenate the elements of your-array onto
    || the end of my-array.
    {my-array.concat your-array}

    || Use a VBox to display the contents of my-array.
    || For each key in my-array, add an HBox to the VBox.
    || The HBox contains the relevant key and element.
    || Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-array do
        {message.add each-element}
    }
    message
}

注意事項

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


equal? (メソッド)
public {Array-of.equal? s2:{Sequence-of t}}:bool

構造的に等価であるかを調べるために、メソッドの引数と Self を比較します。

s2: self と比較するオブジェクト。

戻り値

selfs2 が等しいかどうかを示す bool。このメソッドは、selfs2 が構造的に等しいと true を返し、両者が異なると false を返します。

説明

selfs2 と比較します。両方のコレクションに同じ要素数が含まれ、self の各要素が == s2 の対応する要素である場合、コレクションは構造的に等しいと見なされ、true が返されます。


|| Declare and initialize array-1 (an array
|| of String) with three elements.
{let array-1:{Array-of String} =
    {new {Array-of String}, "apple", "banana", "cherry"}
}

|| Declare and initialize array-2 (an array
|| of String) with two elements.
{let array-2:{Array-of String} =
    {new {Array-of String}, "apple", "banana"}
}

|| Determine if the arrays are equal.
The arrays are equal is...  {array-1.equal? array-2}

|| Add an element to array-2.
{array-2.append "cherry"}

|| And test the arrays for equality again.
After the append operation, the arrays are equal is...
{array-1.equal? array-2}


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

いくつかの要素が選別された、self のクローンを返します。

p: 特定の要素をフィルタリングするかどうかを判断します。このメソッドは、self の各要素に対して p を呼び出します。pfalse を返す場合、このメソッドはクローンにこの要素を含めません。ptrue を返す場合、この要素をクローンに含めます。

戻り値

Sequence-of のサブクラスのインスタンス。返されたオブジェクトは、self と同じタイプです。返されたオブジェクトには、いくつかの要素を選別した self のクローンが含まれます。

次の例は、先頭に文字 a が付くすべての要素が除外された配列のクローンを作成します。


{value
    || Declare and initialize array-1 (an array
    || of String).
    let array-1:{Array-of String} =
        {new {Array-of String}, "apple", "banana", "cherry"}

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

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

注意事項

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


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

要素のキー (インデックス) を基に要素が選別された、self のクローンを返します。

p: 特定の要素をフィルタリングするかどうかを判断します。このメソッドは、self の各要素のキー (インデックス) に対して p を呼び出します。pfalse を返す場合、このメソッドはクローンにその要素を含めません。ptrue を返す場合、この要素をクローンに含めます。

戻り値

Sequence-of のサブクラスのインスタンス。返されたオブジェクトは、self と同じタイプです。返されたオブジェクトには、いくつかの要素を選別した self のクローンが含まれます。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Create a clone that contains the elements of the
    || original, except that elements with even keys are
    || filtered out.
    let new-array:{Array-of String} =
        {my-array.filter-keys-clone
            {proc {index:int}:bool
                {return (index mod 2) == 0}
            }
        }

    || Use a VBox to display the contents of new-array.
    || Add each element to the VBox, then display
    || the VBox.
    let message:VBox = {VBox}
    {for each-element:String in new-array do
        {message.add each-element}
    }
    message
}

注意事項

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


get (メソッド)
public final inline {Array-of.get index:int}:t

特定の要素を返します。

index: 取得する要素のインデックスを示します。

戻り値

取得した要素。戻り値は self.element-type 型です。


|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
    {new {Array-of String},
        "apple",
        "banana",
        "cherry"
    }
}

|| Display the element at index 2.
{my-array.get 2}

注意事項

index が範囲外の場合は、ArrayBoundsException をスローします。

配列アクセス式を使って同じ機能を実行できます。たとえば次のようになります。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String},
            "apple",
            "banana",
            "cherry"
        }

    || Display the element at index 2.
    my-array[2]
}


get-if-exists (メソッド)
public final {Array-of.get-if-exists index:int}:(value:t, found?:bool)

特定の値、および示された要素が発見されたかどうかを示す bool を返します。

index: 取得する要素のインデックスを示します。

戻り値

要素が発見された場合、取得した要素。要素が発見された場合、この戻り値は self.element-type 型になります。

2 番目に返された値は、index が有効かどうかを示します。

index が有効でない場合、最初に返される値は不確定です。

注意事項

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


in-bounds? (メソッド)
public {Array-of.in-bounds? index:int}:bool

メソッドの引数が self の有効なインデックスであるかどうかを示します。

index: テストするインデックスを指定します。

戻り値

このメソッドは、indexself の有効なインデックスである場合、true を返し、それ以外の場合、false を返します。

説明

index0 から self.size - 1 までの数値の場合は、true を返します。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Check if there is an element at index 3.
    || Remember that the first element in an array
    || is at index 0.
    {if {my-array.in-bounds? 3} then
        {text It is there!}
     else
        {text It is not there.}
    }
}

注意事項

このメソッドは、Sequence-of.key-exists? と同じ機能を提供します。


insert (メソッド)
public {Array-of.insert e:t, index:int}:void

self 内の index で指定された位置の直前に e を挿入します。

e: 挿入される要素。
index: e が挿入される場所を指定します。挿入後の e のインデックスは index になります。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Insert an element at position 1.  Subsequent
    || elements are shifted one position to the right.
    {my-array.insert "Mary", 1}

    || Insert an element at position 4.
    {my-array.insert "Sally", 4}

    || Use a VBox to display the contents of price.
    || Add each element to the VBox, then display
    || the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-array do
        {message.add each-element}
    }
    message
}

注意事項

index が範囲外の場合、このメソッドは KeyNotFoundException をスローします。

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


object-serialize (メソッド)
public {Array-of.object-serialize out:SerializeOutputStream}:void

クラス インスタンスが書き込まれるときに、シリアル化コードで呼び出されます。

out: このメソッドを呼び出した SerializeOutputStream

説明

このメソッドは、次のステップを順番に実行する必要があります。
  1. SerializeOutputStream.write-class-version を呼び出します。通常は引数にゼロ (0) を指定します。
  2. シリアル化可能なスーパークラスごとに super.object-serialize を呼び出します。
  3. シリアル化された状態を out に書き込みます。これは通常、フィールドごとに SerializeOutputStream.write-one を呼び出すことによって実行されます。

注意事項

このメソッドは、シリアル化可能なサブクラスでのみ定義する必要があります。


pop (メソッド)
public {Array-of.pop}:t

self の最後から要素を削除して返します。

説明

要素のポップ (取り出し) は、通常後入れ先出し (LIFO) スタックで実行される操作です。このメソッドは、self 内の最後の要素を削除し、それを返します。(self の終わりにある要素は、インデックス size - 1 の要素です)。

Sequence-of.push および Sequence-of.top-of-stack も参照してください。


例: スタックから要素をポップ
|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
    {new {Array-of String}, "Tom", "Dick", "Harry"}}

|| Pop an element from the array.
{text The return value of a pop operation is...}
{my-array.pop}

|| Use a VBox to display the contents of my-array.
|| Add each element to the VBox, then embed the
|| VBox within another for display.
{let message:VBox = {VBox}}
{for each-element:String in my-array do
    {message.add each-element}
}
{VBox
    {text After the pop operation, the array has the
        following elements...},
    {value message}
}

注意事項

シーケンスが空の場合など、self.size0 の場合、このメソッドは KeyNotFoundException をスローします。

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


push (メソッド)
public {Array-of.push e:t}:void

self の最後に e をプッシュします。

e: プッシュされる要素。

説明

要素のプッシュは、通常後入れ先出し法 (LIFO) スタックで実行される操作です。要素をスタックにプッシュする際に、その要素をスタックの最後に追加します。このメソッドを呼び出すと、eself の最後に追加されます。

Sequence-of.pop および Sequence-of.top-of-stack も参照してください。


例: スタックに要素をプッシュ
{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Append an element to the end of the array.
    {my-array.push "Sally"}

    || Use a VBox to display the contents of my-array.
    || Add each element to the VBox, then display
    || the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-array do
        {message.add each-element}
    }
    message
}

注意事項

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


remove (メソッド)
public {Array-of.remove
index:int,
length:int = 1,
error-if-missing?:bool = true
}:void

self から 1 つまたは複数の連続する要素を削除します。

index: 削除する (最初の) 要素のインデックスを指定します。
length: 削除する連続する要素の数を指定します (既定では 1 に設定)。
error-if-missing?: 存在しない要素を削除することを要求した場合に、このメソッドが ArrayBoundsException をスローするかどうかを示します (既定では true に設定)。

説明

{self.key-exists? i}index から index + length - 1 までのすべての i に対して、true である場合、このメソッドは self から適切な要素を削除します。

{self.key-exists? i} が指定した範囲内の任意の ifalse で、 error-if-missing?true である場合、このメソッドは ArrayBoundsException をスローします。

error-if-missing?false の場合、このメソッドは {self.key-exists? i}true である、指定したすべての i 要素を削除し、それ以外に対しては何のアクションも実行されません。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String},
            "apple",
            "banana",
            "cherry"
        }

    || Remove the element at index 1.
    {my-array.remove 1}

    || Use a VBox to display the contents of my-array.
    || For each element in my-array, add a string to the
    || VBox.  Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-array do
        {message.add each-element}
    }
    message
}


reverse (メソッド)
public {Array-of.reverse}:void

self 内の要素の順序を逆にします。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Reverse the order of the elements.
    {my-array.reverse}

    || Use a VBox to display the contents of price.
    || Add each element to the VBox, then display
    || the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-array do
        {message.add each-element}
    }
    message
}

注意事項

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


set (メソッド)
public final inline {Array-of.set index:int, element:t}:void

特定のインデックスの要素を設定します。

index: 設定する要素のインデックスを示します。
element: 設定する要素の値。このパラメータのタイプは self.element-type です。

説明

key が範囲内の場合、このメソッドは element に関連付けられた要素の値を変更します。

key が範囲外の場合、このメソッドは ArrayBoundsException をスローします。


|| Declare and initialize a hash table with
|| String keys and int elements.
|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
    {new {Array-of String},
        "apple",
        "banana",
        "cherry"
    }
}

|| Set the element at index 1 to "plum".
{my-array.set 1, "plum"}

|| Use a VBox to display the contents of my-array.
|| For each element in my-array, add an HBox to the
|| VBox.  The HBox contains the relevant index and
|| element.  Then display the VBox.
{let message:VBox = {VBox}}
{for key each-element:int in my-array do
    {message.add {HBox each-element, " ", {my-array.get each-element}}}
}
{value message}

注意事項

set 式と配列アクセス式を使って類似機能を実行できます。たとえば次のようになります。


|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
    {new {Array-of String},
        "apple",
        "banana",
        "cherry"
    }
}

|| Set the element at index 1 to "plum".
{set my-array[1] = "plum"}

|| Use a VBox to display the contents of my-array.
|| For each element in my-array, add an HBox to the
|| VBox.  The HBox contains the relevant index and
|| element.  Then display the VBox.
{let message:VBox = {VBox}}
{for key each-element:int in my-array do
    {message.add {HBox each-element, " ", {my-array.get each-element}}}
}
{value message}


set-size (メソッド)
public {Array-of.set-size new-size:int, new-val:t}:void

self のサイズを設定します。

new-size: self の新しいサイズを示します。このパラメータが負の数値の場合、このメソッドは ArrayBoundsException をスローします。
new-val: new-sizeself.size の現在の値よりも大きい場合は、新しく作成したスロットに入力する値を示します。

注意事項

new-size < 0 の場合、このメソッドは ArrayBoundsException をスローします。


sort (メソッド)
public {Array-of.sort
comparison-proc:#{proc-type {t, t}:bool} = null
}:void

self の要素をソートします。採用されているのは、安定なソート アルゴリズムです。つまり、同等の要素の相対的な順序は変更しません。

comparison-proc: ソート目的で要素を比較します。このプロシージャは、self 内の 2 つの要素に適用されるときに、その 2 つの要素が既に適切な順序になっている場合に true を返します。

このパラメータが指定されていない場合、システムは、要素を昇順でソートする既定値を選択しようとします。

次の例は、{Array-of String} を昇順 (既定) で並べます。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Sort the elements.
    {my-array.sort}

    || Use a VBox to display the contents of price.
    || Add each element to the VBox, then display
    || the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-array do
        {message.add each-element}
    }
    message
}


次の例は、{Array-of int} を降順で並べます。


{value
    || Declare and initialize an array with int
    || elements.
    let my-array:{Array-of int} =
        {new {Array-of int}, 7, 69, 13, 33, 22}

    || Sort the elements into descending order.
    {my-array.sort comparison-proc =
        {proc {x:int, y:int}:bool
            {return x > y}
        }
    }

    || Use a VBox to display the contents of my-array.
    || Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:int in my-array do
        {message.add each-element}
    }
    message
}

注意事項

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


splice (メソッド)
public {Array-of.splice s:{Sequence-of t}, index:int}:void

index で指定された位置の直前で s1self にスプライスします。

s1: スプライス先の要素の Sequence
index: s1の最初の要素を挿入する場所を指定します。挿入後に、s1の最初の要素のインデックスは index になります。s1 の他の要素は、順番に挿入されます。


{value
    || Declare and initialize an array with String
    || elements.
    let my-array:{Array-of String} =
        {new {Array-of String}, "Tom", "Dick", "Harry"}

    || Declare and initialize another array with
    || String elements.
    let your-array:{Array-of String} =
        {new {Array-of String}, "Mary", "Sally"}

    || Insert the elements of your-array into my-array
    || at index 1.  Subsequent elements of my-array
    || are shifted to the right.
    {my-array.splice your-array, 1}

    || Use a VBox to display the contents of my-array.
    || For each key in my-array, add an HBox to the VBox.
    || The HBox contains the relevant key and element.
    || Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-array do
        {message.add each-element}
    }
    message
}

注意事項

index が範囲外の場合、このメソッドは KeyNotFoundException をスローします。

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


top-of-stack (メソッド)
public {Array-of.top-of-stack}:t

スタックとして見たときに self の最上位にある要素を、self を変更しないで返します。これはシーケンスの最後の要素です。

戻り値

シーケンスの上にある要素。

説明

コレクションの最上位にある値を返すという処理は、通常後入れ先出し (LIFO) スタックで実行される操作です。このメソッドは、self の最後の要素を返します。 このメソッドを呼び出しても、 self のコンテンツは変更されません。しかし、既定の実装では一時的に状態を変える push に続く pop を呼び出します。Array-of を含む多くのサブクラスでは、この問題を回避するためにこのメソッドをオーバーライドしてください。 Sequence-of.pushSequence-of.pop も参照してください。


例: スタックの上部の要素を取得します。
|| Declare and initialize an array with String
|| elements.
{let my-array:{Array-of String} =
    {new {Array-of String}, "Tom", "Dick", "Harry"}
}

|| View the top of the stack.
{text The return value of a top-of-stack operation is...}
{my-array.top-of-stack}

|| Use a VBox to display the contents of my-array.
|| Add each element to the VBox, then embed the
|| VBox within another for display.
{let message:VBox = {VBox}}
{for each-element:String in my-array do
    {message.add each-element}
}
{VBox
    {text After the top-of-stack operation, the array has
        the following elements...},
    {value message}
}

注意事項

シーケンスが空の場合など、self.size0 の場合、このメソッドは KeyNotFoundException をスローします。