EmptyQueue.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2004-2015 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.util;
  20. import java.util.Collection;
  21. import java.util.Collections;
  22. import java.util.Iterator;
  23. import java.util.Queue;
  24. /**
  25. * @author UnAfraid
  26. * @param <E>
  27. */
  28. public final class EmptyQueue<E> implements Queue<E>
  29. {
  30. private static final Queue<Object> EMPTY_QUEUE = new EmptyQueue<>();
  31. @SuppressWarnings("unchecked")
  32. public static <E> Queue<E> emptyQueue()
  33. {
  34. return (Queue<E>) EMPTY_QUEUE;
  35. }
  36. @Override
  37. public int size()
  38. {
  39. return 0;
  40. }
  41. @Override
  42. public boolean isEmpty()
  43. {
  44. return true;
  45. }
  46. @Override
  47. public boolean contains(Object o)
  48. {
  49. return false;
  50. }
  51. @Override
  52. public Iterator<E> iterator()
  53. {
  54. return Collections.<E> emptyIterator();
  55. }
  56. @Override
  57. public Object[] toArray()
  58. {
  59. return new Object[0];
  60. }
  61. @Override
  62. public <T> T[] toArray(T[] a)
  63. {
  64. throw new UnsupportedOperationException();
  65. }
  66. @Override
  67. public boolean remove(Object o)
  68. {
  69. throw new UnsupportedOperationException();
  70. }
  71. @Override
  72. public boolean containsAll(Collection<?> c)
  73. {
  74. return false;
  75. }
  76. @Override
  77. public boolean addAll(Collection<? extends E> c)
  78. {
  79. throw new UnsupportedOperationException();
  80. }
  81. @Override
  82. public boolean removeAll(Collection<?> c)
  83. {
  84. throw new UnsupportedOperationException();
  85. }
  86. @Override
  87. public boolean retainAll(Collection<?> c)
  88. {
  89. throw new UnsupportedOperationException();
  90. }
  91. @Override
  92. public void clear()
  93. {
  94. throw new UnsupportedOperationException();
  95. }
  96. @Override
  97. public boolean add(E e)
  98. {
  99. throw new UnsupportedOperationException();
  100. }
  101. @Override
  102. public boolean offer(E e)
  103. {
  104. throw new UnsupportedOperationException();
  105. }
  106. @Override
  107. public E remove()
  108. {
  109. throw new UnsupportedOperationException();
  110. }
  111. @Override
  112. public E poll()
  113. {
  114. throw new UnsupportedOperationException();
  115. }
  116. @Override
  117. public E element()
  118. {
  119. throw new UnsupportedOperationException();
  120. }
  121. @Override
  122. public E peek()
  123. {
  124. throw new UnsupportedOperationException();
  125. }
  126. }