|
| 1 | +/* |
| 2 | +// $Id: ArrayNamedListImpl.java 482 2012-01-05 23:27:27Z jhyde $ |
| 3 | +// |
| 4 | +// Licensed to Julian Hyde under one or more contributor license |
| 5 | +// agreements. See the NOTICE file distributed with this work for |
| 6 | +// additional information regarding copyright ownership. |
| 7 | +// |
| 8 | +// Julian Hyde licenses this file to you under the Apache License, |
| 9 | +// Version 2.0 (the "License"); you may not use this file except in |
| 10 | +// compliance with the License. You may obtain a copy of the License at: |
| 11 | +// |
| 12 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +// |
| 14 | +// Unless required by applicable law or agreed to in writing, software |
| 15 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +// See the License for the specific language governing permissions and |
| 18 | +// limitations under the License. |
| 19 | +*/ |
| 20 | +package org.olap4j.impl; |
| 21 | + |
| 22 | +import org.olap4j.metadata.NamedList; |
| 23 | + |
| 24 | +import java.util.*; |
| 25 | + |
| 26 | +/** |
| 27 | + * Map backed by a {@link org.olap4j.metadata.NamedList}. |
| 28 | + * |
| 29 | + * @author jhyde |
| 30 | + * @version $Id: AbstractNamedList.java 482 2012-01-05 23:27:27Z jhyde $ |
| 31 | + */ |
| 32 | +class NamedListMap<T> extends AbstractMap<String, T> { |
| 33 | + private final NamedList<T> namedList; |
| 34 | + |
| 35 | + /** |
| 36 | + * Creates a NamedListMap. |
| 37 | + * |
| 38 | + * @param namedList Named list |
| 39 | + */ |
| 40 | + public NamedListMap(NamedList<T> namedList) { |
| 41 | + this.namedList = namedList; |
| 42 | + } |
| 43 | + |
| 44 | + public Set<Entry<String, T>> entrySet() { |
| 45 | + return new AbstractSet<Entry<String, T>>() { |
| 46 | + public Iterator<Entry<String, T>> iterator() { |
| 47 | + final Iterator<T> iterator = namedList.iterator(); |
| 48 | + return new Iterator<Entry<String, T>>() { |
| 49 | + public boolean hasNext() { |
| 50 | + return iterator.hasNext(); |
| 51 | + } |
| 52 | + |
| 53 | + public Entry<String, T> next() { |
| 54 | + T x = iterator.next(); |
| 55 | + String name = namedList.elementName(x); |
| 56 | + return new Pair<String, T>(name, x); |
| 57 | + } |
| 58 | + |
| 59 | + public void remove() { |
| 60 | + iterator.remove(); |
| 61 | + } |
| 62 | + }; |
| 63 | + } |
| 64 | + |
| 65 | + public int size() { |
| 66 | + return namedList.size(); |
| 67 | + } |
| 68 | + }; |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +// End NamedListMap.java |
0 commit comments