com.sinch.xms.api.BatchIdImpl Maven / Gradle / Ivy
Show all versions of sdk-sms Show documentation
package com.sinch.xms.api;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
/**
* Immutable implementation of {@link BatchId}.
*
* Use the static factory method to create immutable instances:
* {@code BatchIdImpl.of()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Immutable
@CheckReturnValue
final class BatchIdImpl extends BatchId {
private final String id;
private BatchIdImpl(String id) {
this.id = BatchIdImpl.requireNonNull(id, "id");
}
/**
* @return The value of the {@code id} attribute
*/
@Override
protected String id() {
return id;
}
/**
* This instance is equal to all instances of {@code BatchIdImpl} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
return another instanceof BatchIdImpl
&& equalTo((BatchIdImpl) another);
}
private boolean equalTo(BatchIdImpl another) {
return id.equals(another.id);
}
/**
* Computes a hash code from attributes: {@code id}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + id.hashCode();
return h;
}
/**
* Construct a new immutable {@code BatchId} instance.
* @param id The value for the {@code id} attribute
* @return An immutable BatchId instance
*/
public static BatchId of(String id) {
return new BatchIdImpl(id);
}
private static T requireNonNull(T object, String message) {
if (object == null) throw new NullPointerException(message);
return object;
}
}