([ConstantIndexedCollection -firstObject]): Return nil if emtpy.

([ConstantIndexedCollection -lastObject]): Likewise.
([ConstantIndexedCollection -prevObjectWithEnumState:]): Use -1 to
deal with reversals at extremes.
([ConstantIndexedCollection -nextObjectWithEnumState:]): Use [self
count] to deal with reversals at extremes.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1132 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mccallum 1996-03-13 02:34:22 +00:00
parent 3e003b0db1
commit 88cb4347f5

View file

@ -51,11 +51,15 @@
- firstObject
{
if ([self isEmpty])
return nil;
return [self objectAtIndex: 0];
}
- lastObject
{
if ([self isEmpty])
return nil;
return [self objectAtIndex: [self count]-1];
}
@ -272,15 +276,19 @@
/* If there are not objects in this collection, or we are being
asked for the object before the first object, return nil. */
if ([self isEmpty] || (*(int*)enumState) == 0)
return NO_OBJECT;
if ([self isEmpty] || ((*(int*)enumState) == 0)
|| ((*(int*)enumState) == -1))
{
(*(int*)enumState) == -1;
return NO_OBJECT;
}
if (*(int*)enumState == -2)
/* enumState was just initialized by -newEnumState, start
at the end of the sequence. */
*(int*)enumState = [self count]-1;
else
/* ...otherwise go to the previous index.*/
/* ...otherwise go the previous index. */
(*(int*)enumState)--;
return [self objectAtIndex:(*(unsigned*)enumState)];
@ -325,8 +333,11 @@
/* If there are not objects in this collection, or we are being
asked for the object after the last object, return nil. */
if ([self isEmpty] || (*(int*)enumState) > [self count]-1)
return NO_OBJECT;
if ([self isEmpty] || ((*(int*)enumState) >= (int)([self count]-1)))
{
(*(int*)enumState) = [self count];
return NO_OBJECT;
}
if (*(int*)enumState == -2)
/* enumState was just initialized by -newEnumState, start