| 1 | package de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
| 6 | /**This class stores the information necessary to display a histogram. |
| 7 | * The histogram can be visualized using the information about the bucket |
| 8 | * width and the probability for the buckets. |
| 9 | * @author groenda |
| 10 | */ |
| 11 | public class Histogram { |
| 12 | /** The default width for histogram classes */ |
| 13 | public static final double DEFAULT_BUCKET_WIDTH = 1.0; |
| 14 | |
| 15 | /** The maximum number of buckets to show when initialising the diagram. The user can decide to show more. */ |
| 16 | public static final double MAXIMUM_NUMBER_OF_BUCKETS = 100; |
| 17 | |
| 18 | /** List of the entities, that describe the probability for each of the buckets |
| 19 | * @see HistogramBucketInformation |
| 20 | */ |
| 21 | protected List<HistogramBucketInformation> bucketInformation; |
| 22 | |
| 23 | /** Contains the width of each bucket of the histogram. */ |
| 24 | protected double bucketWidth; |
| 25 | |
| 26 | /** title/name of the histogram */ |
| 27 | private String title; |
| 28 | |
| 29 | /**Creates a new histogram without buckets and default bucket width. |
| 30 | * @param title Title od name of the histogram. |
| 31 | */ |
| 32 | public Histogram(String title) { |
| 33 | this(title, DEFAULT_BUCKET_WIDTH); |
| 34 | } |
| 35 | |
| 36 | /**Creates a new histogram without buckets. |
| 37 | * @param title Title or name of the histogram. |
| 38 | * @param bucketWidth Width of a bucket of the histogram. |
| 39 | */ |
| 40 | public Histogram(String title, double bucketWidth) { |
| 41 | this.bucketInformation = new ArrayList<HistogramBucketInformation>(); |
| 42 | this.title = title; |
| 43 | this.bucketWidth = bucketWidth; |
| 44 | } |
| 45 | |
| 46 | /**Adds a new bucket to the histogram. |
| 47 | * @param entity information about the bucket. |
| 48 | */ |
| 49 | public void addEntity(HistogramBucketInformation entity){ |
| 50 | bucketInformation.add(entity); |
| 51 | } |
| 52 | |
| 53 | /**Removes a bucket from the histogram. |
| 54 | * @param entity bucket to remove. |
| 55 | */ |
| 56 | public void removeEntity(HistogramBucketInformation entity){ |
| 57 | bucketInformation.remove(entity); |
| 58 | } |
| 59 | |
| 60 | /**Returns the list of the buckets and their respective probability. |
| 61 | * @return the list of the entities. |
| 62 | */ |
| 63 | public List<HistogramBucketInformation> getBucketInformation() { |
| 64 | return bucketInformation; |
| 65 | } |
| 66 | |
| 67 | /**Receives the title or name of the histogram. |
| 68 | * @return Title or name of the histogram. |
| 69 | */ |
| 70 | public String getTitle() { |
| 71 | return title; |
| 72 | } |
| 73 | |
| 74 | /**Sets the title or name of the histogram. |
| 75 | * @param title The new title. |
| 76 | */ |
| 77 | public void setTitle(String title) { |
| 78 | this.title=title; |
| 79 | } |
| 80 | |
| 81 | /**Receives the bucket width of the histogram. |
| 82 | * @return the bucket width. |
| 83 | */ |
| 84 | public double getBucketWidth() { |
| 85 | return bucketWidth; |
| 86 | } |
| 87 | |
| 88 | /**Sets the bucket width of the histogram. |
| 89 | * @param bucketWidth the new bucket width. |
| 90 | */ |
| 91 | public void setBucketWidth(double bucketWidth) { |
| 92 | this.bucketWidth = bucketWidth; |
| 93 | } |
| 94 | |
| 95 | } |