FRQ 1
FRQ 1 had us working with 2D arrays, which could be useful for multiple aspects of our project. Though we haven't gotten to this part yet, we will be able to use 2D arrays to store various datatypes when implementing the stapplet functions of our project. Checking for duplicate data could also be useful in these stapplet functions when adding large groups of data at once.
@Data // Annotations to simplify writing code (ie constructors, setters)
@NoArgsConstructor
@AllArgsConstructor
@Entity // Annotation to simplify creating an entity, which is a lightweight persistence domain object. Typically, an entity represents a table in a relational database, and each entity instance corresponds to a row in that table.
public class QrCode {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ElementCollection
private List<LinkFreq> linkFreqs = new ArrayList<>();
public void addLink(LinkFreq linkFreq ){
linkFreqs.add(linkFreq);
return;
}
}
This code is also a form of 2d array in which nested lists are used. For example, the linkFreqs is an association between a link and a frequency and there is a list of linkfreq objects within each qr code object.
FRQ 2
The FRQ had a branching logic chain, in which one answer led to false and another led to a second if statement. I also utilized this concept when accepting the QR code on the frontend and choosing where to redirect someone. For example, the following code
function getLink(){
return fetchId().then(obj => {
var num = Math.random()
var intervals = [];
for (var i = 0; i < obj.linkFreqs.length; i ++){
if (i == 0){
intervals.push(obj.linkFreqs[i].frequency)
}
else {
console.log(intervals)
intervals.push(intervals[i - 1] + obj.linkFreqs[i-1].frequency)
}
}
for (i in intervals){
console.log(num);
console.log(intervals[i])
if (num < intervals[i]){
link = obj.linkFreqs[i].link;
return link
}
}
})
}
searches through multiple intervals to check if the value is within the given interval and redirect to the correct link.
Another focus of this FRQ was creating a POJO object, like the QR code object I created here. Though in this case spring actually creates all of the necessary constructors, getters and setters through the annotations.
@Data // Annotations to simplify writing code (ie constructors, setters)
@NoArgsConstructor
@AllArgsConstructor
@Entity // Annotation to simplify creating an entity, which is a lightweight persistence domain object. Typically, an entity represents a table in a relational database, and each entity instance corresponds to a row in that table.
public class QrCode {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ElementCollection
private List<LinkFreq> linkFreqs = new ArrayList<>();
public void addLink(LinkFreq linkFreq ){
linkFreqs.add(linkFreq);
return;
}
}
FRQ 3
This FRQ actually reminded me of what we learned about when learning how to save images into base64, where if the image is primarily a single color you can save that color as a variable and then just record how many pixels have that color in the row. I could see this being useful in our project again for the stapplet functions, where if we are storing large groups of data which primarily contain 1 or 2 of a single datatype, it could be more efficient to store the data by storing the value and number of numbers rather than storing each number individually.
This is similar to the example I could use for FRQ 1 as well, but another example of similar concept is my response object for my qrcode creation api call.
@Data
public class QrCodeRequest {
private List<String> links;
private List<Double> frequencies;
}
This object includes two lists which match to the lists passed through to the function when the API is called.
FRQ 4
FRQ 4 had us working with interfaces, this was actually a concept I never really understood before now, but looking through my project I've found instances of using interfaces throughout the project. For example, the following code
@GetMapping("/{id}")
@Transactional
public ResponseEntity<QrCode> getQrCode(@PathVariable long id) {
Optional<QrCode> optional = repository.findById(id);
if (optional.isPresent()) { // Good ID
QrCode qrCode = optional.get(); // value from findByID
Hibernate.initialize(qrCode.getLinkFreqs());
return new ResponseEntity<>(qrCode, HttpStatus.OK); // OK HTTP response: status code, headers, and body
}
// Bad ID
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
includes the "findById" method of the repository class. This method is originally defined within the CrudRepository interface which allows us to customize this method based on differing repository classes.
FRQ 1
FRQ 1 had us working with 2D arrays, which could be useful for multiple aspects of our project. Though we haven't gotten to this part yet, we will be able to use 2D arrays to store various datatypes when implementing the stapplet functions of our project. Checking for duplicate data could also be useful in these stapplet functions when adding large groups of data at once.
This code is also a form of 2d array in which nested lists are used. For example, the linkFreqs is an association between a link and a frequency and there is a list of linkfreq objects within each qr code object.
FRQ 2
The FRQ had a branching logic chain, in which one answer led to false and another led to a second if statement. I also utilized this concept when accepting the QR code on the frontend and choosing where to redirect someone. For example, the following code
searches through multiple intervals to check if the value is within the given interval and redirect to the correct link.
Another focus of this FRQ was creating a POJO object, like the QR code object I created here. Though in this case spring actually creates all of the necessary constructors, getters and setters through the annotations.
FRQ 3
This FRQ actually reminded me of what we learned about when learning how to save images into base64, where if the image is primarily a single color you can save that color as a variable and then just record how many pixels have that color in the row. I could see this being useful in our project again for the stapplet functions, where if we are storing large groups of data which primarily contain 1 or 2 of a single datatype, it could be more efficient to store the data by storing the value and number of numbers rather than storing each number individually.
This is similar to the example I could use for FRQ 1 as well, but another example of similar concept is my response object for my qrcode creation api call.
This object includes two lists which match to the lists passed through to the function when the API is called.
FRQ 4
FRQ 4 had us working with interfaces, this was actually a concept I never really understood before now, but looking through my project I've found instances of using interfaces throughout the project. For example, the following code
includes the "findById" method of the repository class. This method is originally defined within the CrudRepository interface which allows us to customize this method based on differing repository classes.