ConditionLogicAnd.java 2.2 KB

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