BallContainer
public class BallContainer : Sequence
This is a container can be used to contain Balls. A Ball with a particular volume and color may only appear in a BallContainer once.
-
Declaration
Swift
public typealias Element = Ball -
Declaration
Swift
public typealias Iterator = Set<Ball>.Iterator -
Creates an iterator for the container to support the Sequence protocol, which enables us to, eg, use a
forloop over the balls in aBallContainer.Declaration
Swift
public func makeIterator() -> IteratorReturn Value
An iterator for the container.
-
Adds a ball to the container. This method returns
trueif ball was successfully added to the container, i.e. ball is not already in the container. Of course, you are allowed to put a Ball into a container only once. Hence, this method returnsfalse, if ball is already in the container.Declaration
Swift
public func add(_ ball: Ball) -> BoolParameters
ballBall to be added.
Return Value
true if ball was successfully added to the container, i.e. ball is not already in the container. Returns false, if ball is already in the container.
-
Removes a ball from the container. This method returns
trueif ball was successfully removed from the container, i.e. ball is actually in the container. You cannot remove a Ball if it is not already in the container and so ths method will returnfalse, otherwise.Declaration
Swift
public func remove(_ ball: Ball) -> BoolParameters
ballBall to be removed.
Return Value
true if ball was successfully removed from the container, i.e. ball is actually in the container. Returns false, if ball is not in the container.
-
Each Ball has a volume. This method returns the total volume of all the Balls in the container.
Declaration
Swift
public var volume: Double { get }Return Value
the volume of the contents of the container.
-
Returns the number of Balls in this container.
Declaration
Swift
public var count: Int { get }Return Value
the number of Balls in this container.
-
Empties the container, i.e. removes all its contents.
Declaration
Swift
public func removeAll() -
This method returns
trueif this container contains the specified Ball. It will returnfalseotherwise.Declaration
Swift
public func contains(_ ball: Ball) -> BoolParameters
ballBall to be checked if its in container
Return Value
true if this container contains the specified Ball. Returns false, otherwise.
BallContainer Class Reference