You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenericName.java 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package depends.entity;
  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. public class GenericName implements Serializable{
  7. private static final long serialVersionUID = 1L;
  8. private char[] name;
  9. List<GenericName> arguments;
  10. public GenericName(String name) {
  11. this.name = name.toCharArray();
  12. }
  13. public GenericName(String name, List<GenericName> arguments) {
  14. this.name = name.toCharArray();
  15. this.arguments = arguments;
  16. }
  17. public boolean contains(String rawType) {
  18. if (new String(name).contains(rawType)) return true;
  19. return false;
  20. }
  21. public String getName() {
  22. return new String(name);
  23. }
  24. public List<GenericName> getArguments() {
  25. if (arguments==null) return new ArrayList<>();
  26. return arguments;
  27. }
  28. @Override
  29. public String toString() {
  30. return new String(name) + (getArguments().size()>0?"(" + arguments + ")":"");
  31. }
  32. public GenericName replace(String from, String to) {
  33. name = new String(name).replace(from, to).toCharArray();
  34. for (GenericName arg:getArguments()) {
  35. arg.replace(from, to);
  36. }
  37. return this;
  38. }
  39. public boolean startsWith(String prefix) {
  40. if (name==null) return false;
  41. return new String(name).startsWith(prefix);
  42. }
  43. public String uniqName() {
  44. if (getArguments().size()==0) return new String(name);
  45. StringBuffer sb = new StringBuffer();
  46. sb.append(name);
  47. if (getArguments().size()>0) {
  48. for (GenericName arg:getArguments()) {
  49. sb.append("__").append(arg.uniqName()).append("__");
  50. }
  51. }
  52. return sb.toString();
  53. }
  54. public GenericName substring(int start) {
  55. return new GenericName(new String(this.name).substring(start));
  56. }
  57. public boolean isNull() {
  58. return name==null;
  59. }
  60. public static GenericName build(String name) {
  61. if (name==null) return null;
  62. return new GenericName(name);
  63. }
  64. public static GenericName build(String name, List<GenericName> arguments) {
  65. return new GenericName(name,arguments);
  66. }
  67. public boolean find(GenericName rawType) {
  68. //if (this.equals(rawType)) return true;
  69. for (GenericName subType:this.getArguments()) {
  70. if (subType.equals(rawType)) return true;
  71. boolean found = subType.find(rawType);
  72. if (found) return true;
  73. }
  74. return false;
  75. }
  76. public void appendArguments(List<GenericName> parameters) {
  77. if (this.arguments==null) this.arguments = new ArrayList<>();
  78. this.arguments.addAll(parameters);
  79. }
  80. public void appendArguments(GenericName parameter) {
  81. if (this.arguments==null) this.arguments = new ArrayList<>();
  82. this.arguments.add(parameter);
  83. }
  84. @Override
  85. public int hashCode() {
  86. final int prime = 31;
  87. int result = 1;
  88. result = prime * result + ((arguments == null) ? 0 : arguments.hashCode());
  89. result = prime * result + Arrays.hashCode(name);
  90. return result;
  91. }
  92. @Override
  93. public boolean equals(Object obj) {
  94. if (this == obj)
  95. return true;
  96. if (obj == null)
  97. return false;
  98. if (getClass() != obj.getClass())
  99. return false;
  100. GenericName other = (GenericName) obj;
  101. if (this.getArguments() == null) {
  102. if (other.getArguments() != null)
  103. return false;
  104. } else if (!getArguments().equals(other.getArguments()))
  105. return false;
  106. if (!Arrays.equals(name, other.name))
  107. return false;
  108. return true;
  109. }
  110. }

No Description

Contributors (2)