Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accesory i hermetyzacja #59

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
545055c
1. dodanie pliku gitignore
matmirowski Apr 10, 2024
201eee6
2. Poprawa formatowania klasy HanoiRhymer
matmirowski Apr 10, 2024
882a3af
2. Dodanie pustej linii dla formatowania pliku HanoiRhymer
matmirowski Apr 10, 2024
8f29fab
3. Scalenie z galezia format
matmirowski Apr 10, 2024
0f740e1
5. poprawa konwencji nazewniczej w nazwach pol klas
matmirowski Apr 10, 2024
984cc7a
4.1 poprawa nazw klas
matmirowski Apr 10, 2024
8cf84a1
4.2 zmiana konwencji nazewniczej metod
matmirowski Apr 10, 2024
d7aa18e
5. scalenie zmian z class-method-naming
matmirowski Apr 10, 2024
6b59f65
6. zastapienie literalow stalymi
KaNiuSii May 21, 2024
66fea57
7. ustawienie final przy niemutowalnych atrybutach
KaNiuSii May 21, 2024
a588e99
8. adnotacja override
KaNiuSii May 21, 2024
cde2b59
Zmienna value w pliku Node powinna być final.
KaNiuSii May 21, 2024
ccadcdc
Zmienna temp w pliku FIFORhymer powinna być final.
KaNiuSii May 21, 2024
901df2b
Zmienna za mało mówi o swoim przeznaczeniu, można zmienić na np. MAX_…
KaNiuSii May 21, 2024
268fb2a
Niepowiazane dane.
KaNiuSii May 21, 2024
43b0731
Zmienne w peekaboo i countOut nie są ze sobą powiązane, utwórz osobne…
KaNiuSii May 21, 2024
4fe1d0d
Merge pull request #2 from matmirowski/constants
matmirowski May 21, 2024
81ad7f1
9. Zastosowanie mozliwie najmniejszej widocznosci atrybutow klas
matmirowski May 26, 2024
3cbf6c4
10. Dodanie gettera dla pola total w klasie DefaultCountingOutRhymer
matmirowski May 26, 2024
3338d82
11. Hermetyzacja nieprywatnych atrybutow
matmirowski May 26, 2024
a304bae
12. Usuniecie nieuzywanego gettera
matmirowski May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.idea/
target/
bin/
42 changes: 42 additions & 0 deletions src/main/java/edu/kis/vh/nursery/DefaultCountingOutRhymer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package edu.kis.vh.nursery;

public class DefaultCountingOutRhymer {

private static final int MAX = 11;

private static final int DEFAULT_VALUE = -1;

private static final int ERROR = -1;

private static final int MAX_SIZE = MAX + 1;

private final int[] numbers = new int[MAX_SIZE];

private int total = DEFAULT_VALUE;

public void countIn(int in) {
if (!isFull())
numbers[++total] = in;
}

public boolean callCheck() {
return total == DEFAULT_VALUE;
}

public boolean isFull() {
return total == MAX;
}

protected int peekaboo() {
if (callCheck())
return ERROR;
return numbers[total];
}

public int countOut() {
if (callCheck())
return ERROR;
return numbers[total--];
}

}
18 changes: 8 additions & 10 deletions src/main/java/edu/kis/vh/nursery/FIFORhymer.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package edu.kis.vh.nursery;

public class FIFORhymer extends defaultCountingOutRhymer {
public class FIFORhymer extends DefaultCountingOutRhymer {

private final DefaultCountingOutRhymer temp = new DefaultCountingOutRhymer();

public defaultCountingOutRhymer temp = new defaultCountingOutRhymer();

@Override
public int countOut() {
while (!callCheck())

temp.countIn(super.countOut());

temp.countIn(super.countOut());

int ret = temp.countOut();

while (!temp.callCheck())

countIn(temp.countOut());

countIn(temp.countOut());

return ret;
}
}
14 changes: 8 additions & 6 deletions src/main/java/edu/kis/vh/nursery/HanoiRhymer.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package edu.kis.vh.nursery;

public class HanoiRhymer extends defaultCountingOutRhymer {
public class HanoiRhymer extends DefaultCountingOutRhymer {

int totalRejected = 0;
private static final int START = 0;
private int totalRejected = START;

public int reportRejected() {
return totalRejected;
}


@Override
public void countIn(int in) {
if (!callCheck() && in > peekaboo())
if (!callCheck() && in > peekaboo())
totalRejected++;
else
super.countIn(in);
else
super.countIn(in);
}
}
34 changes: 0 additions & 34 deletions src/main/java/edu/kis/vh/nursery/defaultCountingOutRhymer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package edu.kis.vh.nursery.factory;

import edu.kis.vh.nursery.defaultCountingOutRhymer;
import edu.kis.vh.nursery.DefaultCountingOutRhymer;
import edu.kis.vh.nursery.FIFORhymer;
import edu.kis.vh.nursery.HanoiRhymer;
import edu.kis.vh.nursery.factory.Rhymersfactory;

public class DefaultRhymersFactory implements Rhymersfactory {

@Override
public defaultCountingOutRhymer GetStandardRhymer() {
return new defaultCountingOutRhymer();
public DefaultCountingOutRhymer getStandardRhymer() {
return new DefaultCountingOutRhymer();
}

@Override
public defaultCountingOutRhymer GetFalseRhymer() {
return new defaultCountingOutRhymer();
public DefaultCountingOutRhymer getFalseRhymer() {
return new DefaultCountingOutRhymer();
}

@Override
public defaultCountingOutRhymer GetFIFORhymer() {
public DefaultCountingOutRhymer getFIFORhymer() {
return new FIFORhymer();
}

@Override
public defaultCountingOutRhymer GetHanoiRhymer() {
public DefaultCountingOutRhymer getHanoiRhymer() {
return new HanoiRhymer();
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/edu/kis/vh/nursery/factory/Rhymersfactory.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package edu.kis.vh.nursery.factory;

import edu.kis.vh.nursery.defaultCountingOutRhymer;

public interface Rhymersfactory {
public defaultCountingOutRhymer GetStandardRhymer();
public defaultCountingOutRhymer GetFalseRhymer();
public defaultCountingOutRhymer GetFIFORhymer();
public defaultCountingOutRhymer GetHanoiRhymer();
}
import edu.kis.vh.nursery.DefaultCountingOutRhymer;

public interface Rhymersfactory {

public DefaultCountingOutRhymer getStandardRhymer();

public DefaultCountingOutRhymer getFalseRhymer();

public DefaultCountingOutRhymer getFIFORhymer();

public DefaultCountingOutRhymer getHanoiRhymer();

}
18 changes: 9 additions & 9 deletions src/main/java/edu/kis/vh/nursery/list/IntLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

public class IntLinkedList {

Node last;
int i;
private static final int ERROR = -1;
private Node last;
private int i;

public void push(int i) {
if (last == null)
last = new Node(i);
else {
last.next = new Node(i);
last.next.prev = last;
last = last.next;
last.setNext(new Node(i));
last.getNext().setPrev(last);
last = last.getNext();
}
}

Expand All @@ -26,15 +27,14 @@ public boolean isFull() {
public int top() {
if (isEmpty())
return -1;
return last.value;
return last.getValue();
}

public int pop() {
if (isEmpty())
return -1;
int ret = last.value;
last = last.prev;
int ret = last.getValue();
last = last.getPrev();
return ret;
}

}
35 changes: 29 additions & 6 deletions src/main/java/edu/kis/vh/nursery/list/Node.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
package edu.kis.vh.nursery.list;

public class Node {

public int value;
public Node prev, next;
private int value;
private Node prev;
private Node next;

public Node(int i) {
value = i;
setValue(i);
}

public int getValue() {
return value;
}

public void setValue(int value) {
this.value = value;
}

public Node getPrev() {
return prev;
}

public void setPrev(Node prev) {
this.prev = prev;
}

public Node getNext() {
return next;
}

public void setNext(Node next) {
this.next = next;
}

}
}
6 changes: 2 additions & 4 deletions src/test/java/edu/kis/vh/nursery/RhymersDemo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package edu.kis.vh.nursery;

import edu.kis.vh.nursery.defaultCountingOutRhymer;
import edu.kis.vh.nursery.HanoiRhymer;
import edu.kis.vh.nursery.factory.DefaultRhymersFactory;
import edu.kis.vh.nursery.factory.Rhymersfactory;

Expand All @@ -10,8 +8,8 @@ class RhymersDemo {
public static void main(String[] args) {
Rhymersfactory factory = new DefaultRhymersFactory();

defaultCountingOutRhymer[] rhymers = { factory.GetStandardRhymer(), factory.GetFalseRhymer(),
factory.GetFIFORhymer(), factory.GetHanoiRhymer()};
DefaultCountingOutRhymer[] rhymers = { factory.getStandardRhymer(), factory.getFalseRhymer(),
factory.getFIFORhymer(), factory.getHanoiRhymer()};

for (int i = 1; i < 15; i++)
for (int j = 0; j < 3; j++)
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/edu/kis/vh/nursery/RhymersJUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class RhymersJUnitTest {

@Test
public void testCountIn() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
int testValue = 4;
rhymer.countIn(testValue);

Expand All @@ -17,7 +17,7 @@ public void testCountIn() {

@Test
public void testCallCheck() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
boolean result = rhymer.callCheck();
Assert.assertEquals(true, result);

Expand All @@ -29,7 +29,7 @@ public void testCallCheck() {

@Test
public void testIsFull() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
final int STACK_CAPACITY = 12;
for (int i = 0; i < STACK_CAPACITY; i++) {
boolean result = rhymer.isFull();
Expand All @@ -43,7 +43,7 @@ public void testIsFull() {

@Test
public void testPeekaboo() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
final int EMPTY_STACK_VALUE = -1;

int result = rhymer.peekaboo();
Expand All @@ -60,7 +60,7 @@ public void testPeekaboo() {

@Test
public void testCountOut() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
final int EMPTY_STACK_VALUE = -1;

int result = rhymer.countOut();
Expand Down