java – Abstraction of references to getter and setter methods for test purposes

Is the following code easy to understand? If not, how should it be changed to be more understandable? The purpose of this is to reduce the similar code in unit tests. This avoids repeating lines for calling getters, setters, and equal checks.

/ **
* Example of string for tests.
* /
private static final String STRING_EXAMPLE = "stringExample";

/ **
* Check that a getter and a setter are consistent.
* /
@Test
public void testGetterSettersForA () {
A a = new A ();
assertGetterSetterConsistent (STRING_EXAMPLE, a :: setC, a :: getC);
}

/ **
* Assert that a getter and a setter are consistent.
* @param enters the object to set.
* @param setter the setter.
* @param getter the getter.
* /
private static  void assertGetterSetterConsistent (T input, consumer installer, supplier getter) {
consistent boolean = isSetConsistentToGet (input, setter, getter);
assertTrue ("Getter and Setter must be consistent.", consistent);
}

/ **
* Check if the object being set is the same as the object being obtained.
* @param enters the object to set.
* @param setter the setter.
* @param getter the getter.
* @return if the object being set is the same as the object being obtained.
* /
private static  boolean isSetConsistentToGet (T entry, Consumer installer, supplier getter) {
setter.accept (input);
T getValue = getter.get ();
return areEqual (input, getValue);
}

/ **
* Null safe check if two objects are equal.
* @param first the first object.
* @param second the second object.
* @return if the two objects are equal.
* /
private static  boolean areEqual (First Object, Second Object) {
if (first == null) {
return second == null;
}
return first.equals (second);
}

/ **
* Class to test a getter and a setter.
* /
final static class A private {
/ **
* Variable named c.
* /
private channel c;

/ **
* Get c.
* @ back c.
* /
public String getC () {
return c;
}

/ **
* Set c.
* @param c the value to set.
* /
public void setC (String c) {
this.c = c;
}
}

object-oriented – Is it a good idea to define the getter and setter defined in c #?

I've tried this way to define a custom defined property, but I'm wondering how to handle if one of the dependent properties has a null value.

Public class ObtainedMarksDetail
{
private decimal? _percentage;
public decimal? TheTotalTheory {get; together; }
public decimal? PracticalTotal {get; together; }
public decimal? TheoryFullMarksTotal {get; together; }
public decimal? PracticalFullMarksTotal {get; together; }
public decimal? TheoryPassMarksTotal {get; together; }
public decimal? PracticalPassMarksTotal {get; together; }

public decimal? TotalPercentage
{

get {return _percentage = (TheoryTotal + PracticalTotal) / (TheoryFullMarksTotal + PracticalFullMarksTotal); }
set {_percentage = value; }
}

}

My question is how to set the default value for the dependent properties, that is, I tried this way, but that indicates an error.

    public decimal? TheTotalTheory {get; together; } = 0.0;

Also what else from other ThéorieTotal throws null value how can i handle in the composite getter of the property TotalPercentage

        public decimal? TotalPercentage
{

get {return _percentage = (TheoryTotal + PracticalTotal) / (TheoryFullMarksTotal + PracticalFullMarksTotal); }
set {_percentage = value; }
}

java – Is a setter with a compound object as a parameter a better parameter or separate parameters for each parameter of the compound object?

I have two ideas on how to proceed with an availability class, but I'm not sure which one is the best.

Public class TimeRange {
private time stamp startTime;
private endTime timestamp;

public TimeRange () {
// set default values
}
// appropriate getters
// setters
public void setStartTime (Timestamp startTime) {
this.startTime = startTime;
}

public void setEndTime (Timestamp endTime) {
this.endTime = endTime;
}
// a code that validates the object is in a valid state.
}

First idea:

public class WeeklyAvailabilities {
private TimeRange mondaySlot;
private TimeRange tuesdaySlot;
Private TimeRange Wednesday to Wednesday;
private TimeRange thursdaySlot;
private TimeRange fridaySlot;
private TimeRange saturdaySlot;
private TimeRange sundaySlot;

public WeeklyAvailabilities () {
// set default values
}
// getters and others
public void setMondayStartTime (Start timestamp) {
mondaySlot.setStartTime (start);
}

public void setMondayEndTime (end of timestamp) {
mondaySlot.setEndTime (end);
}
// continue the pattern for all slots
}

Second idea:

public class WeeklyAvailabilities {
private TimeRange mondaySlot;
private TimeRange tuesdaySlot;
Private TimeRange Wednesday to Wednesday;
private TimeRange thursdaySlot;
private TimeRange fridaySlot;
private TimeRange saturdaySlot;
private TimeRange sundaySlot;

public WeeklyAvailabilities () {
// set default values
}
// getters and others
public void setMondaySlot (TimeRange mondaySlot) {
this.mondaySlot = mondayaySlot;
}

// continue the pattern for all slots
}

I am in conflict because the first idea does not require the creation of a new object each time, while the second idea would require something of that kind. Really, I wondered if I could know which one is the best or if there could be a third option that I completely ignore.