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

Accessory i hermetyzacja(viachaslau) #79

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin/
/target/
/.idea/
*.class
50 changes: 50 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,50 @@
package edu.kis.vh.nursery;

public class DefaultCountingOutRhymer {
public static final int ARRAY_S = 12;
public static final int DEFAULT_NEGATIVE_VALUE = -1;
public static final int ARRAY_S_PLUS_DEFAULT_NEGATIVE_VALUE = 11;
private int[] numbers = new int[ARRAY_S];

public static int getArraySize() {
return ARRAY_SIZE;
}

public static int getDefaultNegativeValue() {
return DEFAULT_NEGATIVE_VALUE;
}

public static int getArraySizePlusDefaultNegativeValue() {
return ARRAY_SIZE_PLUS_DEFAULT_NEGATIVE_VALUE;
}

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

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

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

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

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

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

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

public defaultCountingOutRhymer temp = new defaultCountingOutRhymer();
private final DefaultCountingOutRhymer temp = new DefaultCountingOutRhymer();

@Override
public int countOut() {
Expand Down
12 changes: 6 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,17 @@
package edu.kis.vh.nursery;

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

int totalRejected = 0;
private int totalRejected = 0;

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
10 changes: 5 additions & 5 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;
import edu.kis.vh.nursery.DefaultCountingOutRhymer;

public interface Rhymersfactory {

public defaultCountingOutRhymer GetStandardRhymer();
public DefaultCountingOutRhymer GetStandardRhymer();

public defaultCountingOutRhymer GetFalseRhymer();
public DefaultCountingOutRhymer GetFalseRhymer();

public defaultCountingOutRhymer GetFIFORhymer();
public DefaultCountingOutRhymer GetFIFORhymer();

public defaultCountingOutRhymer GetHanoiRhymer();
public DefaultCountingOutRhymer GetHanoiRhymer();

}
34 changes: 24 additions & 10 deletions src/main/java/edu/kis/vh/nursery/list/IntLinkedList.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package edu.kis.vh.nursery.list;

import static edu.kis.vh.nursery.DefaultCountingOutRhymer.DEFAULT_NEGATIVE_VALUE;
public class IntLinkedList {

private final int LINKED_LIST_DEFAULT_NEGATIVE_VALUE = -1;
private Node last;
private int i;
Node last;
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 @@ -25,16 +27,28 @@ public boolean isFull() {

public int top() {
if (isEmpty())
return -1;
return last.value;
return LINKED_LIST_DEFAULT_NEGATIVE_VALUE;
return last.getValue();
}

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

public int getLINKED_LIST_DEFAULT_NEGATIVE_VALUE() {
return LINKED_LIST_DEFAULT_NEGATIVE_VALUE;
}

public Node getLast() {
return last;
}


public int getI() {
return i;
}
}
25 changes: 23 additions & 2 deletions src/main/java/edu/kis/vh/nursery/list/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@

public class Node {

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

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


public int getValue() {
return 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;
}
}
4 changes: 1 addition & 3 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,7 +8,7 @@ class RhymersDemo {
public static void main(String[] args) {
Rhymersfactory factory = new DefaultRhymersFactory();

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

for (int i = 1; i < 15; i++)
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