StoreID.java
/*
* SPDX-FileCopyrightText: 2025 kaumei.io
* SPDX-License-Identifier: Apache-2.0
*/
package io.kaumei.jdbc.anno.store;
import io.kaumei.jdbc.anno.model.ConverterNameDV;
import org.jspecify.annotations.Nullable;
import javax.lang.model.type.TypeMirror;
import static io.kaumei.jdbc.anno.ctx.JavaModelToString.searchKey;
public class StoreID implements Comparable<StoreID> {
public static StoreID of(TypeMirror type) {
return new StoreID(type, ConverterNameDV.unnamed());
}
public static StoreID of(TypeMirror type, ConverterNameDV name) {
return new StoreID(type, name);
}
// ------------------------------------------------------------------------
private final String value;
private StoreID(TypeMirror type, ConverterNameDV name) {
this.value = name.hasName()
? "name:" + name.value()
: "type:" + searchKey(type);
}
// ------------------------------------------------------------------------
@Override
public int compareTo(StoreID o) {
return this.value.compareTo(o.value);
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
return this.value.equals(((StoreID) o).value);
}
@Override
public int hashCode() {
return this.value.hashCode();
}
@Override
public String toString() {
return value;
}
}