Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mem-patch #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/
/.classpath
/.project
4 changes: 2 additions & 2 deletions demos/prefuse/demos/Congress.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ public Renderer getRenderer(VisualItem item) {

// set up the actions
AxisLayout xaxis = new AxisLayout(group, "State Code",
Constants.X_AXIS, VisiblePredicate.TRUE);
Constants.X_AXIS, VisiblePredicate.getTruePredicate());
AxisLayout yaxis = new AxisLayout(group, RECEIPTS,
Constants.Y_AXIS, VisiblePredicate.TRUE);
Constants.Y_AXIS, VisiblePredicate.getTruePredicate());
//yaxis.setScale(Constants.LOG_SCALE);
yaxis.setRangeModel(receiptsQ.getModel());
receiptsQ.getNumberModel().setValueRange(0,65000000,0,65000000);
Expand Down
4 changes: 2 additions & 2 deletions demos/prefuse/demos/ScatterPlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public ScatterPlot(Table t, String xfield, String yfield, String sfield) {

// set up the actions
AxisLayout x_axis = new AxisLayout(group, xfield,
Constants.X_AXIS, VisiblePredicate.TRUE);
Constants.X_AXIS, VisiblePredicate.getTruePredicate());
m_vis.putAction("x", x_axis);

AxisLayout y_axis = new AxisLayout(group, yfield,
Constants.Y_AXIS, VisiblePredicate.TRUE);
Constants.Y_AXIS, VisiblePredicate.getTruePredicate());
m_vis.putAction("y", y_axis);

ColorAction color = new ColorAction(group,
Expand Down
4 changes: 2 additions & 2 deletions src/prefuse/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ public void setPredicate(String expr) {
*/
public synchronized void setPredicate(Predicate p) {
if ( p == null ) {
m_predicate.set(VisiblePredicate.TRUE);
m_predicate.set(VisiblePredicate.getTruePredicate());
} else {
m_predicate.set(new Predicate[] {p, VisiblePredicate.TRUE});
m_predicate.set(new Predicate[] {p, VisiblePredicate.getTruePredicate()});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/prefuse/Visualization.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ public void invalidateAll() {
* @return an iterator over all visible items.
*/
public Iterator visibleItems() {
return items(VisiblePredicate.TRUE);
return items(VisiblePredicate.getTruePredicate());
}

/**
Expand All @@ -945,7 +945,7 @@ public Iterator visibleItems() {
* @return an iterator over all visible items in the specified group
*/
public Iterator visibleItems(String group) {
return items(group, VisiblePredicate.TRUE);
return items(group, VisiblePredicate.getTruePredicate());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/prefuse/action/ItemAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ItemAction(String group, Predicate filter) {
* @param group the name of the group to process
*/
public ItemAction(Visualization vis, String group) {
this(vis, group, VisiblePredicate.TRUE);
this(vis, group, VisiblePredicate.getTruePredicate());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/prefuse/action/filter/VisibilityFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public VisibilityFilter(Visualization vis, String group, Predicate p) {
*/
protected void setPredicate(Predicate p) {
m_predicate = p;
m_filter = new OrPredicate(p, VisiblePredicate.TRUE);
m_filter = new OrPredicate(p, VisiblePredicate.getTruePredicate());
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/prefuse/util/display/RenderingQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RenderingQueue {
// buffer queues for use in sorting, these prevent continual re-allocation
transient static VisualItem[] items_buf;
transient static int[] scores_buf;

/**
* Clear both rendering and picking queues.
*/
Expand Down Expand Up @@ -122,6 +122,9 @@ private void sort(VisualItem[] items, int[] scores, int size) {
}
// now sort
ArrayLib.sort(scores, items, scores_buf, items_buf, 0, size);

// clean up the temp buffer from object references
Arrays.fill(items_buf, null);
}

} // end of class RenderingQueue
44 changes: 33 additions & 11 deletions src/prefuse/visual/expression/VisiblePredicate.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package prefuse.visual.expression;

import java.lang.ref.WeakReference;

import prefuse.data.expression.ColumnExpression;
import prefuse.data.expression.Expression;
import prefuse.data.expression.Function;
Expand All @@ -12,15 +14,35 @@
*
* @author <a href="http://jheer.org">jeffrey heer</a>
*/
public class VisiblePredicate extends ColumnExpression
implements Predicate, Function
{

/** Convenience instance for the visible == true case. */
public static final Predicate TRUE = new VisiblePredicate();
/** Convenience instance for the visible == false case. */
public static final Predicate FALSE = new NotPredicate(TRUE);

public class VisiblePredicate extends ColumnExpression implements Predicate, Function {

private static WeakReference TRUE_REFERENCE;
private static WeakReference FALSE_REFERENCE;

public static synchronized Predicate getTruePredicate() {
if (TRUE_REFERENCE != null) {
Object item = TRUE_REFERENCE.get();
if (item instanceof Predicate) {
return (Predicate) item;
}
}
VisiblePredicate TRUE = new VisiblePredicate();
TRUE_REFERENCE = new WeakReference(TRUE);
return TRUE;
}

public static synchronized Predicate getFalsePredicate() {
if (FALSE_REFERENCE != null) {
Object item = FALSE_REFERENCE.get();
if (item instanceof Predicate) {
return (Predicate) item;
}
}
Predicate FALSE = new NotPredicate(getTruePredicate());
TRUE_REFERENCE = new WeakReference(FALSE);
return FALSE;
}

/**
* Create a new VisiblePredicate.
*/
Expand Down Expand Up @@ -48,12 +70,12 @@ public void addParameter(Expression e) {
public int getParameterCount() {
return 0;
}

/**
* @see java.lang.Object#toString()
*/
public String toString() {
return getName()+"()";
return getName() + "()";
}

} // end of class VisiblePredicate