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

org.usergrid.management.ApplicationInfo Maven / Gradle / Ivy

There is a newer version: 0.0.27.1
Show newest version
/*******************************************************************************
 * Copyright 2012 Apigee Corporation
 * 
 * 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 org.usergrid.management;

import static org.usergrid.persistence.Schema.PROPERTY_NAME;
import static org.usergrid.persistence.Schema.PROPERTY_UUID;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;

public class ApplicationInfo {

	private final UUID id;
	private final String name;

	public ApplicationInfo(UUID id, String name) {
		this.id = id;
		this.name = name;
	}

	public ApplicationInfo(Map properties) {
		id = (UUID) properties.get(PROPERTY_UUID);
		name = (String) properties.get(PROPERTY_NAME);
	}

	public UUID getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public static List fromNameIdMap(Map map) {
		List list = new ArrayList();
		for (Entry s : map.entrySet()) {
			list.add(new ApplicationInfo(s.getValue(), s.getKey()));
		}
		return list;
	}

	public static List fromIdNameMap(Map map) {
		List list = new ArrayList();
		for (Entry s : map.entrySet()) {
			list.add(new ApplicationInfo(s.getKey(), s.getValue()));
		}
		return list;
	}

	public static Map toNameIdMap(List list) {
		Map map = new LinkedHashMap();
		for (ApplicationInfo i : list) {
			map.put(i.getName(), i.getId());
		}
		return map;
	}

	public static Map toIdNameMap(List list) {
		Map map = new LinkedHashMap();
		for (ApplicationInfo i : list) {
			map.put(i.getId(), i.getName());
		}
		return map;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		ApplicationInfo other = (ApplicationInfo) obj;
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy