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

io.imunity.scim.common.ListResponse Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */

package io.imunity.scim.common;

import static org.springframework.util.Assert.notEmpty;
import static org.springframework.util.Assert.notNull;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

@JsonPropertyOrder(
{ "schemas", "totalResults", "resources" })
@JsonDeserialize(builder = ListResponse.Builder.class)
public class ListResponse
{
	public static final String SCHEMA = "urn:ietf:params:scim:api:messages:2.0:ListResponse";

	public final Set schemas;
	public final int totalResults;
	public final List resources;

	private ListResponse(Builder builder)
	{
		this.schemas = Set.copyOf(builder.schemas);
		this.totalResults = builder.totalResults;
		this.resources = List.copyOf(builder.resources);
	}

	@Override
	public int hashCode()
	{
		return Objects.hash(resources, schemas, totalResults);
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ListResponse other = (ListResponse) obj;
		return Objects.equals(resources, other.resources) && Objects.equals(schemas, other.schemas)
				&& totalResults == other.totalResults;
	}

	public static  Builder builder()
	{
		return new Builder();
	}

	public static final class Builder
	{
		private Set schemas;
		private Integer totalResults;
		private List resources = Collections.emptyList();

		private Builder()
		{
			withSchemas(Set.of(SCHEMA));
		}

		private Builder withSchemas(Set schemas)
		{
			this.schemas = schemas;
			return this;
		}

		public Builder withTotalResults(int totalResults)
		{
			this.totalResults = totalResults;
			return this;
		}

		public Builder withResources(List resources)
		{
			this.resources = resources;
			return this;
		}

		public ListResponse build()
		{
			notNull(schemas, "schemas cannot be null.");
			notEmpty(schemas, "schemas cannot be empty.");
			notNull(totalResults, "id cannot be null.");
			return new ListResponse(this);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy