MASON-INTEREST-L Archives

July 2013

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show HTML Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Tue, 9 Jul 2013 03:28:07 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (99 lines)
These are pretty specific functions, and I'd prefer to generalize them.  For example, what would the equivalent be for ObjectGrid2D?  What happens when you pass in null?

[Also: though good Java compilers will optimize this anyway, you should do things like this:]

	for int x = 0 to width
		int[] fieldx = field[x]
		for int y = 0 to length
			if fieldx[y] == from
				fieldx[y] = to

Sean

On Jul 8, 2013, at 10:39 PM, Joey Harrison wrote:

> I just whipped these up:
> 
>     
>     /**
>      * Replace instances of one value to another.
>      * @param from any element that matches this value will be replaced
>      * @param to with this value
>      */
>     public void replace(int from, int to) 
>     	{
>     	for (int x = 0; x < width; x++)
>     		for (int y = 0; y < height; y++)
>     			if (field[x][y] == from)
>     				field[x][y] = to;
>     	}
> 
> ---
> 
>     /**
>      * Replace instances of one value to another.
>      * @param from any element that matches this value will be replaced
>      * @param to with this value
>      */
>     public void replace(double from, double to) 
>     	{
>     	for (int x = 0; x < width; x++)
>     		for (int y = 0; y < height; y++)
>     			if (field[x][y] == from)
>     				field[x][y] = to;
>     	}
> 
> With Sean's permission, I'll check them in.
> 
> Joey
> 
> On Mon, Jul 8, 2013 at 10:38 PM, Joey Harrison <[log in to unmask]> wrote:
> I just whipped these up:
> 
>     
>     /**
>      * Replace instances of one value to another.
>      * @param from any element that matches this value will be replaced
>      * @param to with this value
>      */
>     public void replace(int from, int to) 
>     	{
>     	for (int x = 0; x < width; x++)
>     		for (int y = 0; y < height; y++)
>     			if (field[x][y] == from)
>     				field[x][y] = to;
>     	}
> 
> ---
> 
>     /**
>      * Replace instances of one value to another.
>      * @param from any element that matches this value will be replaced
>      * @param to with this value
>      */
>     public void replace(double from, double to) 
>     	{
>     	for (int x = 0; x < width; x++)
>     		for (int y = 0; y < height; y++)
>     			if (field[x][y] == from)
>     				field[x][y] = to;
>     	}
> 
> With Sean's permission, I'll check them in.
> 
> Joey
> 
> On Mon, Jul 8, 2013 at 8:46 PM, Mark Coletti <[log in to unmask]> wrote:
> I'd like, as a convenience, for these member functions:
> 
> IntGrid2D.replace(int from, int to); // change all values of 'from' to 'to'
> DoubleGrid2D.replace(double from, double to);
> 
> (I'd do it myself, but this is outside GeoMason's bailiwick.)
> 
> -- 
> [log in to unmask]
> 
> 
> 

ATOM RSS1 RSS2