ConditionLogicAnd.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.skills.conditions;
  16. import com.l2jserver.gameserver.skills.Env;
  17. /**
  18. * The Class ConditionLogicAnd.
  19. *
  20. * @author mkizub
  21. */
  22. public class ConditionLogicAnd extends Condition
  23. {
  24. private static Condition[] _emptyConditions = new Condition[0];
  25. public Condition[] conditions = _emptyConditions;
  26. /**
  27. * Instantiates a new condition logic and.
  28. */
  29. public ConditionLogicAnd()
  30. {
  31. super();
  32. }
  33. /**
  34. * Adds the.
  35. *
  36. * @param condition the condition
  37. */
  38. public void add(Condition condition)
  39. {
  40. if (condition == null)
  41. return;
  42. if (getListener() != null)
  43. condition.setListener(this);
  44. final int len = conditions.length;
  45. final Condition[] tmp = new Condition[len + 1];
  46. System.arraycopy(conditions, 0, tmp, 0, len);
  47. tmp[len] = condition;
  48. conditions = tmp;
  49. }
  50. /**
  51. * Sets the listener.
  52. *
  53. * @param listener the new listener
  54. * @see com.l2jserver.gameserver.skills.conditions.Condition#setListener(com.l2jserver.gameserver.skills.conditions.ConditionListener)
  55. */
  56. @Override
  57. void setListener(ConditionListener listener)
  58. {
  59. if (listener != null)
  60. {
  61. for (Condition c : conditions)
  62. c.setListener(this);
  63. }
  64. else
  65. {
  66. for (Condition c : conditions)
  67. c.setListener(null);
  68. }
  69. super.setListener(listener);
  70. }
  71. /**
  72. * Test impl.
  73. *
  74. * @param env the env
  75. * @return true, if successful
  76. * @see com.l2jserver.gameserver.skills.conditions.Condition#testImpl(com.l2jserver.gameserver.skills.Env)
  77. */
  78. @Override
  79. public boolean testImpl(Env env)
  80. {
  81. for (Condition c : conditions)
  82. {
  83. if (!c.test(env))
  84. return false;
  85. }
  86. return true;
  87. }
  88. }