/**
 * Copyright 2015 OpenSearchServer Inc.
 *
 * 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.opensearchserver.affinities.model;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlTransient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@JsonInclude(Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class AffinityResults {

	public String name;

	public List<AffinityResult> results;

	public AffinityResults() {
		this.name = null;
		this.results = null;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public AffinityResults setName(String name) {
		this.name = name;
		return this;
	}

	/**
	 * @param results
	 *            the results to set
	 */
	public AffinityResults setResults(List<AffinityResult> results) {
		this.results = results;
		return this;
	}

	/**
	 * @param result
	 *            the result to add
	 */
	@XmlTransient
	@JsonIgnore
	public AffinityResults addResult(AffinityResult result) {
		if (results == null)
			results = new ArrayList<AffinityResult>(1);
		results.add(result);
		return this;
	}

	@XmlTransient
	@JsonIgnore
	public boolean isEmpty() {
		return results == null || results.isEmpty();
	}
}
