/** * Set the layer that a given shape will be displayed in. Since the shapes in this game are two * dimensional, it must be decided which will appear "on top" when two shapes overlap. The shape * in the higher layer will appear on top. * * <p>Setting a shape's layer will only affect how it is displayed; a shape's layer has no effect * on how it interacts with other shapes. (For example, two shapes can touch even if they are in * different layers. See {@link Shape#isTouching(Shape)}.) * * @param shape the shape whose layer is being set. * @param layer the layer into which this shape will be moved. */ static void setLayer(Shape shape, int layer) { removeFromLayers(shape); // add new stuff if (!layerContents.containsKey(layer)) { layerContents.put(layer, new CopyOnWriteArrayList<Shape>()); int insertionPoint = ~Collections.binarySearch(layers, layer); layers.add(insertionPoint, layer); } layerContents.get(layer).add(shape); layerOf.put(shape, layer); }