私はこのようなものを持っています:
something need here = scope.getConnections();
//getConnections() returns Collection<Set<IConnection>>
getConnections()
すべての接続(返されるもの)を反復処理する必要があります
どうやってするか ?
私はこのようなものを持っています:
something need here = scope.getConnections();
//getConnections() returns Collection<Set<IConnection>>
getConnections()
すべての接続(返されるもの)を反復処理する必要があります
どうやってするか ?
Collection<Set<IConnection>> sets = scope.getConnections();
for (Set<IConnection> set : sets) {
for (IConnection connection : set) {
//do something
}
}
for (Set<IConnection> set : scope.getConnections()) {
for (IConnection iConnection : set) {
// use each iConnection
}
}
私はあなたがそうするように接続を返さないことをお勧めします。
getConnectionsはのみを返す必要があります
Collection<IConnection>
public Collection<IConnection> getConnections()
{
return connections;
}
クラス内で、必要な方法または保存する必要のある方法を選択できます
private Set<IConnection> connections;
クラス設計の問題としてダブルループを検討してください。
あなたのクラスのユーザーとして私があなたのクラスの使用をやめるたびにダブルループを書かなければならない場合。あなたの同僚もそうします。
for (IConnection connection : provider.getConnections())
{
connection.doAction();
}
2つのネストされたforループの答えがおそらく必要なすべてですが、「connections」コレクションをgoogle-collectionsのIterables.concat()に渡して、単一の「フラット化された」反復可能ファイルを取得することもできることに注意してください。