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

com.networknt.oas.jsonoverlay.ChildMapOverlay Maven / Gradle / Ivy

There is a newer version: 2.1.38
Show newest version
/*******************************************************************************
 *  Copyright (c) 2017 ModelSolv, Inc. and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *     ModelSolv, Inc. - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.networknt.oas.jsonoverlay;

import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.databind.JsonNode;
import com.networknt.oas.jsonoverlay.MapOverlay.MapOverlayFactory;

import java.util.Map;
import java.util.regex.Pattern;

public class ChildMapOverlay> extends ChildOverlay, MapOverlay> {

	private MapOverlay mapOverlay;

	public ChildMapOverlay(String path, JsonNode json, JsonOverlay parent,
			OverlayFactory, MapOverlay> factory, ReferenceRegistry refReg) {
		super(path, json, parent, factory, refReg);
		@SuppressWarnings("unchecked")
		MapOverlay castOverlay = (MapOverlay) overlay;
		this.mapOverlay = castOverlay;
	}

	public ChildMapOverlay(String path, Map value, JsonOverlay parent,
			OverlayFactory, MapOverlay> factory, ReferenceRegistry refReg) {
		super(path, value, parent, factory, refReg);
	}

	@Override
	protected boolean isPartial() {
		return ((MapOverlayFactory) factory).getKeyPattern() != null;
	}

	@Override
	protected boolean matchesPath(JsonPointer path) {
		if (super.matchesPath(path)) {
			String key = super.tailPath(path).getMatchingProperty();
			Pattern keyPattern = mapOverlay.getKeyPattern();
			return keyPattern == null || keyPattern.matcher(key).matches();
		} else {
			return false;
		}
	}

	public boolean containsKey(String name) {
		return mapOverlay.containsKey(name);
	}

	public V get(String name) {
		return mapOverlay.get(name);
	}

	public void set(String name, V value) {
		mapOverlay.set(name, value);
	}

	public void remove(String name) {
		mapOverlay.remove(name);
	}

	public int size() {
		return mapOverlay.size();
	}

	public ChildOverlay getChild(String key) {
		@SuppressWarnings("unchecked")
		ChildOverlay child = (ChildOverlay) mapOverlay.getOverlay(key);
		return child;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy