对于Boss类,我需要所有销售价值最高的代理商的名称(例如:foreach代理商,如果他有,请选择代理商名称)
max(foreach command, total = total + price of the product * quantity from command).
我如何在OCL中执行此操作?
答案 0 :(得分:2)
如果您认为自己位于模型的根部(特别是没有上下文),那么为了选择20
第一个顶级代理商:
Agent.allInstances()->sortedBy(- sale->collect(quantity*product.price)->sum())->subSequence(1, 20)
来自Boss
个实例:
self.workers->sortedBy(- sale->collect(quantity*product.price)->sum())->subSequence(1, 20)
请求背后的想法是(对于第一个):
Agent.allInstances()
)...->sortedBy(...)
)... sale->...->sum()
)quantity*product.price
)...sale->collect(...)
)sum
一个)中反过来将顶部置于第一个位置(... - sale->collect()->sum()...
)...->subSequence(1,X)
)编辑>
关于关联类导航的详细信息(来自" OCL规范",第21页)
要指定关联类的导航(示例中的作业和结婚),OCL使用点和名称 协会类
遵循规范的早期版本,Association Class
名称被视为小写,在更高版本中,名称不受影响。
EDIT2>
为了获得更高的分数和代理人姓名达到这个最高分:
let score : Integer = -(self.workers->collect(sale->collect(quantity*product.price)->sum())->sortedBy(i | -i)->first())
in self.workers->select(sale->collect(quantity*product.price)->sum() = score).name
第一个让我们选择较高的分数(收集所有分数,按相反顺序对它们进行排序并选择第一个元素),然后选择所有分数等于先前计算得分的工人。