View Single Post
Old 01-29-2013, 03:25 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You're comparing the last event to the first event for if it should be set to null. The signature you have is also incorrect, as the original post indicates this takes the date and time.
It's simpler than this, even without the use of Arrays or collections:
PHP Code:
for (int i 0this.activities.length; ++i// don't start at 1.  numEvents also won't really be usable here.
{
    
Event e this.activities[i];
    if (
!= null)
    {
        if (
e.getDate().isEqual(date) && e.getTime().isEqual(time))
        {
            
this.activities[i] = null;
            --
this.numEvents;
            
// not sure if you want to instantiate a new event.
        
}
    }

Now, you need to decide if you want to leave a spacer within the array or not. If memory is a non-issue, than I say just leave it, BUT you will need to modify any code in which you iterate to verify it's not null prior to accessing it. So if you hit the array[4] and it has a null on it, you cannot check the value of this since it doesn't exist. Personally, I would either leave the null over adding a default event with no data within it, or I would shift the array back.

Edit:
I should mention, this works okay in my head, but it is untested. Pretty sure its as easy as that in Java :P

Edit:
Hmm, I'm wondering as well if a [do/]while loop would be better here. You'll need to add a terminating condition too, there's no reason continuing through the array if you've already verified that the item was removed (you can only have one slot of date and time).


__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php

Last edited by Fou-Lu; 01-29-2013 at 03:28 PM..
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
blahblahblah (01-29-2013)