jonas_fe
jonas_fe

Reputation: 51

Counting connections of specific agent type

I have the code (see below), which counts agents ("developers") in a specific state. This works just fine.

Now I do not want to count agents in a specific state, but agents of a specific type only. How can I alter the code (or write some new code) to achieve this?

Thank you very much!

return this.getConnections()
    .stream()
    .filter(Developer -> Developer.inState(WantA))
    .count(); 

Upvotes: 0

Views: 143

Answers (1)

Sahar Esmaeilzadeh
Sahar Esmaeilzadeh

Reputation: 135

You can check object type in Java by using the instanceofkeyword.

return this.getConnections()
.stream()
.filter(obj -> obj instanceof ClassName)
.count();

Upvotes: 1

Related Questions