Revision: 1801 Author: [email protected] Date: Wed Dec 30 15:27:33 2009 Log: @refactor
Move all questions into a specialist QuestionSet class. This will allow us to do additional error checking and data manipulation on questions. http://code.google.com/p/simal/source/detail?r=1801 Added: /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/QuestionSet.java Modified: /trunk/uk.ac.osswatch.simal.ssmm/readme.txt /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/SustainabilityRating.java /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/MultipleChoiceQuestion.java /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/Question.java /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/SelectionQuestion.java /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestMultipleChoiceQuestion.java /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestQuestion.java /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestSelectionQuestion.java ======================================= --- /dev/null +++ /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/QuestionSet.java Wed Dec 30 15:27:33 2009 @@ -0,0 +1,44 @@ +package uk.ac.osswatch.simal.ssmm.model; + +import java.util.Collection; +import java.util.LinkedHashMap; +/* + * Copyright 2008 University of Oxford + * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ + +public class QuestionSet { + private LinkedHashMap<String, Question> questions = new LinkedHashMap<String, Question>(); + + /** + * Add a new question to this set. It will be placed at the end of the current set of questions. + * + * @param id - a unique identifier for this question, usually this will be one or two words + * @param question - the full text of the question + */ + public void put(String id, Question question) { + if (questions.containsKey(id)) throw new IllegalArgumentException("Attempt to add a questoin with a duplicate identifier: " + id); + questions.put(id, question); + } + + /** + * Return a collection containing all the questions in this set. + * @return + */ + public Collection<Question> values() { + return questions.values(); + } + +} ======================================= --- /trunk/uk.ac.osswatch.simal.ssmm/readme.txt Thu Dec 10 03:46:15 2009 +++ /trunk/uk.ac.osswatch.simal.ssmm/readme.txt Wed Dec 30 15:27:33 2009 @@ -1,4 +1,4 @@ -This module provides a module for the measuring of the sustainability of open source +A module for the measuring of the sustainability of open source software by providing an evaluation mechanism. Use @@ -10,4 +10,9 @@ The application will ask you a series of questions and, upon completion, will provide a rating based on the Sustainability Maturity Model. - + +Adding more questions +===================== + + + ======================================= --- /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/SustainabilityRating.java Thu Dec 10 17:11:20 2009 +++ /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/SustainabilityRating.java Wed Dec 30 15:27:33 2009 @@ -1,4 +1,20 @@ package uk.ac.osswatch.simal.ssmm; +/* + * Copyright 2008 University of Oxford + * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ import java.util.Iterator; import java.util.LinkedHashMap; @@ -6,14 +22,15 @@ import uk.ac.osswatch.simal.ssmm.model.MultipleChoiceQuestion; import uk.ac.osswatch.simal.ssmm.model.Question; +import uk.ac.osswatch.simal.ssmm.model.QuestionSet; import uk.ac.osswatch.simal.ssmm.model.SelectionQuestion; public class SustainabilityRating { private static final Object HELP_COMMAND = "help"; - private static LinkedHashMap<String, Question> infoQuestions = new LinkedHashMap<String, Question>(); - private static LinkedHashMap<String, Question> legalQuestions = new LinkedHashMap<String, Question>(); - private static LinkedHashMap<String, Question> knowledgeQuestions = new LinkedHashMap<String, Question>(); + private static QuestionSet infoQuestions = new QuestionSet(); + private static QuestionSet legalQuestions = new QuestionSet(); + private static QuestionSet knowledgeQuestions = new QuestionSet(); /** * @param args */ @@ -85,10 +102,10 @@ /** * Ask all the questions in a set. * - * @param questions the questions to ask + * @param infoQuestions2 the questions to ask */ - private static void askAll(LinkedHashMap<String, Question> questions) { - Iterator<Question> itr = questions.values().iterator(); + private static void askAll(QuestionSet infoQuestions2) { + Iterator<Question> itr = infoQuestions2.values().iterator(); while (itr.hasNext()) { Question question = itr.next(); ask(question); @@ -97,10 +114,10 @@ /** * Report the response to all the questions in a set. - * @param questions + * @param infoQuestions2 */ - private static void reportAll(LinkedHashMap<String, Question> questions) { - Iterator<Question> itr = questions.values().iterator(); + private static void reportAll(QuestionSet infoQuestions2) { + Iterator<Question> itr = infoQuestions2.values().iterator(); while (itr.hasNext()) { Question question = itr.next(); System.out.print(question.getLabel()); @@ -111,7 +128,7 @@ /** * Ask a question and return the answer. The answer is also stored in the question - * object. + * object for later retrieval. * * @param question * @return @@ -120,14 +137,13 @@ System.out.println("\n"); printHeading(question); System.out.println(question.getText()); - String answer; if (question instanceof SelectionQuestion) { - answer = getSelectionResponse((SelectionQuestion) question); + getSelectionResponse((SelectionQuestion) question); } else if (question instanceof MultipleChoiceQuestion) { - answer = getMultiChoiceResponse((MultipleChoiceQuestion) question); + getMultiChoiceResponse((MultipleChoiceQuestion) question); } else { - answer = getFreeFormresponse(question); + getFreeFormresponse(question); } return question.getAnswer(); } ======================================= --- /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/MultipleChoiceQuestion.java Thu Dec 10 17:11:20 2009 +++ /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/MultipleChoiceQuestion.java Wed Dec 30 15:27:33 2009 @@ -1,4 +1,20 @@ package uk.ac.osswatch.simal.ssmm.model; +/* + * Copyright 2008 University of Oxford + * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ import java.util.LinkedHashMap; ======================================= --- /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/Question.java Thu Dec 10 17:11:20 2009 +++ /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/Question.java Wed Dec 30 15:27:33 2009 @@ -1,4 +1,20 @@ package uk.ac.osswatch.simal.ssmm.model; +/* + * Copyright 2008 University of Oxford + * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ /** * A base question type that allows a free text answer. ======================================= --- /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/SelectionQuestion.java Thu Dec 10 17:11:20 2009 +++ /trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/SelectionQuestion.java Wed Dec 30 15:27:33 2009 @@ -1,4 +1,20 @@ package uk.ac.osswatch.simal.ssmm.model; +/* + * Copyright 2008 University of Oxford + * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ import java.util.Iterator; import java.util.LinkedHashMap; ======================================= --- /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestMultipleChoiceQuestion.java Thu Dec 10 14:36:43 2009 +++ /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestMultipleChoiceQuestion.java Wed Dec 30 15:27:33 2009 @@ -1,4 +1,20 @@ package uk.ac.osswatch.simal.ssmm.model; +/* + * Copyright 2008 University of Oxford + * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ import static org.junit.Assert.assertEquals; ======================================= --- /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestQuestion.java Thu Dec 10 06:47:28 2009 +++ /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestQuestion.java Wed Dec 30 15:27:33 2009 @@ -1,4 +1,20 @@ package uk.ac.osswatch.simal.ssmm.model; +/* + * Copyright 2008 University of Oxford + * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ import static org.junit.Assert.assertEquals; ======================================= --- /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestSelectionQuestion.java Thu Dec 10 17:11:20 2009 +++ /trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestSelectionQuestion.java Wed Dec 30 15:27:33 2009 @@ -1,4 +1,20 @@ package uk.ac.osswatch.simal.ssmm.model; +/* + * Copyright 2008 University of Oxford + * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ import static org.junit.Assert.assertEquals; -- You received this message because you are subscribed to the Google Groups "Simal Commits" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/simal-commits?hl=en.
