org.glassfish.jaxb.runtime.v2.schemagen.MultiMap Maven / Gradle / Ivy
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.glassfish.jaxb.runtime.v2.schemagen;
import java.util.Map;
import java.util.TreeMap;
/**
* A special {@link Map} that 'conceptually' stores a set of values for each key.
*
*
* When multiple values are stored, however, this class doesn't let the caller
* see individual values, and instead it returns a specially designated "MANY" value,
* which is given as a parameter to the constructor.
*
* @author Kohsuke Kawaguchi
*/
final class MultiMap,V> extends TreeMap {
private final V many;
public MultiMap(V many) {
this.many = many;
}
@Override
public V put(K key, V value) {
V old = super.put(key, value);
if(old!=null && !old.equals(value)) {
// different value stored
super.put(key,many);
}
return old;
}
@Override
public void putAll(Map extends K, ? extends V> map) {
throw new UnsupportedOperationException();
}
}