org.eclipse.basyx.vab.model.VABModelMap Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (C) 2021 the Eclipse BaSyx Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/
package org.eclipse.basyx.vab.model;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.eclipse.basyx.submodel.metamodel.connected.ConnectedElement;
import org.eclipse.basyx.vab.support.TypeDestroyer;
/**
* Base class for all hash maps that contain VAB meta models
*
* Subclasses contain meta model structures for the virtual automation bus. They
* may be copied during instantiation and when creating facades. Implementations
* need to support this behavior.
*
* Warning: equals and hashcode are overwritten so that classes extending
* maps with equal content are always seen as producting the same hashcode/being
* equal
*
* @author kuhn
*
*/
public class VABModelMap implements Map {
protected Map map;
/**
* Default constructor
*/
public VABModelMap() {
map = new HashMap<>();
}
public void setMap(Map map) {
this.map = map;
}
/**
* Wrap an existing map into a VABModelMap
*/
public VABModelMap(Map wrappedContents) {
this();
this.putAll(wrappedContents);
}
/**
* Put element with qualified path into map. This function assumes that all
* intermediate elements are maps as well.
*
* @param path
* path to element in contained map(s)
* @param value
* value to be put
*/
@SuppressWarnings("unchecked")
public > T putPath(String path, Object value) {
// Current Map, start with this map and then traverse according to path
Map currentMap = (Map) this;
// Split string
String[] pathArray = path.split("/");
// Traverse path except last element
for (int i = 0; i < pathArray.length - 1; i++) {
// Get map element
Map mapElement = (Map) currentMap.get(pathArray[i]);
// Create map element if it does not exist yet
if (mapElement == null) {
mapElement = new VABModelMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy