Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

53
LINES

< > BotCompany Repo | #1029596 // ParameterizedTypeImpl - an implementation of ParameterizedType

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (413L/3K).

1  
// from GSON project, simplified
2  
// (Note: There is a ParameterizedTypeImpl in the JDK, but it is not public
3  
// and has a different constructor signature)
4  
static persistable final class ParameterizedTypeImpl implements ParameterizedType {
5  
  private /*final*/ Type ownerType;
6  
  private /*final*/ Type rawType;
7  
  private /*final*/ Type[] typeArguments;
8  
9  
  *(Type *ownerType, Type *rawType, Type... *typeArguments) {}
10  
11  
  public Type[] getActualTypeArguments() {
12  
    return typeArguments;
13  
  }
14  
15  
  public Type getRawType() {
16  
    return rawType;
17  
  }
18  
19  
  public Type getOwnerType() {
20  
    return ownerType;
21  
  }
22  
23  
  @Override public boolean equals(Object other) {
24  
    if (other cast ParameterizedType)
25  
      ret eq(ownerType, other.getOwnerType())
26  
        && eq(rawType, other.getRawType())
27  
        && eq(asList(typeArguments), asList(other.getActualTypeArguments()));
28  
    false;
29  
  }
30  
31  
  @Override public int hashCode() {
32  
    return Arrays.hashCode(typeArguments)
33  
        ^ rawType.hashCode()
34  
        ^ _hashCode(ownerType);
35  
  }
36  
37  
  @Override public String toString() {
38  
    int length = typeArguments.length;
39  
    if (length == 0)
40  
      ret typeToString(rawType);
41  
42  
    new StringBuilder stringBuilder;
43  
    stringBuilder.append(typeToString(rawType)).append("<").append(typeToString(typeArguments[0]));
44  
    for (int i = 1; i < length; i++) {
45  
      stringBuilder.append(", ").append(typeToString(typeArguments[i]));
46  
    }
47  
    ret stringBuilder.append(">").toString();
48  
  }
49  
  
50  
  static S typeToString(Type type) {
51  
    return type instanceof Class ? ((Class<?>) type).getName() : type.toString();
52  
  }
53  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029596
Snippet name: ParameterizedTypeImpl - an implementation of ParameterizedType
Eternal ID of this version: #1029596/8
Text MD5: 5ec4abd179e2bf9113a7cb60e7917b6f
Transpilation MD5: 69949eb90fa6c8cc0322bd585065391e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-01 01:19:22
Source code size: 1634 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 228 / 546
Version history: 7 change(s)
Referenced in: [show references]