aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/packrect
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-07-03 16:21:36 +0200
committerSven Gothel <[email protected]>2014-07-03 16:21:36 +0200
commit556d92b63555a085b25e32b1cd55afce24edd07a (patch)
tree6be2b02c62a77d5aba81ffbe34c46960608be163 /src/jogl/classes/com/jogamp/opengl/util/packrect
parenta90f4a51dffec3247278e3c683ed4462b1dd9ab5 (diff)
Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74)
- Change non static accesses to static members using declaring type - Change indirect accesses to static members to direct accesses (accesses through subtypes) - Add final modifier to private fields - Add final modifier to method parameters - Add final modifier to local variables - Remove unnecessary casts - Remove unnecessary '$NON-NLS$' tags - Remove trailing white spaces on all lines
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/packrect')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java54
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java52
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java54
4 files changed, 87 insertions, 87 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java
index 9aadfba93..e694f1b33 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java
@@ -42,29 +42,29 @@ package com.jogamp.opengl.util.packrect;
import java.util.*;
public class Level {
- private int width;
+ private final int width;
private int height;
- private int yPos;
- private LevelSet holder;
+ private final int yPos;
+ private final LevelSet holder;
- private List<Rect> rects = new ArrayList<Rect>();
+ private final List<Rect> rects = new ArrayList<Rect>();
private List<Rect> freeList;
private int nextAddX;
static class RectXComparator implements Comparator<Rect> {
@Override
- public int compare(Rect r1, Rect r2) {
+ public int compare(final Rect r1, final Rect r2) {
return r1.x() - r2.x();
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
return this == obj;
}
}
private static final Comparator<Rect> rectXComparator = new RectXComparator();
- public Level(int width, int height, int yPos, LevelSet holder) {
+ public Level(final int width, final int height, final int yPos, final LevelSet holder) {
this.width = width;
this.height = height;
this.yPos = yPos;
@@ -80,7 +80,7 @@ public class Level {
in the RectanglePacker and allocation from the free list. More
disruptive changes like compaction of the level must be
requested explicitly. */
- public boolean add(Rect rect) {
+ public boolean add(final Rect rect) {
if (rect.h() > height) {
// See whether it's worth trying to expand vertically
if (nextAddX + rect.w() > width) {
@@ -108,8 +108,8 @@ public class Level {
// See whether we can add from the free list
if (freeList != null) {
Rect candidate = null;
- for (Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
- Rect cur = iter.next();
+ for (final Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
+ final Rect cur = iter.next();
if (cur.canContain(rect)) {
candidate = cur;
break;
@@ -139,7 +139,7 @@ public class Level {
}
/** Removes the given Rect from this Level. */
- public boolean remove(Rect rect) {
+ public boolean remove(final Rect rect) {
if (!rects.remove(rect))
return false;
@@ -165,14 +165,14 @@ public class Level {
/** Indicates whether this Level could satisfy an allocation request
if it were compacted. */
- public boolean couldAllocateIfCompacted(Rect rect) {
+ public boolean couldAllocateIfCompacted(final Rect rect) {
if (rect.h() > height)
return false;
if (freeList == null)
return false;
int freeListWidth = 0;
- for (Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
- Rect cur = iter.next();
+ for (final Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
+ final Rect cur = iter.next();
freeListWidth += cur.w();
}
// Add on the remaining space at the end
@@ -180,12 +180,12 @@ public class Level {
return (freeListWidth >= rect.w());
}
- public void compact(Object backingStore, BackingStoreManager manager) {
+ public void compact(final Object backingStore, final BackingStoreManager manager) {
Collections.sort(rects, rectXComparator);
int nextCompactionDest = 0;
manager.beginMovement(backingStore, backingStore);
- for (Iterator<Rect> iter = rects.iterator(); iter.hasNext(); ) {
- Rect cur = iter.next();
+ for (final Iterator<Rect> iter = rects.iterator(); iter.hasNext(); ) {
+ final Rect cur = iter.next();
if (cur.x() != nextCompactionDest) {
manager.move(backingStore, cur,
backingStore, new Rect(nextCompactionDest, cur.y(), cur.w(), cur.h(), null));
@@ -203,9 +203,9 @@ public class Level {
}
/** Visits all Rects contained in this Level. */
- public void visit(RectVisitor visitor) {
- for (Iterator<Rect> iter = rects.iterator(); iter.hasNext(); ) {
- Rect rect = iter.next();
+ public void visit(final RectVisitor visitor) {
+ for (final Iterator<Rect> iter = rects.iterator(); iter.hasNext(); ) {
+ final Rect rect = iter.next();
visitor.visit(rect);
}
}
@@ -216,8 +216,8 @@ public class Level {
original Rects. */
public void updateRectangleReferences() {
for (int i = 0; i < rects.size(); i++) {
- Rect cur = rects.get(i);
- Rect next = cur.getNextLocation();
+ final Rect cur = rects.get(i);
+ final Rect next = cur.getNextLocation();
next.setPosition(cur.x(), cur.y());
if (cur.w() != next.w() || cur.h() != next.h())
throw new RuntimeException("Unexpected disparity in rectangle sizes during updateRectangleReferences");
@@ -235,8 +235,8 @@ public class Level {
Collections.sort(freeList, rectXComparator);
int i = 0;
while (i < freeList.size() - 1) {
- Rect r1 = freeList.get(i);
- Rect r2 = freeList.get(i+1);
+ final Rect r1 = freeList.get(i);
+ final Rect r2 = freeList.get(i+1);
if (r1.maxX() + 1 == r2.x()) {
// Coalesce r1 and r2 into one block
freeList.remove(i+1);
@@ -246,7 +246,7 @@ public class Level {
}
}
// See whether the last block bumps up against the addition point
- Rect last = freeList.get(freeList.size() - 1);
+ final Rect last = freeList.get(freeList.size() - 1);
if (last.maxX() + 1 == nextAddX) {
nextAddX -= last.w();
freeList.remove(freeList.size() - 1);
@@ -262,8 +262,8 @@ public class Level {
public void dumpFreeSpace() {
int freeListWidth = 0;
- for (Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
- Rect cur = iter.next();
+ for (final Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
+ final Rect cur = iter.next();
System.err.println(" Free rectangle at " + cur);
freeListWidth += cur.w();
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java
index 433421f1a..803ca28cf 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java
@@ -47,14 +47,14 @@ import java.util.*;
public class LevelSet {
// Maintained in sorted order by increasing Y coordinate
- private List<Level> levels = new ArrayList<Level>();
+ private final List<Level> levels = new ArrayList<Level>();
private int nextAddY;
- private int w;
+ private final int w;
private int h;
/** A LevelSet manages all of the backing store for a region of a
specified width and height. */
- public LevelSet(int w, int h) {
+ public LevelSet(final int w, final int h) {
this.w = w;
this.h = h;
}
@@ -66,14 +66,14 @@ public class LevelSet {
the LevelSet given its current dimensions, false if not. Caller
is responsible for performing compaction, expansion, etc. as a
consequence. */
- public boolean add(Rect rect) {
+ public boolean add(final Rect rect) {
if (rect.w() > w)
return false;
// Go in reverse order through the levels seeing whether we can
// trivially satisfy the allocation request
for (int i = levels.size() - 1; i >= 0; --i) {
- Level level = levels.get(i);
+ final Level level = levels.get(i);
if (level.add(rect))
return true;
}
@@ -82,7 +82,7 @@ public class LevelSet {
// increases the computational complexity of the addition process,
// but prevents us from expanding unnecessarily.
for (int i = levels.size() - 1; i >= 0; --i) {
- Level level = levels.get(i);
+ final Level level = levels.get(i);
if (level.couldAllocateIfCompacted(rect))
return false;
}
@@ -92,19 +92,19 @@ public class LevelSet {
if (nextAddY + rect.h() > h)
return false;
- Level newLevel = new Level(w, rect.h(), nextAddY, this);
+ final Level newLevel = new Level(w, rect.h(), nextAddY, this);
levels.add(newLevel);
nextAddY += rect.h();
- boolean res = newLevel.add(rect);
+ final boolean res = newLevel.add(rect);
if (!res)
throw new RuntimeException("Unexpected failure in addition to new Level");
return true;
}
/** Removes the given Rect from this LevelSet. */
- public boolean remove(Rect rect) {
+ public boolean remove(final Rect rect) {
for (int i = levels.size() - 1; i >= 0; --i) {
- Level level = levels.get(i);
+ final Level level = levels.get(i);
if (level.remove(rect))
return true;
}
@@ -116,14 +116,14 @@ public class LevelSet {
if necessary. This is the correct fallback path to {@link
#add(Rect)} above. Returns true if allocated successfully, false
otherwise (indicating the need to expand the backing store). */
- public boolean compactAndAdd(Rect rect,
- Object backingStore,
- BackingStoreManager manager) {
+ public boolean compactAndAdd(final Rect rect,
+ final Object backingStore,
+ final BackingStoreManager manager) {
for (int i = levels.size() - 1; i >= 0; --i) {
- Level level = levels.get(i);
+ final Level level = levels.get(i);
if (level.couldAllocateIfCompacted(rect)) {
level.compact(backingStore, manager);
- boolean res = level.add(rect);
+ final boolean res = level.add(rect);
if (!res)
throw new RuntimeException("Unexpected failure to add after compaction");
return true;
@@ -136,7 +136,7 @@ public class LevelSet {
/** Indicates whether it's legal to trivially increase the height of
the given Level. This is only possible if it's the last Level
added and there's enough room in the backing store. */
- public boolean canExpand(Level level, int height) {
+ public boolean canExpand(final Level level, final int height) {
if (levels.isEmpty())
return false; // Should not happen
if (levels.get(levels.size() - 1) == level &&
@@ -145,7 +145,7 @@ public class LevelSet {
return false;
}
- public void expand(Level level, int oldHeight, int newHeight) {
+ public void expand(final Level level, final int oldHeight, final int newHeight) {
nextAddY += (newHeight - oldHeight);
}
@@ -156,7 +156,7 @@ public class LevelSet {
/** Sets the height of this LevelSet. It is only legal to reduce the
height to greater than or equal to the currently used height. */
- public void setHeight(int height) throws IllegalArgumentException {
+ public void setHeight(final int height) throws IllegalArgumentException {
if (height < getUsedHeight()) {
throw new IllegalArgumentException("May not reduce height below currently used height");
}
@@ -170,11 +170,11 @@ public class LevelSet {
it may be profitable to perform a compaction. */
public float verticalFragmentationRatio() {
int freeHeight = 0;
- int usedHeight = getUsedHeight();
+ final int usedHeight = getUsedHeight();
if (usedHeight == 0)
return 0.0f;
- for (Iterator<Level> iter = iterator(); iter.hasNext(); ) {
- Level level = iter.next();
+ for (final Iterator<Level> iter = iterator(); iter.hasNext(); ) {
+ final Level level = iter.next();
if (level.isEmpty()) {
freeHeight += level.h();
}
@@ -187,9 +187,9 @@ public class LevelSet {
}
/** Visits all Rects contained in this LevelSet. */
- public void visit(RectVisitor visitor) {
- for (Iterator<Level> iter = levels.iterator(); iter.hasNext(); ) {
- Level level = iter.next();
+ public void visit(final RectVisitor visitor) {
+ for (final Iterator<Level> iter = levels.iterator(); iter.hasNext(); ) {
+ final Level level = iter.next();
level.visit(visitor);
}
}
@@ -199,8 +199,8 @@ public class LevelSet {
update the new Rects in a newly laid-out LevelSet with the
original Rects. */
public void updateRectangleReferences() {
- for (Iterator<Level> iter = levels.iterator(); iter.hasNext(); ) {
- Level level = iter.next();
+ for (final Iterator<Level> iter = levels.iterator(); iter.hasNext(); ) {
+ final Level level = iter.next();
level.updateRectangleReferences();
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java
index 89f594230..cbf6b933c 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java
@@ -77,11 +77,11 @@ public class Rect {
this(null);
}
- public Rect(Object userData) {
+ public Rect(final Object userData) {
this(0, 0, 0, 0, userData);
}
- public Rect(int x, int y, int w, int h, Object userData) {
+ public Rect(final int x, final int y, final int w, final int h, final Object userData) {
setPosition(x, y);
setSize(w, h);
setUserData(userData);
@@ -94,7 +94,7 @@ public class Rect {
public Object getUserData() { return userData; }
public Rect getNextLocation() { return nextLocation; }
- public void setPosition(int x, int y) {
+ public void setPosition(final int x, final int y) {
if (x < 0)
throw new IllegalArgumentException("Negative x");
if (y < 0)
@@ -103,7 +103,7 @@ public class Rect {
this.y = y;
}
- public void setSize(int w, int h) throws IllegalArgumentException {
+ public void setSize(final int w, final int h) throws IllegalArgumentException {
if (w < 0)
throw new IllegalArgumentException("Negative width");
if (h < 0)
@@ -112,8 +112,8 @@ public class Rect {
this.h = h;
}
- public void setUserData(Object obj) { userData = obj; }
- public void setNextLocation(Rect nextLocation) { this.nextLocation = nextLocation; }
+ public void setUserData(final Object obj) { userData = obj; }
+ public void setNextLocation(final Rect nextLocation) { this.nextLocation = nextLocation; }
// Helpers for computations.
@@ -139,7 +139,7 @@ public class Rect {
return y() + h() - 1;
}
- public boolean canContain(Rect other) {
+ public boolean canContain(final Rect other) {
return (w() >= other.w() &&
h() >= other.h());
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java
index 44faa44b0..65f59ba53 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java
@@ -48,34 +48,34 @@ import java.util.*;
backing store, when necessary. */
public class RectanglePacker {
- private BackingStoreManager manager;
+ private final BackingStoreManager manager;
private Object backingStore;
private LevelSet levels;
- private float EXPANSION_FACTOR = 0.5f;
- private float SHRINK_FACTOR = 0.3f;
+ private final float EXPANSION_FACTOR = 0.5f;
+ private final float SHRINK_FACTOR = 0.3f;
- private int initialWidth;
- private int initialHeight;
+ private final int initialWidth;
+ private final int initialHeight;
private int maxWidth = -1;
private int maxHeight = -1;
static class RectHComparator implements Comparator<Rect> {
@Override
- public int compare(Rect r1, Rect r2) {
+ public int compare(final Rect r1, final Rect r2) {
return r2.h() - r1.h();
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
return this == obj;
}
}
private static final Comparator<Rect> rectHComparator = new RectHComparator();
- public RectanglePacker(BackingStoreManager manager,
- int initialWidth,
- int initialHeight) {
+ public RectanglePacker(final BackingStoreManager manager,
+ final int initialWidth,
+ final int initialHeight) {
this.manager = manager;
levels = new LevelSet(initialWidth, initialHeight);
this.initialWidth = initialWidth;
@@ -95,7 +95,7 @@ public class RectanglePacker {
necessary. Setting up a maximum width and height introduces the
possibility that additions will fail; these are handled with the
BackingStoreManager's allocationFailed notification. */
- public void setMaxSize(int maxWidth, int maxHeight) {
+ public void setMaxSize(final int maxWidth, final int maxHeight) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
}
@@ -107,7 +107,7 @@ public class RectanglePacker {
BackingStoreManager#preExpand BackingStoreManager.preExpand}
does not clear enough space for the incoming rectangle, then
this method will throw a RuntimeException. */
- public void add(Rect rect) throws RuntimeException {
+ public void add(final Rect rect) throws RuntimeException {
// Allocate backing store if we don't have any yet
if (backingStore == null)
backingStore = manager.allocateBackingStore(levels.w(), levels.h());
@@ -143,12 +143,12 @@ public class RectanglePacker {
}
/** Removes the given rectangle from this RectanglePacker. */
- public void remove(Rect rect) {
+ public void remove(final Rect rect) {
levels.remove(rect);
}
/** Visits all Rects contained in this RectanglePacker. */
- public void visit(RectVisitor visitor) {
+ public void visit(final RectVisitor visitor) {
levels.visit(visitor);
}
@@ -168,7 +168,7 @@ public class RectanglePacker {
}
// The "cause" rect may be null
- private void compactImpl(Rect cause) {
+ private void compactImpl(final Rect cause) {
// Have to either expand, compact or both. Need to figure out what
// direction to go. Prefer to expand vertically. Expand
// horizontally only if rectangle being added is too wide. FIXME:
@@ -205,12 +205,12 @@ public class RectanglePacker {
nextLevelSet = new LevelSet(newWidth, newHeight);
// Make copies of all existing rectangles
- List<Rect> newRects = new ArrayList<Rect>();
- for (Iterator<Level> i1 = levels.iterator(); i1.hasNext(); ) {
- Level level = i1.next();
- for (Iterator<Rect> i2 = level.iterator(); i2.hasNext(); ) {
- Rect cur = i2.next();
- Rect newRect = new Rect(0, 0, cur.w(), cur.h(), null);
+ final List<Rect> newRects = new ArrayList<Rect>();
+ for (final Iterator<Level> i1 = levels.iterator(); i1.hasNext(); ) {
+ final Level level = i1.next();
+ for (final Iterator<Rect> i2 = level.iterator(); i2.hasNext(); ) {
+ final Rect cur = i2.next();
+ final Rect newRect = new Rect(0, 0, cur.w(), cur.h(), null);
cur.setNextLocation(newRect);
// Hook up the reverse mapping too for easier replacement
newRect.setNextLocation(cur);
@@ -222,7 +222,7 @@ public class RectanglePacker {
Collections.sort(newRects, rectHComparator);
// Try putting all of these rectangles into the new level set
done = true;
- for (Iterator<Rect> iter = newRects.iterator(); iter.hasNext(); ) {
+ for (final Iterator<Rect> iter = newRects.iterator(); iter.hasNext(); ) {
if (!nextLevelSet.add(iter.next())) {
done = false;
break;
@@ -268,13 +268,13 @@ public class RectanglePacker {
// new locations of rectangles on the backing store. Allocate a
// new backing store, move the contents over and deallocate the
// old one.
- Object newBackingStore = manager.allocateBackingStore(nextLevelSet.w(),
+ final Object newBackingStore = manager.allocateBackingStore(nextLevelSet.w(),
nextLevelSet.h());
manager.beginMovement(backingStore, newBackingStore);
- for (Iterator<Level> i1 = levels.iterator(); i1.hasNext(); ) {
- Level level = i1.next();
- for (Iterator<Rect> i2 = level.iterator(); i2.hasNext(); ) {
- Rect cur = i2.next();
+ for (final Iterator<Level> i1 = levels.iterator(); i1.hasNext(); ) {
+ final Level level = i1.next();
+ for (final Iterator<Rect> i2 = level.iterator(); i2.hasNext(); ) {
+ final Rect cur = i2.next();
manager.move(backingStore, cur,
newBackingStore, cur.getNextLocation());
}