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

com.mgmtp.perfload.loadprofiles.ui.model.Settings Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
/*
 * Copyright (c) 2013 mgm technology partners GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mgmtp.perfload.loadprofiles.ui.model;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.mgmtp.perfload.loadprofiles.model.Client;
import com.mgmtp.perfload.loadprofiles.model.Operation;
import com.mgmtp.perfload.loadprofiles.model.Target;

/**
 * @author rnaegele
 */
@XmlRootElement
public class Settings implements Cloneable {

	@XmlElement(name = "operation")
	@XmlElementWrapper(name = "operations")
	private final List operations = newArrayList();

	@XmlElement(name = "target")
	@XmlElementWrapper(name = "targets")
	private final List targets = newArrayList();

	@XmlElement(name = "client")
	@XmlElementWrapper(name = "clients")
	private final List clients = newArrayList();

	public static Settings of(final List operations, final List targets, final List clients) {
		Settings settings = new Settings();
		settings.operations.addAll(operations);
		settings.targets.addAll(targets);
		settings.clients.addAll(clients);
		return settings;
	}

	/**
	 * @return the operations
	 */
	public List getOperations() {
		return ImmutableList.copyOf(operations);
	}

	/**
	 * @return the targets
	 */
	public List getTargets() {
		return ImmutableList.copyOf(targets);
	}

	/**
	 * @return the clients
	 */
	public List getClients() {
		return ImmutableList.copyOf(clients);
	}

	public Settings deepClone() {
		List clonedOperations = ImmutableList.copyOf(transform(getOperations(), new Function() {
			@Override
			public Operation apply(final Operation input) {
				return input.clone();
			}
		}));

		List clonedTargets = ImmutableList.copyOf(transform(getTargets(), new Function() {
			@Override
			public Target apply(final Target input) {
				return input.clone();
			}
		}));

		List clonedClients = ImmutableList.copyOf(transform(getClients(), new Function() {
			@Override
			public Client apply(final Client input) {
				return input.clone();
			}
		}));

		return Settings.of(clonedOperations, clonedTargets, clonedClients);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy