當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。