PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/main/java/com/google/test/metric/Type.java

http://testability-explorer.googlecode.com/
Java | 89 lines | 61 code | 13 blank | 15 comment | 8 complexity | 5a25b3fa4b388f4ef3920ce1cbf007e9 MD5 | raw file
 1/*
 2 * Copyright 2007 Google Inc.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.google.test.metric;
17
18public class Type {
19  private final String name;
20  private final String code;
21  private final int array;
22
23  protected Type() {
24    this.name = null;
25    this.code = null;
26    this.array = 0;
27  }
28
29  protected Type(String name, String code) {
30    this(0, name, code);
31  }
32
33  protected Type(int array, String name, String code) {
34    this.array = array;
35    this.name = name;
36    if (name.contains(";")) {
37      throw new IllegalArgumentException();
38    }
39    this.code = code;
40  }
41
42  @Override
43  public String toString() {
44    return name;
45  }
46
47  public String getCode() {
48    return code;
49  }
50
51  public Type toArray() {
52    return new Type(array + 1, name + "[]", "[" + code);
53  }
54
55  public boolean isPrimitive() {
56    return code.length() == 1;
57  }
58
59  public boolean isObject() {
60    return !isPrimitive();
61  }
62
63  public boolean isArray() {
64    return array > 0;
65  }
66
67  @Override
68  public int hashCode() {
69    final int prime = 31;
70    int result = 1;
71    result = prime * result + array;
72    result = prime * result + ((code == null) ? 0 : code.hashCode());
73    result = prime * result + ((name == null) ? 0 : name.hashCode());
74    return result;
75  }
76
77  @Override
78  public boolean equals(Object obj) {
79    if (this == obj) {
80      return true;
81    }
82    if (obj == null) {
83      return false;
84    }
85    Type other = (Type) obj;
86    return code.equals(other.code);
87  }
88
89}