All Downloads are FREE. Search and download functionalities are using the official Maven repository.

swim.util.IterableMap Maven / Gradle / Ivy

There is a newer version: 3.10.0
Show newest version
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package swim.util;

import java.util.AbstractCollection;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

public interface IterableMap extends Iterable>, Map {
  @Override
  boolean isEmpty();

  @Override
  int size();

  @Override
  boolean containsKey(Object key);

  @Override
  boolean containsValue(Object value);

  @Override
  V get(Object key);

  @Override
  V put(K key, V newValue);

  @Override
  void putAll(Map map);

  @Override
  V remove(Object key);

  @Override
  void clear();

  @Override
  default Set> entrySet() {
    return new IterableMapEntrySet(this);
  }

  @Override
  default Set keySet() {
    return new IterableMapKeySet(this);
  }

  @Override
  default Collection values() {
    return new IterableMapValues(this);
  }

  @Override
  Cursor> iterator();

  default Cursor keyIterator() {
    return new CursorKeys(iterator());
  }

  default Cursor valueIterator() {
    return new CursorValues(iterator());
  }
}

final class IterableMapEntrySet extends AbstractSet> {
  private final IterableMap map;

  IterableMapEntrySet(IterableMap map) {
    this.map = map;
  }

  @Override
  public int size() {
    return this.map.size();
  }

  @Override
  public Cursor> iterator() {
    return this.map.iterator();
  }
}

final class IterableMapKeySet extends AbstractSet {
  private final IterableMap map;

  IterableMapKeySet(IterableMap map) {
    this.map = map;
  }

  @Override
  public int size() {
    return this.map.size();
  }

  @Override
  public Cursor iterator() {
    return this.map.keyIterator();
  }
}

final class IterableMapValues extends AbstractCollection {
  private final IterableMap map;

  IterableMapValues(IterableMap map) {
    this.map = map;
  }

  @Override
  public int size() {
    return this.map.size();
  }

  @Override
  public Cursor iterator() {
    return this.map.valueIterator();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy