MCPcopy Index your code
hub / github.com/beanshell/beanshell / getBshIterator

Method getBshIterator

src/bsh/CollectionManager.java:60–111  ·  view source on GitHub ↗
( Object obj )

Source from the content-addressed store, hash-verified

58 }
59
60 public Iterator getBshIterator( Object obj )
61 throws IllegalArgumentException
62 {
63 if(obj==null)
64 throw new NullPointerException("Cannot iterate over null.");
65
66 if (obj instanceof Enumeration) {
67 final Enumeration enumeration = (Enumeration)obj;
68 return new Iterator<Object>() {
69 public boolean hasNext() {
70 return enumeration.hasMoreElements();
71 }
72 public Object next() {
73 return enumeration.nextElement();
74 }
75 public void remove() {
76 throw new UnsupportedOperationException();
77 }
78 };
79 }
80
81 if (obj instanceof Iterator)
82 return (Iterator)obj;
83
84 if (obj instanceof Iterable)
85 return ((Iterable)obj).iterator();
86
87 if (obj.getClass().isArray()) {
88 final Object array = obj;
89 return new Iterator() {
90 private int index = 0;
91 private final int length = Array.getLength(array);
92
93 public boolean hasNext() {
94 return index < length;
95 }
96 public Object next() {
97 return Array.get(array, index++);
98 }
99 public void remove() {
100 throw new UnsupportedOperationException();
101 }
102 };
103 }
104
105 if (obj instanceof CharSequence)
106 return getBshIterator(
107 obj.toString().toCharArray());
108
109 throw new IllegalArgumentException(
110 "Cannot iterate over object of type "+obj.getClass());
111 }
112
113 public boolean isMap( Object obj ) {
114 return obj instanceof Map;

Callers 2

isBshIterableMethod · 0.95
evalMethod · 0.95

Calls 3

iteratorMethod · 0.80
getClassMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected