您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TabCompletionMatches.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.ui.input;
  23. import java.util.ArrayList;
  24. import java.util.Collections;
  25. import java.util.List;
  26. /**
  27. * Describes a set of matches from a tab completion attempt.
  28. *
  29. * @deprecated This class is dumb. Just use a List.
  30. */
  31. @Deprecated
  32. public class TabCompletionMatches extends ArrayList<String> {
  33. /**
  34. * Adds a result to this result set.
  35. *
  36. * @param result The result to be added
  37. */
  38. public void addResult(final String result) {
  39. add(result);
  40. }
  41. /**
  42. * Determines if this result set contains the specified result.
  43. *
  44. * @param result The result to be tested
  45. *
  46. * @return True if this set contains the specified result, false otherwise
  47. */
  48. public boolean hasResult(final String result) {
  49. return contains(result);
  50. }
  51. /**
  52. * Merges the specified additional results with this result set.
  53. *
  54. * @param additional The results to merge
  55. */
  56. public void merge(final TabCompletionMatches additional) {
  57. additional.getResults().stream().filter(result -> !hasResult(result))
  58. .forEach(this::addResult);
  59. }
  60. /**
  61. * Gets the total size of this result set.
  62. *
  63. * @return the size of this result set
  64. */
  65. public int getResultCount() {
  66. return size();
  67. }
  68. /**
  69. * Retrieves the list of results that this set contains.
  70. *
  71. * @return An unmodifiable list containing the results
  72. */
  73. public List<String> getResults() {
  74. return Collections.unmodifiableList(this);
  75. }
  76. @Override
  77. public String toString() {
  78. final StringBuilder buff = new StringBuilder();
  79. for (String entry : this) {
  80. if (buff.length() > 0) {
  81. buff.append(", ");
  82. }
  83. buff.append(entry);
  84. }
  85. return buff.toString();
  86. }
  87. }