当前位置: 首页>>代码示例>>Java>>正文


Java Comparable类代码示例

本文整理汇总了Java中java.lang.Comparable的典型用法代码示例。如果您正苦于以下问题:Java Comparable类的具体用法?Java Comparable怎么用?Java Comparable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Comparable类属于java.lang包,在下文中一共展示了Comparable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: typeVariableWithBounds

import java.lang.Comparable; //导入依赖的package包/类
@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, Q extends Number & Comparable> {\n"
            + "  P x;\n"
            + "\n"
            + "  @A Q y;\n"
            + "}\n");
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:25,代码来源:TestTypeSpec.java

示例2: classImplementsExtends

import java.lang.Comparable; //导入依赖的package包/类
@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");
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:24,代码来源:TestTypeSpec.java

示例3: classImplementsExtendsSameName

import java.lang.Comparable; //导入依赖的package包/类
@Test
public void classImplementsExtendsSameName()
        throws Exception
{
    ClassName javapoetTaco = ClassName.get(tacosPackage, "Taco");
    ClassName tacoBellTaco = ClassName.get("com.taco.bell", "Taco");
    ClassName fishTaco = ClassName.get("org.fish.taco", "Taco");
    TypeSpec typeSpec = TypeSpec.classBuilder("Taco")
            .superclass(fishTaco)
            .addSuperinterface(ParameterizedTypeName.get(ClassName.get(Comparable.class), javapoetTaco))
            .addSuperinterface(tacoBellTaco)
            .build();
    assertThat(toString(typeSpec)).isEqualTo(""
            + "package com.squareup.tacos;\n"
            + "\n"
            + "import java.lang.Comparable;\n"
            + "\n"
            + "class Taco extends org.fish.taco.Taco "
            + "implements Comparable<Taco>, com.taco.bell.Taco {\n"
            + "}\n");
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:22,代码来源:TestTypeSpec.java

示例4: interfaceExtends

import java.lang.Comparable; //导入依赖的package包/类
@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");
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:19,代码来源:TestTypeSpec.java

示例5: partition

import java.lang.Comparable; //导入依赖的package包/类
/**
 * gibt das mittlere Element des (umgeordneten Arrays) zur�ck
 */

private static int partition(ArrayList<Comparable> list, int m, int n)
{
    Comparable x = list.get(m);  // Pivot-Element
    int j = n + 1;
    int i = m - 1;
    
    while (true)
    {
        j--;
        while (list.get(j).compareTo(x) > 0) j--;
        i++;
        while (list.get(i).compareTo(x) < 0) i++;
        if (i < j) exchange(list, i, j);
        else return j;
    }
}
 
开发者ID:renespeck,项目名称:Cugar,代码行数:21,代码来源:QuickSort.java

示例6: foo

import java.lang.Comparable; //导入依赖的package包/类
public void foo() {
  Runnable r = new Runnable() {
    @Override
    public void run() {
      Comparable<Integer> c = new Comparable<Integer>() {
        @Override
        public int compareTo(Integer o) {
          return 0;
        }
      };
    }
  };
  
  class FooLocal {
    Runnable r = new Runnable() {
      @Override
      public void run() {
      }
    };
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:ManyClasses.java

示例7: mergeLists

import java.lang.Comparable; //导入依赖的package包/类
public static <T extends Comparable<T>> Node<T> mergeLists(
        Node<T> a, Node<T> b) {

    if (a == null && b == null) {
        return null;
    }
    if (a == null) {
        return b;
    }
    if (b == null) {
        return a;
    }

    Node<T> temp = a.next;
    a.next = b.next;
    a.next.prev = a;
    b.next = temp;
    b.next.prev = b;

    return a.compareTo(b) < 0 ? a : b;
}
 
开发者ID:gabormakrai,项目名称:dijkstra-performance,代码行数:22,代码来源:FibonacciHeap.java

示例8: superclassReferencesSelf

import java.lang.Comparable; //导入依赖的package包/类
@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");
}
 
开发者ID:square,项目名称:javapoet,代码行数:17,代码来源:JavaFileTest.java

示例9: typeVariableWithBounds

import java.lang.Comparable; //导入依赖的package包/类
@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");
}
 
开发者ID:square,项目名称:javapoet,代码行数:23,代码来源:TypeSpecTest.java

示例10: classImplementsExtends

import java.lang.Comparable; //导入依赖的package包/类
@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");
}
 
开发者ID:square,项目名称:javapoet,代码行数:21,代码来源:TypeSpecTest.java

示例11: typeVariables

import java.lang.Comparable; //导入依赖的package包/类
@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");
}
 
开发者ID:square,项目名称:javapoet,代码行数:55,代码来源:TypeSpecTest.java

示例12: interfaceExtends

import java.lang.Comparable; //导入依赖的package包/类
@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");
}
 
开发者ID:square,项目名称:javapoet,代码行数:16,代码来源:TypeSpecTest.java

示例13: typeVariables

import java.lang.Comparable; //导入依赖的package包/类
@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");
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:58,代码来源:TestTypeSpec.java

示例14: foo

import java.lang.Comparable; //导入依赖的package包/类
public void foo() {
    Comparable<String> c = (o) -> ba<caret>r();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:OneLineLambdaValueCompatibleOneLine.java

示例15: genericMethod

import java.lang.Comparable; //导入依赖的package包/类
public <T extends Comparable> T genericMethod(T genericArg) {
	return genericArg;
}
 
开发者ID:JozefCeluch,项目名称:thesis-disassembler,代码行数:4,代码来源:ClassWithMethods.java


注:本文中的java.lang.Comparable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。