Added model classes for database
This commit is contained in:
parent
ed2f64a431
commit
abdd6f9b7f
56
SWADroid/src/es/ugr/swad/swadroid/model/Course.java
Normal file
56
SWADroid/src/es/ugr/swad/swadroid/model/Course.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* This file is part of SWADroid.
|
||||
*
|
||||
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*
|
||||
* SWADroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWADroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with SWADroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package es.ugr.swad.swadroid.model;
|
||||
|
||||
/**
|
||||
* Class for store a course
|
||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*/
|
||||
public class Course extends Model {
|
||||
/**
|
||||
* Course name
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Course identifier
|
||||
* @param name Course name
|
||||
*/
|
||||
public Course(int id, String name) {
|
||||
super(id);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets course name
|
||||
* @return Course name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets course name
|
||||
* @param name Course name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
51
SWADroid/src/es/ugr/swad/swadroid/model/Model.java
Normal file
51
SWADroid/src/es/ugr/swad/swadroid/model/Model.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of SWADroid.
|
||||
*
|
||||
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*
|
||||
* SWADroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWADroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with SWADroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package es.ugr.swad.swadroid.model;
|
||||
|
||||
/**
|
||||
* Superclass for encapsulate common behavior of all Models.
|
||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com> *
|
||||
*/
|
||||
public class Model {
|
||||
/**
|
||||
* Model identifier
|
||||
*/
|
||||
private int id;
|
||||
|
||||
public Model(int id) {
|
||||
super();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets model identifier
|
||||
* @return Model identifier
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets model identifier
|
||||
* @param id Model identifier
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
78
SWADroid/src/es/ugr/swad/swadroid/model/Notice.java
Normal file
78
SWADroid/src/es/ugr/swad/swadroid/model/Notice.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of SWADroid.
|
||||
*
|
||||
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*
|
||||
* SWADroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWADroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with SWADroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package es.ugr.swad.swadroid.model;
|
||||
|
||||
/**
|
||||
* Class for store a notice
|
||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*/
|
||||
public class Notice extends Model {
|
||||
/**
|
||||
* Notice timestamp
|
||||
*/
|
||||
private int timestamp;
|
||||
/**
|
||||
* Notice description
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Notice identifier
|
||||
* @param timestamp Notice timestamp
|
||||
* @param description Notice description
|
||||
*/
|
||||
public Notice(int id, int timestamp, String description) {
|
||||
super(id);
|
||||
this.timestamp = timestamp;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets notice timestamp
|
||||
* @return Notice timestamp
|
||||
*/
|
||||
public int getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets notice timestamp
|
||||
* @param timestamp Notice timestamp
|
||||
*/
|
||||
public void setTimestamp(int timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets notice description
|
||||
* @return Notice description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets notice description
|
||||
* @param description Notice description
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
46
SWADroid/src/es/ugr/swad/swadroid/model/Pair.java
Normal file
46
SWADroid/src/es/ugr/swad/swadroid/model/Pair.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of SWADroid.
|
||||
*
|
||||
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*
|
||||
* SWADroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWADroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with SWADroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package es.ugr.swad.swadroid.model;
|
||||
|
||||
/**
|
||||
* Class for manage a pair of values
|
||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*/
|
||||
public class Pair<FIRST, SECOND> implements Comparable<Pair<FIRST, SECOND>> {
|
||||
public final FIRST first;
|
||||
public final SECOND second;
|
||||
|
||||
private Pair(FIRST first, SECOND second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public static <FIRST, SECOND> Pair<FIRST, SECOND> of(FIRST first, SECOND second) {
|
||||
return new Pair<FIRST, SECOND>(first, second);
|
||||
}
|
||||
|
||||
public int compareTo(Pair<FIRST, SECOND> o) {
|
||||
int cmp = compare(first, o.first);
|
||||
return cmp == 0 ? compare(second, o.second) : cmp;
|
||||
}
|
||||
|
||||
private static int compare(Object o1, Object o2) {
|
||||
return o1 == null ? o2 == null ? 0 : -1 : o2 == null ? +1 : ((Comparable) o1).compareTo(o2);
|
||||
}
|
||||
}
|
121
SWADroid/src/es/ugr/swad/swadroid/model/Student.java
Normal file
121
SWADroid/src/es/ugr/swad/swadroid/model/Student.java
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* This file is part of SWADroid.
|
||||
*
|
||||
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*
|
||||
* SWADroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWADroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with SWADroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package es.ugr.swad.swadroid.model;
|
||||
|
||||
/**
|
||||
* Class for store a student
|
||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*/
|
||||
public class Student extends Model {
|
||||
/**
|
||||
* Student's dni
|
||||
*/
|
||||
private String dni;
|
||||
/**
|
||||
* Student's first name
|
||||
*/
|
||||
private String firstName;
|
||||
/**
|
||||
* Student's first surname
|
||||
*/
|
||||
private String surname1;
|
||||
/**
|
||||
* Student's second surname
|
||||
*/
|
||||
private String surname2;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param dni Student's dni
|
||||
* @param firstName Student's first name
|
||||
* @param surname1 Student's first surname
|
||||
* @param surname2 Student's second surname
|
||||
*/
|
||||
public Student(int id, String dni, String firstName, String surname1,
|
||||
String surname2) {
|
||||
super(id);
|
||||
this.firstName = firstName;
|
||||
this.surname1 = surname1;
|
||||
this.surname2 = surname2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets student's dni
|
||||
* @return Student's dni
|
||||
*/
|
||||
public String getDni() {
|
||||
return dni;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets student's dni
|
||||
* @param dni Student's dni
|
||||
*/
|
||||
public void setDni(String dni) {
|
||||
this.dni = dni;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets student's first name
|
||||
* @return Student's first name
|
||||
*/
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets student's first name
|
||||
* @param Student's first name
|
||||
*/
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets student's first surname
|
||||
* @return Student's first surname
|
||||
*/
|
||||
public String getSurname1() {
|
||||
return surname1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets student's first surname
|
||||
* @param Student's first surname
|
||||
*/
|
||||
public void setSurname1(String surname1) {
|
||||
this.surname1 = surname1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets student's second surname
|
||||
* @return Student's second surname
|
||||
*/
|
||||
public String getSurname2() {
|
||||
return surname2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets student's second surname
|
||||
* @param Student's second surname
|
||||
*/
|
||||
public void setSurname2(String surname2) {
|
||||
this.surname2 = surname2;
|
||||
}
|
||||
}
|
78
SWADroid/src/es/ugr/swad/swadroid/model/TestAnswer.java
Normal file
78
SWADroid/src/es/ugr/swad/swadroid/model/TestAnswer.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of SWADroid.
|
||||
*
|
||||
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*
|
||||
* SWADroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWADroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with SWADroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package es.ugr.swad.swadroid.model;
|
||||
|
||||
/**
|
||||
* Class for store a test answer
|
||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*/
|
||||
public class TestAnswer extends Model {
|
||||
/**
|
||||
* Flag to know if this is the correct answer of the question
|
||||
*/
|
||||
private boolean correct;
|
||||
/**
|
||||
* Answer's text
|
||||
*/
|
||||
private String answer;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Answer id
|
||||
* @param correct Flag to know if this is the correct answer of the question
|
||||
* @param answer Answer's text
|
||||
*/
|
||||
public TestAnswer(int id, boolean correct, String answer) {
|
||||
super(id);
|
||||
this.correct = correct;
|
||||
this.answer = answer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets answer correct flag
|
||||
* @return Answer correct flag
|
||||
*/
|
||||
public boolean getCorrect() {
|
||||
return correct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets answer correct flag
|
||||
* @param Answer correct flag
|
||||
*/
|
||||
public void setCorrect(boolean correct) {
|
||||
this.correct = correct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets answer text
|
||||
* @return Answer text
|
||||
*/
|
||||
public String getAnswer() {
|
||||
return answer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets answer text
|
||||
* @param answer Answer text
|
||||
*/
|
||||
public void setAnswer(String answer) {
|
||||
this.answer = answer;
|
||||
}
|
||||
}
|
190
SWADroid/src/es/ugr/swad/swadroid/model/TestQuestion.java
Normal file
190
SWADroid/src/es/ugr/swad/swadroid/model/TestQuestion.java
Normal file
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* This file is part of SWADroid.
|
||||
*
|
||||
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*
|
||||
* SWADroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWADroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with SWADroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package es.ugr.swad.swadroid.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Clas for store a test question
|
||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*/
|
||||
public class TestQuestion extends Model {
|
||||
/**
|
||||
* Question's text
|
||||
*/
|
||||
private String question;
|
||||
/**
|
||||
* Answer type
|
||||
*/
|
||||
private String anstype;
|
||||
/**
|
||||
* Number of hits
|
||||
*/
|
||||
private int numhits;
|
||||
/**
|
||||
* Flag to shuffle answers in test
|
||||
*/
|
||||
private boolean shuffle;
|
||||
/**
|
||||
* Test score
|
||||
*/
|
||||
private float score;
|
||||
/**
|
||||
* Question's answers
|
||||
*/
|
||||
private List<TestAnswer> answers;
|
||||
|
||||
/**
|
||||
* @param id Test identifier
|
||||
* @param question Question's text
|
||||
* @param anstype Answer type
|
||||
* @param numhits Number of hits
|
||||
* @param shuffle Flag to shuffle answers in test
|
||||
* @param score Test score
|
||||
*/
|
||||
public TestQuestion(int id, String question, String anstype, int numhits,
|
||||
boolean shuffle, float score) {
|
||||
super(id);
|
||||
this.question = question;
|
||||
this.anstype = anstype;
|
||||
this.numhits = numhits;
|
||||
this.shuffle = shuffle;
|
||||
this.score = score;
|
||||
this.answers = new ArrayList<TestAnswer>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets question's text
|
||||
* @return Question's text
|
||||
*/
|
||||
public String getQuestion() {
|
||||
return question;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets question's text
|
||||
* @param question Question's text
|
||||
*/
|
||||
public void setQuestion(String question) {
|
||||
this.question = question;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets answer type
|
||||
* @return Answer type
|
||||
*/
|
||||
public String getAnstype() {
|
||||
return anstype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets answer type
|
||||
* @param anstype Answer type
|
||||
*/
|
||||
public void setAnstype(String anstype) {
|
||||
this.anstype = anstype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number of hits
|
||||
* @return Number of hits
|
||||
*/
|
||||
public int getNumhits() {
|
||||
return numhits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets number of hits
|
||||
* @param numhits Number of hits
|
||||
*/
|
||||
public void setNumhits(int numhits) {
|
||||
this.numhits = numhits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets shuffle flag
|
||||
* @return Shuffle flag
|
||||
*/
|
||||
public boolean getShuffle() {
|
||||
return shuffle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets shuffle flag
|
||||
* @param shuffle Shuffle flag
|
||||
*/
|
||||
public void setShuffle(boolean shuffle) {
|
||||
this.shuffle = shuffle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets test score
|
||||
* @return Test score
|
||||
*/
|
||||
public float getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets test score
|
||||
* @param score Test score
|
||||
*/
|
||||
public void setScore(float score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets question's answers
|
||||
* @return Question's answers
|
||||
*/
|
||||
public List<TestAnswer> getAnswers() {
|
||||
return answers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets question's answers
|
||||
* @param answers Question's answers
|
||||
*/
|
||||
public void setAnswers(List<TestAnswer> answers) {
|
||||
this.answers = answers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets correct answer for this test
|
||||
* @return Correct test's answer
|
||||
*/
|
||||
public TestAnswer getCorrectAnswer() {
|
||||
TestAnswer correct = null;
|
||||
TestAnswer current = null;
|
||||
Iterator<TestAnswer> it = this.answers.iterator();
|
||||
boolean continueCondition = true;
|
||||
|
||||
while(it.hasNext() && continueCondition) {
|
||||
current = it.next();
|
||||
if(current.getCorrect()) {
|
||||
correct = current;
|
||||
continueCondition = false;
|
||||
}
|
||||
}
|
||||
|
||||
return correct;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user