|
Re: xcore derived list of objects [message #1140023 is a reply to message #1139790] |
Wed, 16 October 2013 04:59 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Tim,
Comments below.
On 16/10/2013 4:48 AM, Tim Hinkes wrote:
> Hello,
>
> i'm very new to emf/xcore, but i think it could be a great advantage
> for my coding workflow.
>
> Today i encountered a problem.
>
>
> class LimitOrder
> {
> Currency currency
> BigDecimal price
> BigDecimal amount
> OrderType orderType
> refers OpenOrder order opposite limitOrder
> }
>
> class OrderBook
> {
>
> contains LimitOrder[] limitOrders
> derived LimitOrder[] askList get
> {
> return limitOrders.filter[it.orderType == OrderType::ASK].toEList
>
> }
>
>
> Could someone point out for me why it is impossible to get a
> List/Collection of actual Objects out of a derived Attribute, but it
> is fine to get a List of Datatypes (derived someFooDatatype[] ask
> get{...}) as a derived Attribute?
What you show is a derived reference and needs a "refers" keyword.
>
> Or did i get something wrong for what one should use the derived
> directive?
You have to be more careful with multi-valued derived values because the
list returned by it must implement internal APIs, so there are
alternatives with the first one being not quite correct (but you'll only
noticed that occasionally at runtime), the second one being correct but
complex (https://bugs.eclipse.org/bugs/show_bug.cgi?id=377103), and the
third one generating the same Java API and being correct (but not
providing a reflectively visible feature.
refers derived LimitOrder[] askList get
{
return limitOrders.filter[it.orderType == OrderType::ASK].toEList
}
refers derived LimitOrder[] askList2 get
{
val result = limitOrders.filter[it.orderType == OrderType::ASK]
return new UnmodifiableEList(this as InternalEObject,
ExamplePackage$Literals::ORDER_BOOK__ASK_LIST2, result.size,
result.toList.toArray)
}
op LimitOrder[] getAskList3()
{
return limitOrders.filter[it.orderType == OrderType::ASK].toEList
}
>
> I have a big list of Orders, there orders have the types
> ASK/BID(Enums) But instead of saving two seperate lists in the
> OrderBook class, i want to get these Orders as Lists sorted by ask or
> bid. I thoght this is it for what there are derived attributes
> Like getting the Age of a Person without saving the age, but saving
> the birthday?!
Just keep in mind the distinction between attributes and references
where the former must refer to a data type (defined with a type or enum
keywork) and the later must refer to a class (defined with a class or
interface keyword).
>
> Thank you in advance
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03419 seconds