| 135 | } |
| 136 | |
| 137 | private static class Single implements Buffer { |
| 138 | private volatile Object val; |
| 139 | |
| 140 | public Single(Object o) { |
| 141 | this.val = o; |
| 142 | } |
| 143 | |
| 144 | public Buffer add(Object o) { |
| 145 | if (val == NONE) { |
| 146 | val = o; |
| 147 | return this; |
| 148 | } else { |
| 149 | return new Many(val, o); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | public Object remove() { |
| 154 | if(val == NONE) { |
| 155 | throw new IllegalStateException("Removing object from empty buffer"); |
| 156 | } |
| 157 | Object ret = val; |
| 158 | val = NONE; |
| 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | public boolean isEmpty() { |
| 163 | return val == NONE; |
| 164 | } |
| 165 | |
| 166 | public String toString() { |
| 167 | return "Single: " + val; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | private static class Many implements Buffer { |
| 172 | private final Queue vals = new LinkedList(); |
nothing calls this directly
no outgoing calls
no test coverage detected