Chaitanya Srikakolapu
BAN USERpackage main.rules;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class RulesExecute {
public static void main(String[] args){
RulesExecute executor = new RulesExecute();
RulesTable table = new RulesTable();
RuleRecord r = new RuleRecord();
r.rule1="A1";r.rule2="B2";r.rule3="C3"; r.result=40;
table.rules.add( r );
r = new RuleRecord();
r.rule1="A1";r.rule2="B1";r.rule3="C1"; r.result=20;
table.rules.add( r );
r = new RuleRecord();
r.rule1="A2";r.rule2="B2";r.rule3="C2"; r.result=10;
table.rules.add( r );
r = new RuleRecord();
r.rule1="A1";r.rule2="B1";r.rule3="C1"; r.result=20;
table.rules.add( r );
r = new RuleRecord();
r.rule1="*";r.rule2="B1";r.rule3="*"; r.result=20;
table.rules.add( r );
r = new RuleRecord();
r.rule1="A5";r.rule2="B2";r.rule3="*"; r.result=10;
table.rules.add( r );
List<RuleRecord> tempList = new ArrayList<>( table.rules );
boolean ambiguous = table.rules.stream().anyMatch( record->{
tempList.remove( record );
return tempList.stream().filter( other->{
if(executor.ruleMatch( other.rule1, record.rule1 ) &&
executor.ruleMatch( other.rule2, record.rule2 ) &&
executor.ruleMatch( other.rule3, record.rule3 ) &&
other.result != record.result){
return true;
}else{
return false;
}
} ).collect(Collectors.toList()).size() > 0;
} );
System.out.print( ambiguous );
}
public boolean ruleMatch(String rule1, String rule2){
if(rule1.equals( "*" ) || rule2.equals( "*" )){
return true;
}else if(rule1.equals( rule2 )){
return true;
}
return false;
}
}
I think getCircle already returns center point and radius right. Say it returns center point as (p,q), and radius = r
After finding the triplet, for each other point in the list
square-root of ((x-p)^2 + (y-q)^2) == radius will give the points in that circle perimeter.
Buffer all these points in a list.
Repeat above for other triplet combinations, but skip the combination where all three points are already part of a circle identified.
- Chaitanya Srikakolapu November 29, 2019