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

io.katharsis.resource.information.DefaultResourceInstanceBuilder Maven / Gradle / Ivy

There is a newer version: 2.6.3
Show newest version
package io.katharsis.resource.information;

import io.katharsis.request.dto.DataBody;
import io.katharsis.utils.ClassUtils;

/**
 * Default implementation for {@link ResourceInstanceBuilder}} that creates a new instance of the given class
 * using its default constructor.
 */
public class DefaultResourceInstanceBuilder implements ResourceInstanceBuilder {

	private Class resourceClass;

	public DefaultResourceInstanceBuilder(Class resourceClass) {
		this.resourceClass = resourceClass;
	}

	@Override
	public T buildResource(DataBody body) {
		return (T) ClassUtils.newInstance(resourceClass);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((resourceClass == null) ? 0 : resourceClass.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;
		DefaultResourceInstanceBuilder other = (DefaultResourceInstanceBuilder) obj;
		if (resourceClass == null) {
			if (other.resourceClass != null)
				return false;
		} else if (!resourceClass.equals(other.resourceClass))
			return false;
		return true;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy