Fix java-specific errors causing type problems

By making the CachedArrays inner class a static nested class instead, we can
instantiate it from outside the CachingBFS class. Then by making CacheQueue
*have* rather than *be* a Queue, we can skip all the type shenanigans with
generics.
Rearrange destructive queue iteration for empty case