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

com.sappenin.utils.rest.v2.InternalId Maven / Gradle / Ivy

Go to download

Utilities, Helpers, and base-classes for assisting in server-side REST API implementations written in Java.

The newest version!
/**
 * Copyright (C) 2014 Sappenin Inc. ([email protected])
 * 
 * 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.sappenin.utils.rest.v2;

import lombok.EqualsAndHashCode;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.google.common.base.Preconditions;

/**
 * Copyright (C) 2014 Sappenin Inc. ([email protected])
 * 
 * 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.
 */

/**
 * A typed internal identifier that represents the server-side internal identifier of a resource. This can internally
 * hold something like an integer, long number or other type as a String identifier that both client and server can use
 * to aid in locating the actual resource.
 */
// No @Get on purpose so we don't get this value, instead call #toString
@EqualsAndHashCode
@JsonSerialize(using = ToStringSerializer.class)
public class InternalId
{
	private final String internalId;

	/**
	 * Required-args Constructor.
	 * 
	 * @param internalId
	 */
	public InternalId(final String internalId)
	{
		Preconditions.checkArgument(!StringUtils.isBlank(internalId), "Id may not be empty, blank, or null!");
		this.internalId = internalId;
	}

	// No Getter for internalId on purpose so we don't get this value, instead call #toString

	/**
	 * Overridden directly (and not using lombok) so that when expecting to get an internal id as a String, we don't
	 * have to call getId().getId(). Instead, we can just call someObject.getId(), and let the toString do its magic.
	 * 
	 * @return
	 */
	@Override
	public String toString()
	{
		return this.internalId;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy