@Override public T requestInstance() { T n = super.requestInstance(); used.add(n); return n; } }
/** * Either returns a recycled instance or a new one. */ public T requestInstance() { T a; if( unused.size() > 0 ) { a = unused.pop(); } else { a = createInstance(); } return a; }
/** * Removes the edge from the two nodes and recycles the data structure */ void detachEdge(SquareEdge edge) { edge.a.edges[edge.sideA] = null; edge.b.edges[edge.sideB] = null; edge.distance = 0; edges.recycleInstance(edge); }
@Test public void requestInstance_recycleInstance() { RecycleManager<Dummy> manager = new RecycleManager<Dummy>(Dummy.class); Dummy first = manager.requestInstance(); Dummy second = manager.requestInstance(); manager.recycleInstance(first); Dummy third = manager.requestInstance(); assertTrue(first==third); assertTrue(first!=second); assertEquals(0, manager.unused.size()); }
@Override public T requestInstance() { T n = super.requestInstance(); used.add(n); return n; } }
/** * Either returns a recycled instance or a new one. */ public T requestInstance() { T a; if( unused.size() > 0 ) { a = unused.pop(); } else { a = createInstance(); } return a; }
/** * Creates a new edge which will connect the two nodes. The side on each node which is connected * is specified by the indexes. * @param a First node * @param indexA side on node 'a' * @param b Second node * @param indexB side on node 'b' * @param distance distance apart the center of the two nodes */ void connect( SquareNode a , int indexA , SquareNode b , int indexB , double distance ) { SquareEdge edge = edges.requestInstance(); edge.reset(); edge.a = a; edge.sideA = indexA; edge.b = b; edge.sideB = indexB; edge.distance = distance; a.edges[indexA] = edge; b.edges[indexB] = edge; } }