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 and herm #44

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
78 changes: 78 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/.idea
/target/



.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
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 int getTotal() {
return total;
}

public static final int ARRAY_SIZE = 12;
public static final int TOTAL = -1;
private final int[] numbers = new int[ARRAY_SIZE];

private int total = TOTAL;


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

protected boolean callCheck() {
return total == TOTAL;
}

protected boolean isFull() {
return total == ARRAY_SIZE - 1;
}

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

protected int countOut() {
if (callCheck())
return -1;
return numbers[total--];
}

}
21 changes: 0 additions & 21 deletions src/main/java/edu/kis/vh/nursery/FIFORhymer.java

This file was deleted.

21 changes: 21 additions & 0 deletions src/main/java/edu/kis/vh/nursery/FifoRhymer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.kis.vh.nursery;

public class FifoRhymer extends DefaultCountingOutRhymer {

private DefaultCountingOutRhymer temp = new DefaultCountingOutRhymer();

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

temp.countIn(super.countOut());

final int ret = temp.countOut();

while (!temp.callCheck())

countIn(temp.countOut());

return ret;
}
}
15 changes: 8 additions & 7 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() {
protected int reportRejected() {
return totalRejected;
}

public void countIn(int in) {
if (!callCheck() && in > peekaboo())
@Override
protected void countIn(int in) {
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,27 @@
package edu.kis.vh.nursery.factory;

import edu.kis.vh.nursery.defaultCountingOutRhymer;
import edu.kis.vh.nursery.FIFORhymer;
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() {
return new FIFORhymer();
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();
DefaultCountingOutRhymer getStandardRhymer();

public defaultCountingOutRhymer GetFalseRhymer();
DefaultCountingOutRhymer getFalseRhymer();

public defaultCountingOutRhymer GetFIFORhymer();
DefaultCountingOutRhymer getFIFORhymer();

public defaultCountingOutRhymer GetHanoiRhymer();
DefaultCountingOutRhymer getHanoiRhymer();

}
2 changes: 1 addition & 1 deletion src/main/java/edu/kis/vh/nursery/list/IntLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public int top() {
public int pop() {
if (isEmpty())
return -1;
int ret = last.value;
final int ret = last.value;
last = last.prev;
return ret;
}
Expand Down
34 changes: 18 additions & 16 deletions src/test/java/edu/kis/vh/nursery/RhymersDemo.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
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;

class RhymersDemo {

private static final int RHYMERS_COUNT = 15;
private static final int RHYMERS_LAST_INDEX = 3;
private static final int MAX_RANGE = 20;

public static void main(String[] args) {
Rhymersfactory factory = new DefaultRhymersFactory();
defaultCountingOutRhymer[] rhymers = { factory.GetStandardRhymer(), factory.GetFalseRhymer(),
factory.GetFIFORhymer(), factory.GetHanoiRhymer()};
for (int i = 1; i < 15; i++)
for (int j = 0; j < 3; j++)

DefaultCountingOutRhymer[] rhymers = {factory.getStandardRhymer(), factory.getFalseRhymer(),
factory.getFIFORhymer(), factory.getHanoiRhymer()};

for (int i = 1; i < RHYMERS_COUNT; i++)
for (int j = 0; j < RHYMERS_LAST_INDEX; j++)
rhymers[j].countIn(i);

java.util.Random rn = new java.util.Random();
for (int i = 1; i < 15; i++)
rhymers[3].countIn(rn.nextInt(20));
for (int i = 1; i < RHYMERS_COUNT; i++)
rhymers[RHYMERS_LAST_INDEX].countIn(rn.nextInt(MAX_RANGE));

for (int i = 0; i < rhymers.length; i++) {
while (!rhymers[i].callCheck())
System.out.print(rhymers[i].countOut() + " ");
System.out.println();
}

System.out.println("total rejected is "
+ ((HanoiRhymer) rhymers[3]).reportRejected());
+ ((HanoiRhymer) rhymers[RHYMERS_LAST_INDEX]).reportRejected());

}

}
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