Game Development Reference
In-Depth Information
Figure 10-4 . Add .addCurrentCast(), removeCurrentCast(), and resetCurrentCast methods to the CastingDirector
class
The second method that we will code is the .removeCurrentCast() method, which
will also pass in a comma delimited List of Actor objects to the List (and ArrayList
class implementing List) interfaces .removeAll() method call.
To show this .removeCurrentCast() method that we are going to pass more than one
Actor object into the body of the method, we again use the Actor... annotation, and I
am going to again name this variable actors . Inside of the body of the .removeCur-
rentCast() method we will again call the .removeAll() method off of the
CURRENT_CAST object, and inside of the .removeAll() method we'll nest another
Java statement that will create an Arrays object from the comma delimited List using
the .asList() method called off the Arrays class reference, again passing the Actor...
comma delimited list named actors into the method. This is done using the following
Java method seen in Figure 10-4 :
public void removeCurrentCast (Actor... actors) {
CURRENT_CAST. removeAll ( Arrays. asList (actors) );
}
Now all you have left to code is a simple .resetCurrentCast() method, which in-
vokes the .clear() method call:
public void resetCurrentCast () {
CURRENT_CAST. clear ();
}
Next let's take a look at one more issue in our CastingDirector.java code thus far,
and then we can move on.
NetBeans Optimization Suggestions: Making a List<Act-
or> Data Store Object Final
As you can see in Figure 10-5 , your code is error-free, but is not warning free, so let's
take a look at what NetBeans wants us to do to the code that relates to our
CURRENT_CAST List<Array> data store object. I used the mouse-over work process,
and popped up the pale yellow hints message, which informed me that the
CURRENT_CAST data field (variable, which is an object) can be marked as final, us-
 
Search WWH ::




Custom Search