类java.lang.Comparable源码实例Demo

下面列出了怎么用java.lang.Comparable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: javapoet   文件: JavaFileTest.java
@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");
}
 
源代码2 项目: javapoet   文件: TypeSpecTest.java
@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");
}
 
源代码3 项目: javapoet   文件: TypeSpecTest.java
@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");
}
 
源代码4 项目: javapoet   文件: TypeSpecTest.java
@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");
}
 
源代码5 项目: javapoet   文件: TypeSpecTest.java
@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");
}
 
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码8 项目: dragonwell8_jdk   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码9 项目: dragonwell8_jdk   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码10 项目: TencentKona-8   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码11 项目: TencentKona-8   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码12 项目: jdk8u60   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码13 项目: jdk8u60   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码14 项目: JDKSourceCode1.8   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码15 项目: JDKSourceCode1.8   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码16 项目: openjdk-jdk8u   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码17 项目: openjdk-jdk8u   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码20 项目: openjdk-jdk9   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * {@code null} otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码21 项目: openjdk-jdk9   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * {@code null} otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码22 项目: jdk8u-jdk   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码23 项目: jdk8u-jdk   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码24 项目: Java8CN   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码25 项目: Java8CN   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码26 项目: hottub   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码27 项目: hottub   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码28 项目: openjdk-8-source   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
源代码29 项目: openjdk-8-source   文件: OpenMBeanParameterInfo.java
/**
 * Returns the maximal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the maximum value.
 */
public Comparable<?> getMaxValue() ;
 
源代码30 项目: openjdk-8   文件: OpenMBeanParameterInfo.java
/**
 * Returns the minimal value for this parameter, if it has one, or
 * <tt>null</tt> otherwise.
 *
 * @return the minimum value.
 */
public Comparable<?> getMinValue() ;
 
 类所在包
 类方法
 同包方法