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

com.coditory.quark.context.BeanDescriptor Maven / Gradle / Ivy

There is a newer version: 0.1.22
Show newest version
package com.coditory.quark.context;

import java.util.Objects;

import static java.util.Objects.requireNonNull;

final class BeanDescriptor {
    public static  BeanDescriptor descriptor(Class type) {
        return new BeanDescriptor<>(type, null);
    }

    public static  BeanDescriptor descriptor(Class type, String name) {
        return new BeanDescriptor<>(type, name);
    }

    private final String name;
    private final Class type;

    private BeanDescriptor(Class type, String name) {
        this.type = requireNonNull(type);
        this.name = name == null || name.isBlank() ? null : name;
    }

     BeanDescriptor withType(Class type) {
        return new BeanDescriptor<>(type, name);
    }

    String getName() {
        return name;
    }

    Class getType() {
        return type;
    }

    @Override
    public String toString() {
        return "BeanDescriptor{" +
                "name='" + name + '\'' +
                ", type=" + type +
                '}';
    }

    String toShortString() {
        return name != null
                ? type.getSimpleName() + ":" + name
                : type.getSimpleName();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BeanDescriptor that = (BeanDescriptor) o;
        return Objects.equals(name, that.name)
                && Objects.equals(type, that.type);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, type);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy