PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/main/java/com/google/test/metric/report/issues/Issue.java

http://testability-explorer.googlecode.com/
Java | 117 lines | 78 code | 19 blank | 20 comment | 8 complexity | ed957b6256e1a54a47325ae6a7cf5cdd MD5 | raw file
  1/*
  2 * Copyright 2009 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.report.issues;
 17
 18import java.util.Comparator;
 19
 20import com.google.common.base.Nullable;
 21import com.google.common.base.Predicate;
 22import com.google.test.metric.SourceLocation;
 23
 24/**
 25 * A model of a single reportable issue with the class under analysis.
 26 *
 27 * @author alexeagle@google.com (Alex Eagle)
 28 */
 29public class Issue implements IssueHolder {
 30  private final String element;
 31  private float contributionToClassCost;
 32  private boolean isLineNumberApproximate;
 33  private IssueType type;
 34  private IssueSubType subType;
 35  private SourceLocation location;
 36
 37  public Issue(SourceLocation location, String element, float contributionToClassCost,
 38               IssueType type, IssueSubType subType) {
 39    this.location = location;
 40    this.element = element;
 41    this.contributionToClassCost = contributionToClassCost;
 42    this.type = type;
 43    this.subType = subType;
 44  }
 45
 46  public void setContributionToClassCost(float contributionToClassCost) {
 47    this.contributionToClassCost = contributionToClassCost;
 48  }
 49
 50  public String getElement() {
 51    return element;
 52  }
 53
 54  public float getContributionToClassCost() {
 55    return contributionToClassCost;
 56  }
 57
 58  public boolean isLineNumberApproximate() {
 59    return isLineNumberApproximate;
 60  }
 61
 62  public void setLineNumberIsApproximate(boolean isApprox) {
 63    this.isLineNumberApproximate = isApprox;
 64  }
 65
 66  @Override
 67  public String toString() {
 68    return String.format("On line %d, element %s with contribution %f (%s/%s)",
 69        location.getLineNumber(), element, contributionToClassCost, type, subType);
 70  }
 71
 72  public void setType(IssueType type) {
 73    this.type = type;
 74  }
 75
 76  public IssueType getType() {
 77    return type;
 78  }
 79
 80  public IssueSubType getSubType() {
 81    return subType;
 82  }
 83
 84  public void setSubType(IssueSubType subType) {
 85    this.subType = subType;
 86  }
 87
 88  public boolean isEmpty() {
 89    return 0f == contributionToClassCost;
 90  }
 91
 92  public float getTotalCost() {
 93    return contributionToClassCost;
 94  }
 95
 96  public SourceLocation getLocation() {
 97    return location;
 98  }
 99
100  public static Predicate<? super Issue> isType(final IssueType issueType,
101                                                final IssueSubType subType) {
102    return new Predicate<Issue>() {
103      public boolean apply(@Nullable Issue issue) {
104        if (issue.getType() == null || issue.getSubType() == null) {
105          return false;
106        }
107        return issue.getType() == issueType && issue.getSubType() == subType;
108      }
109    };
110  }
111
112  public static class TotalCostComparator implements Comparator<Issue> {
113    public int compare(Issue issue, Issue issue1) {
114      return Float.compare(issue.getContributionToClassCost(), issue1.getContributionToClassCost());
115    }
116  }
117}