/platform/util/src/com/intellij/util/EmptyQuery.java

https://bitbucket.org/nbargnesi/idea · Java · 54 lines · 27 code · 9 blank · 18 comment · 0 complexity · 4e17bc11f6ae0f989f1e15d25a06a0dd MD5 · raw file

  1. /*
  2. * Copyright 2000-2009 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.intellij.util;
  17. import org.jetbrains.annotations.NotNull;
  18. import java.util.Collection;
  19. import java.util.Collections;
  20. import java.util.Iterator;
  21. /**
  22. * @author max
  23. */
  24. public class EmptyQuery<R> implements Query<R> {
  25. private static final EmptyQuery EMPTY_QUERY_INSTANCE = new EmptyQuery();
  26. @NotNull
  27. public Collection<R> findAll() {
  28. return Collections.emptyList();
  29. }
  30. public R findFirst() {
  31. return null;
  32. }
  33. public boolean forEach(@NotNull final Processor<R> consumer) {
  34. return true;
  35. }
  36. public R[] toArray(final R[] a) {
  37. return findAll().toArray(a);
  38. }
  39. public Iterator<R> iterator() {
  40. return findAll().iterator();
  41. }
  42. public static <T> Query<T> getEmptyQuery() {
  43. return (Query<T>) EMPTY_QUERY_INSTANCE;
  44. }
  45. }