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

de.larssh.json.dom.children.JsonDomObjectChildren Maven / Gradle / Ivy

package de.larssh.json.dom.children;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Function;

import de.larssh.json.dom.values.JsonDomValue;

/**
 * JSON DOM children of a JSON object.
 *
 * @param  {@link JsonDomValue} type
 */
public class JsonDomObjectChildren> extends LinkedHashMap
		implements JsonDomChildren {
	/**
	 * Constructor that allows adding children while applying
	 * {@code jsonDomValueMapper} to each child's value before.
	 *
	 * @param                 type of children before mapping to a
	 *                           {@link JsonDomValue} type
	 * @param children           children to apply {@code jsonDomValueMapper} and
	 *                           add
	 * @param jsonDomValueMapper mapper from any given type to a
	 *                           {@link JsonDomValue} type
	 */
	public  JsonDomObjectChildren(final Map children, final Function jsonDomValueMapper) {
		this(children.entrySet(), jsonDomValueMapper);
	}

	/**
	 * Constructor that allows adding children while applying
	 * {@code jsonDomValueMapper} to each child's value before.
	 *
	 * @param                 type of children before mapping to a
	 *                           {@link JsonDomValue} type
	 * @param children           children to apply {@code jsonDomValueMapper} and
	 *                           add
	 * @param jsonDomValueMapper mapper from any given type to a
	 *                           {@link JsonDomValue} type
	 */
	public  JsonDomObjectChildren(final Set> children, final Function jsonDomValueMapper) {
		this(children.iterator(), jsonDomValueMapper);
	}

	/**
	 * Constructor that allows adding children while applying
	 * {@code jsonDomValueMapper} to each child's value before.
	 *
	 * @param                 type of children before mapping to a
	 *                           {@link JsonDomValue} type
	 * @param children           children to apply {@code jsonDomValueMapper} and
	 *                           add
	 * @param jsonDomValueMapper mapper from any given type to a
	 *                           {@link JsonDomValue} type
	 */
	public  JsonDomObjectChildren(final Iterator> children,
			final Function jsonDomValueMapper) {
		while (children.hasNext()) {
			final Entry entry = children.next();
			put(entry.getKey(), jsonDomValueMapper.apply(entry.getValue()));
		}
	}

	/** {@inheritDoc} */
	@Override
	@SuppressWarnings("PMD.UselessOverridingMethod")
	public Set> entrySet() {
		// http://fb-contrib.sourceforge.net/bugdescriptions.html#SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTOR
		return super.entrySet();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy