style: format Java code with google-java-format
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package ru.project.collection;
|
||||
|
||||
import java.util.Arrays;
|
||||
public class MyLinkedList<T> implements MyList<T>
|
||||
{
|
||||
|
||||
public class MyLinkedList<T> implements MyList<T> {
|
||||
private Node<T> head;
|
||||
private int size;
|
||||
|
||||
public void add(T value) {
|
||||
if (head == null) {
|
||||
this.head = new Node<>(value);
|
||||
@@ -15,53 +18,45 @@ public class MyLinkedList<T> implements MyList<T>
|
||||
}
|
||||
size++;
|
||||
}
|
||||
public T get(int index)
|
||||
{
|
||||
|
||||
public T get(int index) {
|
||||
int currentIndex = 0;
|
||||
Node<T> temp = head;
|
||||
while(temp != null)
|
||||
{
|
||||
if (currentIndex == index)
|
||||
{
|
||||
while (temp != null) {
|
||||
if (currentIndex == index) {
|
||||
return temp.getValue();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
temp = temp.getNext();
|
||||
currentIndex++;
|
||||
}
|
||||
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
public void remove(int index)
|
||||
{
|
||||
|
||||
public void remove(int index) {
|
||||
if (index < 0 || index >= size) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
if (index == 0)
|
||||
{
|
||||
if (index == 0) {
|
||||
head = head.getNext();
|
||||
size--;
|
||||
return;
|
||||
|
||||
}
|
||||
int currentIndex = 0;
|
||||
Node<T> temp = head;
|
||||
while (temp != null)
|
||||
{
|
||||
if (currentIndex == index-1)
|
||||
{
|
||||
while (temp != null) {
|
||||
if (currentIndex == index - 1) {
|
||||
temp.setNext(temp.getNext().getNext());
|
||||
size--;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
temp = temp.getNext();
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T set(int index, T value) {
|
||||
if (index < 0 || index >= size) {
|
||||
throw new IllegalArgumentException();
|
||||
@@ -76,13 +71,15 @@ public class MyLinkedList<T> implements MyList<T>
|
||||
temp.setValue(value);
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
public boolean isEmpty()
|
||||
{
|
||||
|
||||
public boolean isEmpty() {
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
Object[] res = new Object[size];
|
||||
|
||||
@@ -36,11 +36,16 @@ public class Student {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Student{" +
|
||||
"groupNumber='" + groupNumber + '\'' +
|
||||
", averageGrade=" + averageGrade +
|
||||
", recordBookNumber='" + recordBookNumber + '\'' +
|
||||
'}';
|
||||
return "Student{"
|
||||
+ "groupNumber='"
|
||||
+ groupNumber
|
||||
+ '\''
|
||||
+ ", averageGrade="
|
||||
+ averageGrade
|
||||
+ ", recordBookNumber='"
|
||||
+ recordBookNumber
|
||||
+ '\''
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user