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

io.pelle.mango.client.base.modules.hierarchical.BaseHierarchicalConfiguration Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2013 Christian Pelster.
 * 
 * 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:
 *     Christian Pelster - initial API and implementation
 */
package io.pelle.mango.client.base.modules.hierarchical;

import io.pelle.mango.client.base.modules.dictionary.model.BaseModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

import com.google.common.base.Function;
import com.google.common.collect.Lists;

public abstract class BaseHierarchicalConfiguration
{

	private Map> hierarchy = new HashMap>();

	private final String id;

	private final String title;

	public BaseHierarchicalConfiguration(String id, String title)
	{
		this.id = id;
		this.title = title;
	}

	@SuppressWarnings("rawtypes")
	protected void addHierarchy(BaseModel baseModel, BaseModel... parentModels)
	{
		if (parentModels.length > 0)
		{
			List parentDictionaryNames = Lists.transform(Arrays.asList(parentModels), new Function()
			{
				@Override
				@Nullable
				public String apply(@Nullable BaseModel input)
				{
					return input.getName();
				}
			});

			this.hierarchy.put(baseModel.getName(), new ArrayList(parentDictionaryNames));
		}
		else
		{
			this.hierarchy.put(baseModel.getName(), Collections.emptyList());
		}
	}

	public HierarchicalConfigurationVO getHierarchyConfigurationVO()
	{
		return new HierarchicalConfigurationVO(getId(), this.title, this.hierarchy);
	}

	public String getId()
	{
		return this.id;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy