Skip to main content
Rollback to Revision 2
Source Link
Toby Speight
  • 88.7k
  • 14
  • 104
  • 327

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnAgefilterBasedOnConsistAge(employeeJSONString) && 
           filterBasedOnGenderfilterBasedOnConsistGender(employeeJSONString) &&
           filterBasedOnNationalityfilterBasedOnConsistNationality(employeeJSONString) &&
           filterBasedOnIsHandicapfilterBasedOnConsistHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // retrieveconverts additionaldomainObject employeeto fieldsa usingformatted employeestring, objectit's a business requirement
}

There are five-line methods, that are linked using logical AND. But the problem here is, the chaining is looking clean. is there a way to improve this logic?

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnAge(employeeJSONString) && 
           filterBasedOnGender(employeeJSONString) &&
           filterBasedOnNationality(employeeJSONString) &&
           filterBasedOnIsHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // retrieve additional employee fields using employee object
}

There are five-line methods, that are linked using logical AND. But the problem here is, the chaining is looking clean. is there a way to improve this logic?

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnConsistAge(employeeJSONString) && 
           filterBasedOnConsistGender(employeeJSONString) &&
           filterBasedOnConsistNationality(employeeJSONString) &&
           filterBasedOnConsistHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // converts domainObject to a formatted string, it's a business requirement
}

There are five-line methods, that are linked using logical AND. But the problem here is, the chaining is looking clean. is there a way to improve this logic?

deleted 41 characters in body
Source Link

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnConsistAgefilterBasedOnAge(employeeJSONString) && 
           filterBasedOnConsistGenderfilterBasedOnGender(employeeJSONString) &&
           filterBasedOnConsistNationalityfilterBasedOnNationality(employeeJSONString) &&
           filterBasedOnConsistHandicapfilterBasedOnIsHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // converts domainObject to aretrieve formattedadditional string,employee it'sfields ausing businessemployee requirementobject
}

There are five-line methods, that are linked using logical AND. But the problem here is, the chaining is looking clean. is there a way to improve this logic?

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnConsistAge(employeeJSONString) && 
           filterBasedOnConsistGender(employeeJSONString) &&
           filterBasedOnConsistNationality(employeeJSONString) &&
           filterBasedOnConsistHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // converts domainObject to a formatted string, it's a business requirement
}

There are five-line methods, that are linked using logical AND. But the problem here is, the chaining is looking clean. is there a way to improve this logic?

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnAge(employeeJSONString) && 
           filterBasedOnGender(employeeJSONString) &&
           filterBasedOnNationality(employeeJSONString) &&
           filterBasedOnIsHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // retrieve additional employee fields using employee object
}

There are five-line methods, that are linked using logical AND. But the problem here is, the chaining is looking clean. is there a way to improve this logic?

added 22 characters in body
Source Link

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnConsistAge(employeeJSONString) && 
           filterBasedOnConsistGender(employeeJSONString) &&
           filterBasedOnConsistNationality(employeeJSONString) &&
           filterBasedOnConsistHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // converts domainObject to a formatted string, it's a business requirement
}

filterBasedOnConsist* There are five-line methods, that are linked using logical AND. Above several AND conditions doesn't lookBut the problem here is, the chaining is looking clean. ifis there a way to improve this logic?

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnConsistAge(employeeJSONString) && 
           filterBasedOnConsistGender(employeeJSONString) &&
           filterBasedOnConsistNationality(employeeJSONString) &&
           filterBasedOnConsistHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // converts domainObject to a formatted string, it's a business requirement
}

filterBasedOnConsist* are five-line methods. Above several AND conditions doesn't look clean. if there a way to improve this logic?

I have a Predicate which takes employee object.

Predicate<Employee> getPredicate() {
    return emp -> filter(emp);
}

Now the filter method is very complex, it calls four other methods which returns true/false if all the conditions are true, the predicate will return true.

private boolean filter(Employee employee) {
    String employeeJSONString = employeeToString(employee);
    return filterBasedOnConsistAge(employeeJSONString) && 
           filterBasedOnConsistGender(employeeJSONString) &&
           filterBasedOnConsistNationality(employeeJSONString) &&
           filterBasedOnConsistHandicap(employeeJSONString);
}

private String employeeToString(Employee employee) {
    // converts domainObject to a formatted string, it's a business requirement
}

There are five-line methods, that are linked using logical AND. But the problem here is, the chaining is looking clean. is there a way to improve this logic?

Tweeted twitter.com/StackCodeReview/status/1242828736812257285
Became Hot Network Question
Source Link
Loading