summaryrefslogtreecommitdiffstats
path: root/trunk/ardor3d-core
diff options
context:
space:
mode:
authorhiflyer <[email protected]>2012-10-15 12:41:14 +0200
committerhiflyer <[email protected]>2012-10-15 12:41:14 +0200
commit9433d88702ce4c5a710bcd20f193aeefce226aac (patch)
treee34360272ba4d1c7467a9f1e26d9c21ced2bb339 /trunk/ardor3d-core
parente60afe7110d0d43cdc41f44aa631de19f312ec54 (diff)
getRenderBucketType now returns the same instance when called with the same name
Diffstat (limited to 'trunk/ardor3d-core')
-rwxr-xr-x[-rw-r--r--]trunk/ardor3d-core/src/main/java/com/ardor3d/renderer/queue/RenderBucketType.java16
-rwxr-xr-xtrunk/ardor3d-core/src/test/java/com/ardor3d/renderer/queue/RenderBucketTypeTest.java38
2 files changed, 42 insertions, 12 deletions
diff --git a/trunk/ardor3d-core/src/main/java/com/ardor3d/renderer/queue/RenderBucketType.java b/trunk/ardor3d-core/src/main/java/com/ardor3d/renderer/queue/RenderBucketType.java
index bd48c03..d5f881d 100644..100755
--- a/trunk/ardor3d-core/src/main/java/com/ardor3d/renderer/queue/RenderBucketType.java
+++ b/trunk/ardor3d-core/src/main/java/com/ardor3d/renderer/queue/RenderBucketType.java
@@ -11,10 +11,11 @@
package com.ardor3d.renderer.queue;
import java.util.HashMap;
+import java.util.Map;
public final class RenderBucketType {
- public static final RenderBucketType getRenderBucketType(final String name) {
+ public static RenderBucketType getRenderBucketType(final String name) {
if (name == null) {
throw new IllegalArgumentException("name must not be null!");
}
@@ -22,11 +23,12 @@ public final class RenderBucketType {
RenderBucketType bucketType = bucketTypeMap.get(name);
if (bucketType == null) {
bucketType = new RenderBucketType(name);
+ bucketTypeMap.put(name, bucketType);
}
return bucketType;
}
- private static final HashMap<String, RenderBucketType> bucketTypeMap = new HashMap<String, RenderBucketType>();
+ private static final Map<String, RenderBucketType> bucketTypeMap = new HashMap<String, RenderBucketType>();
private final String name;
@@ -43,16 +45,6 @@ public final class RenderBucketType {
return name();
}
- @Override
- public boolean equals(final Object obj) {
- return this == obj;
- }
-
- @Override
- public int hashCode() {
- return name.hashCode();
- }
-
/**
* Use your parent's RenderBucketType. If you do not have a parent, {@link #Opaque} will be used instead.
*/
diff --git a/trunk/ardor3d-core/src/test/java/com/ardor3d/renderer/queue/RenderBucketTypeTest.java b/trunk/ardor3d-core/src/test/java/com/ardor3d/renderer/queue/RenderBucketTypeTest.java
new file mode 100755
index 0000000..93e0786
--- /dev/null
+++ b/trunk/ardor3d-core/src/test/java/com/ardor3d/renderer/queue/RenderBucketTypeTest.java
@@ -0,0 +1,38 @@
+package com.ardor3d.renderer.queue;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+public class RenderBucketTypeTest {
+
+ @Test
+ public void getPrebucket() throws Exception {
+ RenderBucketType preBucket = RenderBucketType.getRenderBucketType("PreBucket");
+ assertNotNull(preBucket);
+
+ RenderBucketType preBucket2 = RenderBucketType.getRenderBucketType("PreBucket");
+ assertSame(preBucket, preBucket2);
+ assertSame(RenderBucketType.PreBucket, preBucket);
+ }
+
+ @Test
+ public void getUserDefined() throws Exception {
+ RenderBucketType myBucket = RenderBucketType.getRenderBucketType("MyBucket");
+ assertNotNull(myBucket);
+
+ RenderBucketType myBucket2 = RenderBucketType.getRenderBucketType("MyBucket");
+ assertSame(myBucket, myBucket2);
+ }
+
+ @Test
+ public void getWithNull() throws Exception {
+ try {
+ RenderBucketType nullBucket = RenderBucketType.getRenderBucketType(null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ }
+}