Skip to content

Commit

Permalink
PositionState checks a range instead of just the requested position
Browse files Browse the repository at this point in the history
  • Loading branch information
minhn02 committed Feb 19, 2019
1 parent 9a761b4 commit 7e9a4f5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class Conflict<OT, CT>(

abstract fun invert(): Conflict<CT, OT>

abstract fun isRequestConflicting(request: Request<OT>, conflictingCondition: Condition<CT>, currentOriginCondition: Condition<OT>): Boolean
abstract fun isRequestConflicting(request: Request<OT>, currentConflictingCondition: Condition<CT>, currentOriginCondition: Condition<OT>): Boolean

abstract fun isConditionConflicting(originCondition: Condition<OT>, conflictingCondition: Condition<CT>): Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class PositionBasedConflict(

}

override fun isRequestConflicting(request: Request<Double>, conflictingCondition: Condition<Double>, currentOriginCondition: Condition<Double>): Boolean {
var range: Range<Double> = Range.between(currentOriginCondition.getConditionValue(), request.condition.getConditionValue())
var conflictingRange: Range<Double> = Range.between((conflictingCondition as PositionBasedCondition).range.minimum,
conflictingCondition.range.maximum)
override fun isRequestConflicting(request: Request<Double>, currentConflictingCondition: Condition<Double>, currentOriginCondition: Condition<Double>): Boolean {
val range: Range<Double> = Range.between(currentOriginCondition.getConditionValue(), request.condition.getConditionValue())
val conflictingRange: Range<Double> = Range.between((currentConflictingCondition as PositionBasedCondition).range.minimum,
currentConflictingCondition.range.maximum)

return range.isOverlappedBy(conflictingRange)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.team2073.common.mediator.condition.StateBasedCondition
import com.team2073.common.mediator.request.Request
import com.team2073.common.mediator.subsys.ColleagueSubsystem
import com.team2073.common.mediator.subsys.SubsystemStateCondition
import org.apache.commons.lang3.Range

class PositionStateBasedConflict<T : Enum<T>>(
val originSubsystemPS: Class<out ColleagueSubsystem<Double>>,
Expand All @@ -22,9 +23,10 @@ class PositionStateBasedConflict<T : Enum<T>>(
return StateBasedCondition(resolveState)
}

override fun isRequestConflicting(request: Request<Double>, conflictingCondition: Condition<SubsystemStateCondition<T>>, currentOriginCondition: Condition<Double>): Boolean {
return conflictingCondition.isInCondition(conflictingConditionPS)
&& originCondition.isInCondition(request.condition)
override fun isRequestConflicting(request: Request<Double>, currentConflictingCondition: Condition<SubsystemStateCondition<T>>, currentOriginCondition: Condition<Double>): Boolean {
val travelRange: Range<Double> = Range.between(currentOriginCondition.getConditionValue(), request.condition.getConditionValue())
return currentConflictingCondition.isInCondition(conflictingConditionPS)
&& travelRange.contains(originConditionPS.getConditionValue())
}

override fun invert(): Conflict<SubsystemStateCondition<T>, Double> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class StateBasedConflict<OT : Enum<OT>, CT : Enum<CT>>(
return StateBasedConflict(conflictingSubsystemS, conflictingConditionS, originSubsystemS, originConditionS, inverseResolveState, resolveState)
}

override fun isRequestConflicting(request: Request<SubsystemStateCondition<OT>>, conflictingCondition: Condition<SubsystemStateCondition<CT>>, currentOriginCondition: Condition<SubsystemStateCondition<OT>>): Boolean {
return originCondition.isInCondition(request.condition) && conflictingCondition.isInCondition(conflictingConditionS)
override fun isRequestConflicting(request: Request<SubsystemStateCondition<OT>>, currentConflictingCondition: Condition<SubsystemStateCondition<CT>>, currentOriginCondition: Condition<SubsystemStateCondition<OT>>): Boolean {
return originCondition.isInCondition(request.condition) && currentConflictingCondition.isInCondition(conflictingConditionS)
}

override fun isConditionConflicting(originCondition: Condition<SubsystemStateCondition<OT>>, conflictingCondition: Condition<SubsystemStateCondition<CT>>): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,8 @@ class StatePositionBasedConflict<T : Enum<T>>(val originSubsystemPS: Class<out C

}

override fun isRequestConflicting(request: Request<SubsystemStateCondition<T>>, conflictingCondition: Condition<Double>, currentOriginCondition: Condition<SubsystemStateCondition<T>>): Boolean {
var conflictCase = false
var originCase = false

if (conflictingCondition.isInCondition(conflictingConditionPS)) {
conflictCase = true
}
if (originCondition.isInCondition(request.condition)) {
originCase = true
}

return originCase && conflictCase
override fun isRequestConflicting(request: Request<SubsystemStateCondition<T>>, currentConflictingCondition: Condition<Double>, currentOriginCondition: Condition<SubsystemStateCondition<T>>): Boolean {
return request.condition.isInCondition(originCondition) && currentConflictingCondition.isInCondition(conflictingConditionPS)
}

override fun invert(): Conflict<Double, SubsystemStateCondition<T>> {
Expand Down

0 comments on commit 7e9a4f5

Please sign in to comment.