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

br.com.objectos.way.code.PackageInfo Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
/*
 * Copyright 2014 Objectos, Fábrica de Software LTDA.
 *
 * 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 br.com.objectos.way.code;

import java.util.Objects;

import br.com.objectos.way.pojo.Pojo;
import br.com.objectos.way.testable.Equality;
import br.com.objectos.way.testable.Testable;
import br.com.objectos.way.testable.Tester;

import com.squareup.javapoet.ClassName;

/**
 * @author [email protected] (Marcio Endo)
 */
@Pojo
public abstract class PackageInfo
    implements
    Testable {

  static final PackageInfo JAVA_LANG = builder()
      .name("java.lang")
      .build();

  abstract String name();

  PackageInfo() {
  }

  public static PackageInfoBuilder builder() {
    return new PackageInfoBuilderPojo();
  }

  public boolean hasName(String name) {
    return name().equals(name);
  }

  @Override
  public Equality isEqualTo(Object that) {
    return Tester.of(PackageInfo.class)
        .add("name", o -> o.name())
        .test(this, that);
  }

  public boolean isJavaLang() {
    return "java.lang".equals(name());
  }

  public ClassName className(String simpleName) {
    return ClassName.get(name(), simpleName);
  }

  public ClassName className(String simpleName, String... simpleNames) {
    return ClassName.get(name(), simpleName, simpleNames);
  }

  public String toQualifiedName(NameInfo nameInfo) {
    return String.format("%s.%s", this, nameInfo);
  }

  public String toQualifiedName(String name) {
    return name() + "." + name;
  }

  @Override
  public String toString() {
    return name();
  }

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

  @Override
  public final boolean equals(final Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj instanceof PackageInfo) {
      final PackageInfo that = (PackageInfo) obj;
      return Objects.equals(name(), that.name());
    } else {
      return false;
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy