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

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

http://testability-explorer.googlecode.com/
Java | 78 lines | 50 code | 13 blank | 15 comment | 2 complexity | 47558fd8005aad89424864f03138a2f0 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 Variable {
19
20  protected final Type type;
21  private final boolean isFinal;
22  private final boolean isGlobal;
23  private String name;
24  private int hashCode;
25
26  public Variable(String name, Type type, boolean isFinal, boolean isGlobal) {
27    setName(name);
28    this.type = type;
29    this.isFinal = isFinal;
30    this.isGlobal = isGlobal;
31  }
32
33  public String getName() {
34    return name;
35  }
36
37  @Override
38  public String toString() {
39    return name + "{" + type + "}";
40  }
41
42  public Type getType() {
43    return type;
44  }
45
46  public void setName(String name) {
47    this.name = name;
48    this.hashCode  = computeHashCode();
49  }
50
51  public int computeHashCode() {
52    final int prime = 31;
53    int result = 1;
54    result = prime * result + ((name == null) ? 0 : name.hashCode());
55    result = prime * result + ((type == null) ? 0 : type.hashCode());
56    return result;
57  }
58
59  @Override
60  public int hashCode() {
61    return hashCode;
62  }
63
64  public boolean isGlobal() {
65    return isGlobal;
66  }
67
68  public boolean isFinal() {
69    return isFinal;
70  }
71
72  public String getDescription() {
73    String type = getType().toString();
74    String typeSimpleName = type.substring(type.lastIndexOf(".") + 1);
75    return String.format("%s %s", typeSimpleName, getName());
76  }
77
78}