java.lang.Comparable Java Examples

The following examples show how to use java.lang.Comparable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeSpecTest.java    From javapoet with Apache License 2.0 6 votes vote down vote up
@Test public void classImplementsExtends() throws Exception {
  ClassName taco = ClassName.get(tacosPackage, "Taco");
  ClassName food = ClassName.get("com.squareup.tacos", "Food");
  TypeSpec typeSpec = TypeSpec.classBuilder("Taco")
      .addModifiers(Modifier.ABSTRACT)
      .superclass(ParameterizedTypeName.get(ClassName.get(AbstractSet.class), food))
      .addSuperinterface(Serializable.class)
      .addSuperinterface(ParameterizedTypeName.get(ClassName.get(Comparable.class), taco))
      .build();
  assertThat(toString(typeSpec)).isEqualTo(""
      + "package com.squareup.tacos;\n"
      + "\n"
      + "import java.io.Serializable;\n"
      + "import java.lang.Comparable;\n"
      + "import java.util.AbstractSet;\n"
      + "\n"
      + "abstract class Taco extends AbstractSet<Food> "
      + "implements Serializable, Comparable<Taco> {\n"
      + "}\n");
}
 
Example #2
Source File: TypeSpecTest.java    From javapoet with Apache License 2.0 6 votes vote down vote up
@Test public void typeVariableWithBounds() {
  AnnotationSpec a = AnnotationSpec.builder(ClassName.get("com.squareup.tacos", "A")).build();
  TypeVariableName p = TypeVariableName.get("P", Number.class);
  TypeVariableName q = (TypeVariableName) TypeVariableName.get("Q", Number.class).annotated(a);
  TypeSpec typeSpec = TypeSpec.classBuilder("Location")
      .addTypeVariable(p.withBounds(Comparable.class))
      .addTypeVariable(q.withBounds(Comparable.class))
      .addField(p, "x")
      .addField(q, "y")
      .build();
  assertThat(toString(typeSpec)).isEqualTo(""
      + "package com.squareup.tacos;\n"
      + "\n"
      + "import java.lang.Comparable;\n"
      + "import java.lang.Number;\n"
      + "\n"
      + "class Location<P extends Number & Comparable, @A Q extends Number & Comparable> {\n"
      + "  P x;\n"
      + "\n"
      + "  @A Q y;\n"
      + "}\n");
}
 
Example #3
Source File: JavaFileTest.java    From javapoet with Apache License 2.0 6 votes vote down vote up
@Test public void superclassReferencesSelf() throws Exception {
  String source = JavaFile.builder("com.squareup.tacos",
      TypeSpec.classBuilder("Taco")
          .superclass(ParameterizedTypeName.get(
              ClassName.get(Comparable.class), ClassName.get("com.squareup.tacos", "Taco")))
          .build())
      .build()
      .toString();
  assertThat(source).isEqualTo(""
      + "package com.squareup.tacos;\n"
      + "\n"
      + "import java.lang.Comparable;\n"
      + "\n"
      + "class Taco extends Comparable<Taco> {\n"
      + "}\n");
}
 
Example #4
Source File: TypeSpecTest.java    From javapoet with Apache License 2.0 5 votes vote down vote up
@Test public void interfaceExtends() throws Exception {
  ClassName taco = ClassName.get(tacosPackage, "Taco");
  TypeSpec typeSpec = TypeSpec.interfaceBuilder("Taco")
      .addSuperinterface(Serializable.class)
      .addSuperinterface(ParameterizedTypeName.get(ClassName.get(Comparable.class), taco))
      .build();
  assertThat(toString(typeSpec)).isEqualTo(""
      + "package com.squareup.tacos;\n"
      + "\n"
      + "import java.io.Serializable;\n"
      + "import java.lang.Comparable;\n"
      + "\n"
      + "interface Taco extends Serializable, Comparable<Taco> {\n"
      + "}\n");
}
 
Example #5
Source File: TypeSpecTest.java    From javapoet with Apache License 2.0 4 votes vote down vote up
@Test public void typeVariables() throws Exception {
  TypeVariableName t = TypeVariableName.get("T");
  TypeVariableName p = TypeVariableName.get("P", Number.class);
  ClassName location = ClassName.get(tacosPackage, "Location");
  TypeSpec typeSpec = TypeSpec.classBuilder("Location")
      .addTypeVariable(t)
      .addTypeVariable(p)
      .addSuperinterface(ParameterizedTypeName.get(ClassName.get(Comparable.class), p))
      .addField(t, "label")
      .addField(p, "x")
      .addField(p, "y")
      .addMethod(MethodSpec.methodBuilder("compareTo")
          .addAnnotation(Override.class)
          .addModifiers(Modifier.PUBLIC)
          .returns(int.class)
          .addParameter(p, "p")
          .addCode("return 0;\n")
          .build())
      .addMethod(MethodSpec.methodBuilder("of")
          .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
          .addTypeVariable(t)
          .addTypeVariable(p)
          .returns(ParameterizedTypeName.get(location, t, p))
          .addParameter(t, "label")
          .addParameter(p, "x")
          .addParameter(p, "y")
          .addCode("throw new $T($S);\n", UnsupportedOperationException.class, "TODO")
          .build())
      .build();
  assertThat(toString(typeSpec)).isEqualTo(""
      + "package com.squareup.tacos;\n"
      + "\n"
      + "import java.lang.Comparable;\n"
      + "import java.lang.Number;\n"
      + "import java.lang.Override;\n"
      + "import java.lang.UnsupportedOperationException;\n"
      + "\n"
      + "class Location<T, P extends Number> implements Comparable<P> {\n"
      + "  T label;\n"
      + "\n"
      + "  P x;\n"
      + "\n"
      + "  P y;\n"
      + "\n"
      + "  @Override\n"
      + "  public int compareTo(P p) {\n"
      + "    return 0;\n"
      + "  }\n"
      + "\n"
      + "  public static <T, P extends Number> Location<T, P> of(T label, P x, P y) {\n"
      + "    throw new UnsupportedOperationException(\"TODO\");\n"
      + "  }\n"
      + "}\n");
}
 
Example #6
Source File: OpenMBeanParameterInfo.java    From Java8CN with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #7
Source File: OpenMBeanParameterInfo.java    From Java8CN with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #8
Source File: OpenMBeanParameterInfo.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #9
Source File: OpenMBeanParameterInfo.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #10
Source File: OpenMBeanParameterInfo.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #11
Source File: OpenMBeanParameterInfo.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #12
Source File: OpenMBeanParameterInfo.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #13
Source File: OpenMBeanParameterInfo.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #14
Source File: OpenMBeanParameterInfo.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #15
Source File: OpenMBeanParameterInfo.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #16
Source File: OpenMBeanParameterInfo.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #17
Source File: OpenMBeanParameterInfo.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #18
Source File: OpenMBeanParameterInfo.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #19
Source File: OpenMBeanParameterInfo.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #20
Source File: OpenMBeanParameterInfo.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #21
Source File: OpenMBeanParameterInfo.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #22
Source File: OpenMBeanParameterInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #23
Source File: OpenMBeanParameterInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #24
Source File: OpenMBeanParameterInfo.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #25
Source File: OpenMBeanParameterInfo.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #26
Source File: OpenMBeanParameterInfo.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #27
Source File: OpenMBeanParameterInfo.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
Example #28
Source File: OpenMBeanParameterInfo.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #29
Source File: OpenMBeanParameterInfo.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
Example #30
Source File: OpenMBeanParameterInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;