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