/lottoritter-core/src/main/java/de/lottoritter/business/lotteries/plus5/Plus5Field.java

https://bitbucket.org/sofiworx/lottoritter-platform · Java · 79 lines · 48 code · 12 blank · 19 comment · 17 complexity · b89271bd018de37dca5c19b378a3864f MD5 · raw file

  1. /*
  2. * Copyright 2017 Ulrich Cech & Christopher Schmidt
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package de.lottoritter.business.lotteries.plus5;
  18. import de.lottoritter.business.lotteries.Field;
  19. import de.lottoritter.business.lotteries.MainTicket;
  20. import org.mongodb.morphia.annotations.Transient;
  21. import javax.xml.bind.annotation.XmlRootElement;
  22. import java.util.Arrays;
  23. import java.util.List;
  24. import java.util.Objects;
  25. /**
  26. * @author Ulrich Cech
  27. */
  28. @XmlRootElement
  29. public class Plus5Field extends Field {
  30. private static final long serialVersionUID = 6274579058275959623L;
  31. @Transient
  32. private MainTicket parentTicket;
  33. public Plus5Field() {
  34. }
  35. @Override
  36. public boolean isValid() {
  37. if ((getSelectedNumbers() == null) || ((getSelectedNumbers() != null) && (getSelectedNumbers().isEmpty()))) {
  38. return true;
  39. }
  40. return isValidFilled();
  41. }
  42. @Override
  43. public boolean isValidFilled() {
  44. if ((getSelectedNumbers() != null) && (getSelectedNumbers().size() == Plus5Lottery.SELECTABLE_NUMBERS)) {
  45. for (Integer selectedNumber : getSelectedNumbers()) {
  46. if ((selectedNumber == null) || (selectedNumber < 0) || (selectedNumber > Plus5Lottery.HIGHEST_SELECTABLE_NUMBER)) {
  47. return false;
  48. }
  49. }
  50. final List<Integer> ticketNumber = Arrays.asList(parentTicket.getNumber());
  51. for (int i = 0; i < ticketNumber.size(); i++) {
  52. if (! Objects.equals(ticketNumber.get(i), getSelectedNumbers().get(i))) {
  53. return false;
  54. }
  55. }
  56. return true;
  57. } else {
  58. return false;
  59. }
  60. }
  61. public void setParentTicket(MainTicket parentTicket) {
  62. this.parentTicket = parentTicket;
  63. }
  64. public MainTicket getParentTicket() {
  65. return parentTicket;
  66. }
  67. }