ConditionLogicAnd.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.conditions;
  16. import com.l2jserver.gameserver.model.stats.Env;
  17. /**
  18. * The Class ConditionLogicAnd.
  19. * @author mkizub
  20. */
  21. public class ConditionLogicAnd extends Condition
  22. {
  23. private static Condition[] _emptyConditions = new Condition[0];
  24. public Condition[] conditions = _emptyConditions;
  25. /**
  26. * Instantiates a new condition logic and.
  27. */
  28. public ConditionLogicAnd()
  29. {
  30. super();
  31. }
  32. /**
  33. * Adds the.
  34. * @param condition the condition
  35. */
  36. public void add(Condition condition)
  37. {
  38. if (condition == null)
  39. {
  40. return;
  41. }
  42. if (getListener() != null)
  43. {
  44. condition.setListener(this);
  45. }
  46. final int len = conditions.length;
  47. final Condition[] tmp = new Condition[len + 1];
  48. System.arraycopy(conditions, 0, tmp, 0, len);
  49. tmp[len] = condition;
  50. conditions = tmp;
  51. }
  52. /**
  53. * Sets the listener.
  54. * @param listener the new listener
  55. */
  56. @Override
  57. void setListener(ConditionListener listener)
  58. {
  59. if (listener != null)
  60. {
  61. for (Condition c : conditions)
  62. {
  63. c.setListener(this);
  64. }
  65. }
  66. else
  67. {
  68. for (Condition c : conditions)
  69. {
  70. c.setListener(null);
  71. }
  72. }
  73. super.setListener(listener);
  74. }
  75. /**
  76. * Test impl.
  77. * @param env the env
  78. * @return true, if successful
  79. */
  80. @Override
  81. public boolean testImpl(Env env)
  82. {
  83. for (Condition c : conditions)
  84. {
  85. if (!c.test(env))
  86. {
  87. return false;
  88. }
  89. }
  90. return true;
  91. }
  92. }