public static void main(String[] args) { System.out.println("enum as array:"); System.out.println(" " + Arrays.toString(Color.values()) + "\n"); System.out.println("All enum constants:"); for (Color c : Color.values()) { System.out.println(" " + c.name() + "=" + c.ordinal()); } System.out.println("\nenum from a String:"); String color = "YELLOW"; Color c = Color.valueOf(color); System.out.println( " " + c.name() + "=" + c.ordinal() + " RGB=0x" + Integer.toHexString(c.getRGB())); System.out.println("\nenum from unknown String:"); String color2 = "yellow"; try { Color c2 = Color.valueOf(color2); // throws "IllegalArgumentException" System.out.println( " " + c2.name() + "=" + c2.ordinal() + " RGB=0x" + Integer.toHexString(c2.getRGB())); } catch (IllegalArgumentException iae) { System.out.println(" \"" + color2 + "\" not found in enum."); } // Sample of mapping an int to an enum: EnumSample service = new EnumSample(); switch (Index.valueOf(service.getIndex())) { case ONE: System.out.println("ONE"); break; case TWO: System.out.println("TWO"); break; case INVALID: System.out.println("INVALID"); break; case REG: break; case THREE: break; case ZERO: break; default: break; } }
public static TexturedPolygon newTexturedPolygon(Texture texture, Vector... vectors) { TexturedPolygon texturedPolygon = TexturedPolygonImpl.newInstance(texture, vectors); if (vectors.length >= 2) { if (texture instanceof ShadedTexture) { ShadedTexture shadedTexture = ShadedTexture.class.cast(texture); List<PointLight> pointLights = new ArrayList<>(); Vector normal = texturedPolygon.getNormal(); Vector location = null; double x = normal.getX(); double y = normal.getY() + 500.0D; double z = normal.getZ(); double distanceFalloff = 2500.0D; Color intensity = Color.white(); location = Vector.newInstance(x, y, z); PointLight pointLight = PointLight.newInstance(); pointLight.setLocation(location); pointLight.setIntensity(intensity); pointLight.setDistanceFalloff(distanceFalloff); pointLights.add(pointLight); Color ambientLightIntensity = Color.valueOf(0xFF333333); ShadedSurfaceTexture.createShadedSurfaceTexture( texturedPolygon, shadedTexture, pointLights, new ArrayList<Polygon>(), ambientLightIntensity); } else { Vector origin = vectors[0]; Vector v = vectors[1].copy(); Vector normal = texturedPolygon.getNormal(); v.subtract(origin); Vector u = Vector.toCrossProduct(normal, v); BoundingBox boundingBox = texturedPolygon.getTextureBounds(); boundingBox.setOrigin(origin); boundingBox.setU(u); boundingBox.setV(v); } } return texturedPolygon; }
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Construct a facelet cube from a string FaceCube(String cubeString) { for (int i = 0; i < cubeString.length(); i++) f[i] = Color.valueOf(cubeString.substring(i, i + 1)); }
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FaceCube() { String s = "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"; for (int i = 0; i < 54; i++) f[i] = Color.valueOf(s.substring(i, i + 1)); }