This repository was archived by the owner on Dec 29, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathDataPoint.java
More file actions
153 lines (135 loc) · 3.43 KB
/
Copy pathDataPoint.java
File metadata and controls
153 lines (135 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Class to represent a single data point of light curve data
* @author S.R. Moorhead
* @version 05/28/14
*
*/
//import statements:
import java.util.Scanner;
public class DataPoint {
//instance variables
private double time;
private double flux;
private double weight;
/**
* Zero argument constructor.
* Automatically sets time and flux to zero and weight to 1
* Probably unnecessary.
*/
public DataPoint() {
time = 0;
flux = 0;
weight = 1;
}
/**
* Given time t and flux f and weight w, create a data point.
* @param t is a double representing the time of the data point
* @param f is a double representing the flux level of the data point
*/
public DataPoint(double t, double f) {
time = t;
flux = f;
weight = 1;
}
/**
* Given time t and flux f and weight w, create a data point.
* @param t is a double representing the time of the data point
* @param f is a double representing the flux level of the data point
* @param w is a double representing the weight of the point in comparison to all other points
*/
public DataPoint(double t, double f, double w) {
time = t;
flux = f;
weight = w;
}
/**
* Given a single line from a data file, create a data point.
* @param line is a line containing data in the order: time flux weight
*/
public DataPoint(String line) {
if(line.length() == 0)
throw new IllegalArgumentException("The passed string does not contain any data.");
Scanner s = new Scanner(line);
time = Double.parseDouble(s.next());
flux = Double.parseDouble(s.next());
if(s.hasNext())
weight = Double.parseDouble(s.next());
else
weight = 1;
}
/**
* @return time
*/
public double getTime() {
return time;
}
/**
* @return flux
*/
public double getFlux() {
return flux;
}
/**
* @return weight
*/
public double getWeight() {
return weight;
}
/**
* Change the time value of this DataPoint
* @param newTime is the value of the new time for this DataPoint
*/
public void changeTime(double newTime) {
time = newTime;
}
/**
* Change the flux value of this DataPoint
* @param newFlux is the value of the new flux for this DataPoint
*/
public void changeFlux(double newFlux) {
flux = newFlux;
}
/**
* Change the weight value of this DataPoint
* @param newWeight is the value of the new weight for this DataPoint
*/
public void changeWeight(double newWeight) {
weight = newWeight;
}
/**
* Overrides toString() method in Object class.
* Returns DataPoint to string in format: #TIME# #FLUX# #WEIGHT# (no labels)
*/
public String toString() {
return time + "\t" + flux + "\t" + weight;
}
/**
* Print DataPoint to string in format: Time: #### Flux: #### Weight: ####
*/
public String toLabeledString() {
return "Time: " + time + " Flux: " + flux + " Weight: " + weight;
}
/**
* Returns true if data points are at same time and have same flux and same weight.
* False otherwise.
*/
public boolean equals(Object obj) {
if(obj instanceof DataPoint) {
DataPoint temp = (DataPoint) obj;
if(temp.getFlux() == flux && temp.getTime() == time && temp.getWeight() == weight)
return true;
}
return false;
}
/**
* Perform a deep copy of a data point.
* @return a deep copy of a data point.
*/
public DataPoint deepCopy() {
DataPoint returnCopy = new DataPoint();
returnCopy.time = this.time;
returnCopy.flux = this.flux;
returnCopy.weight = this.weight;
return returnCopy;
}
}