PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Java.NET/JavApi Commons collections (Apache Port)/org.apache.commons.collections.list.UnmodifiableList.cs

https://github.com/gadfly/nofs
C# | 144 lines | 83 code | 21 blank | 40 comment | 1 complexity | eedfd735242d776c276190658a925d03 MD5 | raw file
  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. */
  15. using System;
  16. using java = biz.ritter.javapi;
  17. using org.apache.commons.collections;
  18. using org.apache.commons.collections.iterators;
  19. namespace org.apache.commons.collections.list
  20. {
  21. /**
  22. * Decorates another <code>List</code> to ensure it can't be altered.
  23. * <p>
  24. * This class is java.io.Serializable from Commons Collections 3.1.
  25. *
  26. * @since Commons Collections 3.0
  27. * @version $Revision$ $Date$
  28. *
  29. * @author Stephen Colebourne
  30. */
  31. [Serializable]
  32. public sealed class UnmodifiableList
  33. : AbstractSerializableListDecorator
  34. , Unmodifiable
  35. {
  36. /** Serialization version */
  37. private static readonly long serialVersionUID = 6595182819922443652L;
  38. /**
  39. * Factory method to create an unmodifiable list.
  40. *
  41. * @param list the list to decorate, must not be null
  42. * @throws IllegalArgumentException if list is null
  43. */
  44. public static java.util.List<Object> decorate(java.util.List<Object> list)
  45. {
  46. if (list is Unmodifiable)
  47. {
  48. return list;
  49. }
  50. return new UnmodifiableList(list);
  51. }
  52. //-----------------------------------------------------------------------
  53. /**
  54. * Constructor that wraps (not copies).
  55. *
  56. * @param list the list to decorate, must not be null
  57. * @throws IllegalArgumentException if list is null
  58. */
  59. private UnmodifiableList(java.util.List<Object> list)
  60. : base(list)
  61. {
  62. }
  63. //-----------------------------------------------------------------------
  64. public override java.util.Iterator<Object> iterator()
  65. {
  66. return UnmodifiableIterator.decorate(getCollection().iterator());
  67. }
  68. public override bool add(Object obj)
  69. {
  70. throw new java.lang.UnsupportedOperationException();
  71. }
  72. public override bool addAll(java.util.Collection<Object> coll)
  73. {
  74. throw new java.lang.UnsupportedOperationException();
  75. }
  76. public override void clear()
  77. {
  78. throw new java.lang.UnsupportedOperationException();
  79. }
  80. public override bool remove(Object obj)
  81. {
  82. throw new java.lang.UnsupportedOperationException();
  83. }
  84. public override bool removeAll(java.util.Collection<Object> coll)
  85. {
  86. throw new java.lang.UnsupportedOperationException();
  87. }
  88. public override bool retainAll(java.util.Collection<Object> coll)
  89. {
  90. throw new java.lang.UnsupportedOperationException();
  91. }
  92. //-----------------------------------------------------------------------
  93. public override java.util.ListIterator<Object> listIterator()
  94. {
  95. return UnmodifiableListIterator.decorate(getList().listIterator());
  96. }
  97. public override java.util.ListIterator<Object> listIterator(int index)
  98. {
  99. return UnmodifiableListIterator.decorate(getList().listIterator(index));
  100. }
  101. public override void add(int index, Object obj)
  102. {
  103. throw new java.lang.UnsupportedOperationException();
  104. }
  105. public override bool addAll(int index, java.util.Collection<Object> coll)
  106. {
  107. throw new java.lang.UnsupportedOperationException();
  108. }
  109. public override Object remove(int index)
  110. {
  111. throw new java.lang.UnsupportedOperationException();
  112. }
  113. public override Object set(int index, Object obj)
  114. {
  115. throw new java.lang.UnsupportedOperationException();
  116. }
  117. public override java.util.List<Object> subList(int fromIndex, int toIndex)
  118. {
  119. java.util.List<Object> sub = getList().subList(fromIndex, toIndex);
  120. return new UnmodifiableList(sub);
  121. }
  122. }
  123. }