BrightSide Workbench Full Report + Source Code
ChallengeVisualElement.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.visual;
20 
21 import org.turro.plugin.contacts.IContact;
22 import org.turro.students.entities.Challenge;
23 import org.turro.students.entities.Response;
24 
29 public class ChallengeVisualElement extends VisualElement<ChallengeVisualElements, ChallengeVisualElement, Challenge> {
30 
31  private Boolean challenger;
32  private Boolean participates;
33 
34  public ChallengeVisualElement(String name, ChallengeVisualElements factory) {
35  super(name, factory);
36  }
37 
38  public ChallengeVisualElement setChallenger(Boolean challenger) {
39  this.challenger = challenger;
40  return this;
41  }
42 
43  public ChallengeVisualElement setParticipates(Boolean participates) {
44  this.participates = participates;
45  return this;
46  }
47 
48  @Override
49  protected boolean emptyEntityConstraints() {
50  return challenger == null && participates == null;
51  }
52 
53  @Override
54  protected boolean checkAllMatch(Challenge entity, IContact contact) {
55  return true;
56  }
57 
58  @Override
59  protected boolean checkAnyMatch(Challenge entity, IContact contact) {
60  return checkAttributes(entity, contact) ||
61  checkParticipates(entity, contact);
62  }
63 
64  private boolean checkAttributes(Challenge challenge, IContact contact) {
65  return (challenger == null ? false : (checkContact(contact) && challenge.getIdChallenger().equals(contact.getId())));
66  }
67 
68  private boolean checkParticipates(Challenge challenge, IContact contact) {
69  return isNullOrFalse(participates) ? false : (checkContact(contact) && challenge.isParticipant(contact));
70  }
71 
72  /* Helpers */
73 
74  public boolean allows(String name, Response response, IContact contact) {
75  return super.allows(name, response.getChallenge(), contact);
76  }
77 
78 }
boolean checkAllMatch(Challenge entity, IContact contact)
ChallengeVisualElement setChallenger(Boolean challenger)
ChallengeVisualElement setParticipates(Boolean participates)
ChallengeVisualElement(String name, ChallengeVisualElements factory)
boolean checkAnyMatch(Challenge entity, IContact contact)
boolean allows(String name, Response response, IContact contact)