ConditionLogicAnd.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * @see com.l2jserver.gameserver.model.conditions.Condition#setListener(com.l2jserver.gameserver.model.conditions.ConditionListener)
  56. */
  57. @Override
  58. void setListener(ConditionListener listener)
  59. {
  60. if (listener != null)
  61. {
  62. for (Condition c : conditions)
  63. {
  64. c.setListener(this);
  65. }
  66. }
  67. else
  68. {
  69. for (Condition c : conditions)
  70. {
  71. c.setListener(null);
  72. }
  73. }
  74. super.setListener(listener);
  75. }
  76. /**
  77. * Test impl.
  78. * @param env the env
  79. * @return true, if successful
  80. * @see com.l2jserver.gameserver.model.conditions.Condition#testImpl(com.l2jserver.gameserver.model.stats.Env)
  81. */
  82. @Override
  83. public boolean testImpl(Env env)
  84. {
  85. for (Condition c : conditions)
  86. {
  87. if (!c.test(env))
  88. {
  89. return false;
  90. }
  91. }
  92. return true;
  93. }
  94. }