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

Change Vector to ArrayList #74

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
86 changes: 54 additions & 32 deletions src/controlP5/ControllerList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package controlP5;

/**
* controlP5 is a processing gui library.
*
Expand All @@ -22,76 +20,100 @@
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/

package controlP5;

import java.util.List;
import java.util.Vector;
import java.util.ArrayList;
import java.util.RandomAccess;

/**
* Stores objects of type ControllerInterface and CDrawable, mainly for internal use.
*/
public class ControllerList {

protected List< ControllerInterface< ? >> controllers;
public class ControllerList implements RandomAccess {
protected final List< ControllerInterface< ? > > controllers = new ArrayList< >( );
protected final List< CDrawable > drawables = new ArrayList< >( );

protected List< CDrawable > drawables;
public ControllerList add( final ControllerInterface< ? extends ControllerInterface< ? > > theController ) {
if ( !contains( theController ) ) synchronized ( controllers ) {
controllers.add( theController );
}
return this;
}

public ControllerList( ) {
controllers = new Vector< ControllerInterface< ? >>( );
drawables = new Vector< CDrawable >( );
public ControllerList addDrawable( final CDrawable theController ) {
if ( !containsDrawable( theController ) ) synchronized ( drawables ) {
drawables.add( theController );
}
return this;
}

public void add( ControllerInterface< ? > theController ) {
if ( controllers.indexOf( theController ) < 0 ) {
controllers.add( theController );
public ControllerList remove( final ControllerInterface< ? extends ControllerInterface< ? > > theController ) {
if ( !isEmpty( ) ) synchronized ( controllers ) {
controllers.remove( theController );
}
return this;
}

protected void remove( ControllerInterface< ? > theController ) {
controllers.remove( theController );
public ControllerList removeDrawable( final CDrawable theController ) {
if ( !isEmptyDrawable( ) ) synchronized ( drawables ) {
drawables.remove( theController );
}
return this;
}

protected void addDrawable( CDrawable theController ) {
if ( drawables.indexOf( theController ) < 0 ) {
drawables.add( theController );
public ControllerList clear( ) {
if ( !isEmpty( ) ) synchronized ( controllers ) {
controllers.clear( );
}
return this;
}

protected void removeDrawable( CDrawable theController ) {
drawables.remove( theController );
public ControllerList clearDrawable( ) {
if ( !isEmptyDrawable( ) ) synchronized ( drawables ) {
drawables.clear( );
}
return this;
}

public ControllerInterface< ? > get( int theIndex ) {
public ControllerInterface< ? extends ControllerInterface< ? > > get( final int theIndex ) {
return controllers.get( theIndex );
}

public List< ControllerInterface< ? >> get( ) {
public List< ControllerInterface< ? > > get( ) {
return controllers;
}

public CDrawable getDrawable( int theIndex ) {
public CDrawable getDrawable( final int theIndex ) {
return drawables.get( theIndex );
}

public List< CDrawable > getDrawables( ) {
return drawables;
}

public int sizeDrawable( ) {
return drawables.size( );
public boolean contains( final ControllerInterface< ? extends ControllerInterface< ? > > theController ) {
return controllers.contains( theController );
}

public int size( ) {
return controllers.size( );
public boolean containsDrawable( final CDrawable theController ) {
return drawables.contains( theController );
}

protected void clear( ) {
controllers.clear( );
public boolean isEmpty( ) {
return controllers.isEmpty( );
}

protected void clearDrawable( ) {
drawables.clear( );
public boolean isEmptyDrawable( ) {
return drawables.isEmpty( );
}

public int size( ) {
return controllers.size( );
}

public int sizeDrawable( ) {
return drawables.size( );
}
}