Message from @Paragram Slide - AZ

Discord ID: 495329244465987623


2018-09-28 20:11:21 UTC  

get(i).equals

2018-09-28 20:11:46 UTC  

make the first && an ||

2018-09-28 20:12:45 UTC  

but I'm checking to see if they're both null

2018-09-28 20:13:03 UTC  

but the elseif

2018-09-28 20:13:15 UTC  

o could be null

2018-09-28 20:13:17 UTC  

```java
// Returns true if this list contains the specified element o.
// More formally, returns true if and only if this list contains at least one element e
// such that (o==null ? e==null : o.equals(e)).
// Note: you have to handle the case where a list node stores null data element.
```

2018-09-28 20:14:06 UTC  

if o is not null you will move to the else if

2018-09-28 20:14:14 UTC  

and get(i).data could be null

2018-09-28 20:14:28 UTC  

do this

2018-09-28 20:15:48 UTC  

Object.equals(get(i).data, o)

2018-09-28 20:15:51 UTC  

in the else if

2018-09-28 20:16:03 UTC  

handles nulls

2018-09-28 20:17:26 UTC  

says that the method is not applicable for arguments

2018-09-28 20:17:28 UTC  

Objects.equals

2018-09-28 20:17:31 UTC  

ah

2018-09-28 20:17:33 UTC  

not Object

2018-09-28 20:18:36 UTC  

I still get a null pointer exception from the if statement

2018-09-28 20:19:16 UTC  

this is what is being tested btw

2018-09-28 20:19:22 UTC  

```java
public static void testContains() { //passed test
init();
System.out.println("----------------testContains()------");
System.out.println(list0.contains(null));
System.out.println(list2.contains("1:Good"));
System.out.println(list2.contains("6:Tony"));
System.out.println(list2.contains("notexist"));
System.out.println(list2.contains(""));
System.out.println(list2.contains(null));
System.out.println(list3.contains("notexist"));
System.out.println(list3.contains(null));
drawLine();
}
```

2018-09-28 20:19:34 UTC  

that is from the tester class, not the same class

2018-09-28 20:21:34 UTC  

break when cur is null

2018-09-28 20:21:53 UTC  

it shouldn't break though

2018-09-28 20:22:05 UTC  

it should theoretically be able to find objects with data set to null

2018-09-28 20:22:39 UTC  

cur.next

2018-09-28 20:22:48 UTC  

cur is never null?

2018-09-28 20:23:02 UTC  

recursively

2018-09-28 20:23:04 UTC  

no it should be null at the last node

2018-09-28 20:24:32 UTC  

```java
// Inserts the specified element at the specified position in this list.
// Shifts the element currently at that position (if any) and any subsequent
// elements to the right (adds one to their indices).
// if(index < 0 or index > this.size), throws IndexOutOfBoundsException.

// E.g, if this list is [dummy]->["A"]->["B"]->["C"] with size = 3.
// add(0,D) will result in [dummy]->["D"]->["A"]->["B"]->["C"].
// Continuing on the previous add() call, add(1,"E") will
// change the existing list to [dummy]->["D"]->["E"]->["A"]->["B"]->["C"].
public void add(int index, Object o) {
ListNode newNode = new ListNode(o);
newNode.next = get(index);
get(index - 1).next = newNode;
this.size++;
}
```

2018-09-28 20:24:37 UTC  

maybe this method is messed up

2018-09-28 20:25:25 UTC  

no wait that one should be okay

2018-09-28 20:25:46 UTC  

```java
//Add the object e to the end of this list.
// it returns true, after e is successfully added.
public boolean add(Object e) {
ListNode newNode = new ListNode(e);
newNode.next = null;
get(this.size - 1).next = newNode;
this.size--;
return true;
}
```

2018-09-28 20:25:55 UTC  

this one might be the one with the problem

2018-09-28 20:26:56 UTC  

why --?

2018-09-28 20:27:04 UTC  

ya lol I just noticed that

2018-09-28 20:27:07 UTC  

that's definitely a mistake

2018-09-28 20:27:19 UTC  

doesn't fix the null pointer exception though

2018-09-28 20:27:35 UTC  

is there a stack trace?

2018-09-28 20:28:57 UTC  

this?

2018-09-28 20:29:02 UTC  

```java
Exception in thread "main" java.lang.NullPointerException
at MyLinkedList$ListNode.access$3(MyLinkedList.java:11)
at MyLinkedList.contains(MyLinkedList.java:59)
at MyLinkedListTester.testContains(MyLinkedListTester.java:119)
at MyLinkedListTester.main(MyLinkedListTester.java:216)

```

2018-09-28 20:32:32 UTC  

this is what I have on the contains method now

2018-09-28 20:32:38 UTC  

```java
// Returns true if this list contains the specified element o.
// More formally, returns true if and only if this list contains at least one element e
// such that (o==null ? e==null : o.equals(e)).
// Note: you have to handle the case where a list node stores null data element.
public boolean contains(Object o) {
for (int i = 0; i < size; i++) {
if (o == null && get(i).data == null) {
return true;
}
else if (Objects.equals(get(i).data, o)) {
return true;
}
}
return false;
}
```