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 hermetyzacja #58

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea/
/target/
41 changes: 41 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,41 @@
package edu.kis.vh.nursery;

public class DefaultCountingOutRhymer {

public static final int EMPTY = -1;
public static final int CAPACITY = 12;
public static final int FULL = CAPACITY-1;
private final int[] numbers = new int[CAPACITY];

public int getTotal() {
return total;
}

private int total = -1;

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

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

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

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

public int countOut() {
if (callCheck())
return EMPTY;
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 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;
}
}
11 changes: 6 additions & 5 deletions src/main/java/edu/kis/vh/nursery/HanoiRhymer.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package edu.kis.vh.nursery;

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

int totalRejected = 0;
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 {
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
15 changes: 15 additions & 0 deletions src/main/java/edu/kis/vh/nursery/factory/RhymersFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +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();

}
15 changes: 0 additions & 15 deletions src/main/java/edu/kis/vh/nursery/factory/Rhymersfactory.java

This file was deleted.

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

public class IntLinkedList {

public static final int EMPTY = -1;
Node last;
int i;

Expand All @@ -10,7 +11,7 @@ public void push(int i) {
last = new Node(i);
else {
last.next = new Node(i);
last.next.prev = last;
last.next.setPrev(last);
last = last.next;
}
}
Expand All @@ -25,15 +26,17 @@ public boolean isFull() {

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

}

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

return ret;
}

Expand Down
24 changes: 21 additions & 3 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,29 @@

public class Node {

public int value;
public Node prev, next;

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


public Node(int i) {
value = 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;
}
}
10 changes: 4 additions & 6 deletions src/test/java/edu/kis/vh/nursery/RhymersDemo.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
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;
import edu.kis.vh.nursery.factory.RhymersFactory;

class RhymersDemo {

public static void main(String[] args) {
Rhymersfactory factory = new DefaultRhymersFactory();
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