From c978bf7337972c399d38f183b63aa2ec2a965d9a Mon Sep 17 00:00:00 2001 From: fodfodfod <94200657+fodfodfod@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:56:50 -0400 Subject: [PATCH] it works not --- fancybuild.sh | 1 + .../main/java/shuffleboardlib/Question.java | 24 ++++++++++--- .../java/shuffleboardlib/Questionnaire.java | 36 +++++++++++++------ .../java/shuffleboardlib/LibraryTest.java | 1 - 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/fancybuild.sh b/fancybuild.sh index f996ad9..cc0cc9a 100755 --- a/fancybuild.sh +++ b/fancybuild.sh @@ -1,3 +1,4 @@ ./gradlew build mv lib/build/libs/lib.jar ../2023Robot/libs/ShuffleboardLib.jar +#mv lib/build/libs/lib.jar ../SwerveDrive/libs/ShuffleboardLib.jar diff --git a/lib/src/main/java/shuffleboardlib/Question.java b/lib/src/main/java/shuffleboardlib/Question.java index 78fe44d..9344ec8 100644 --- a/lib/src/main/java/shuffleboardlib/Question.java +++ b/lib/src/main/java/shuffleboardlib/Question.java @@ -6,12 +6,24 @@ public class Question { private final String question; private final HashMap answersHashMap; + private final boolean isFinal; + private final String output; // private final SendableChooser answers; // private static ArrayList questions = new ArrayList(); - public Question(String question, HashMap answersHashMap){ + /** + * Create a question + * @param question a string for the question + * @param answersHashMap a hashmap of all of the answers + * @param isFinal is this the final question in the tree (might not actually do anything) + * @param output the string output, should always be used with isFinal + */ + public Question(String question, HashMap answersHashMap, boolean isFinal, String output){ this.question = question; this.answersHashMap = answersHashMap; + this.isFinal = isFinal; + this.output = output; + // questions.add(this); } @@ -24,10 +36,12 @@ public HashMap getAnswersHashMap(){ return answersHashMap; } - - - - + public boolean isFinal(){ + return isFinal; + } + public String getOutput(){ + return output; + } } diff --git a/lib/src/main/java/shuffleboardlib/Questionnaire.java b/lib/src/main/java/shuffleboardlib/Questionnaire.java index c157b79..abc6da8 100644 --- a/lib/src/main/java/shuffleboardlib/Questionnaire.java +++ b/lib/src/main/java/shuffleboardlib/Questionnaire.java @@ -11,14 +11,15 @@ import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Questionnaire extends SubsystemBase { - /**does not include "Shuffleboard/" */ + /** does not include "Shuffleboard/" */ private final Question rootQuestion; private final NetworkTable networkTable; // questions are switchable choosers which include the questions and the answers private final ArrayList> answerSendableChoosers = new ArrayList>(); // just the question publisher, i don't know why I have this private final ArrayList questionPublishers = new ArrayList(); - // private final ArrayList questionStringThings = new ArrayList(); + // private final ArrayList questionStringThings = new + // ArrayList(); private final int numQuestions; // a desision tree @@ -47,18 +48,16 @@ public Questionnaire(String shuffleboardPath, Question rootQuestion, int numQues // create the question publishers for (int i = 0; i < numQuestions; i++) { questionPublishers.add(networkTable.getStringTopic("Question " + i).publish()); - //this will be the actual question, it will be setup during configureQuestion + // this will be the actual question, it will be setup during configureQuestion // questionStringThings.add(""); // tab.addString(shuffleboardPath, null) - // tab.addString("Question " + i, () -> questionStringThings.get(test)).withPosition(6, i); - tab.add("Question " + i, "you should not see this").withPosition(6, i); + // tab.addString("Question " + i, () -> + // questionStringThings.get(test)).withPosition(6, i); + tab.add("Question " + i, "No Question").withPosition(6, i); } - // add the root question to the sendable choosers - // answerSendableChoosers.get(0).setDefaultOption(rootQuestion.getQuestion(), rootQuestion); - // configure the first question configureQuestion(0, rootQuestion); // configure all the questions in a loop @@ -69,6 +68,7 @@ public Questionnaire(String shuffleboardPath, Question rootQuestion, int numQues } private void configureQuestion(int questionNumber, Question question) { + //question and answer may not exist try { // add the question to the network table questionPublishers.get(questionNumber).set(question.getQuestion()); @@ -77,25 +77,39 @@ private void configureQuestion(int questionNumber, Question question) { answerSendableChoosers.get(questionNumber).setDefaultOption("NA", null); // add the answers to the sendable choosers - // try it because it might be the last question so there won't be more answers - for (String answer : question.getAnswersHashMap().keySet()) { answerSendableChoosers.get(questionNumber).addOption(answer, question.getAnswersHashMap().get(answer)); } } catch (NullPointerException e) { + // question does not exist // do nothing } } + /** + * + * @return the output of the selected option, if none is selected it returns none + */ + public String getOutput() { + for (SendableChooser question : answerSendableChoosers) { + if (question.getSelected() != null && question.getSelected().getOutput() != null){ + return question.getSelected().getOutput(); + } + } + return null; + + } + @Override public void periodic() { // configure the first question configureQuestion(0, rootQuestion); // configure all the questions in a loop for (int i = 1; i < numQuestions; i++) { - configureQuestion(i, answerSendableChoosers.get(i-1).getSelected()); + configureQuestion(i, answerSendableChoosers.get(i - 1).getSelected()); } + } } diff --git a/lib/src/test/java/shuffleboardlib/LibraryTest.java b/lib/src/test/java/shuffleboardlib/LibraryTest.java index a264a6b..3e7129d 100644 --- a/lib/src/test/java/shuffleboardlib/LibraryTest.java +++ b/lib/src/test/java/shuffleboardlib/LibraryTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import static org.junit.Assert.*; -import shuffleboardlib.Questionnaire; public class LibraryTest { @Test public void someLibraryMethodReturnsTrue() {