Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » xcore derived list of objects(Why is it impossible to get Object[ ] out of a derived attribute? Sample Code included)
xcore derived list of objects [message #1139790] Tue, 15 October 2013 21:13 Go to next message
Tim Hinkes is currently offline Tim Hinkes
Messages: 4
Registered: October 2013
Junior Member
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?

Or did i get something wrong for what one should use the derived directive?

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?!

Thank you in advance
Re: xcore derived list of objects [message #1140023 is a reply to message #1139790] Wed, 16 October 2013 00:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25946
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
Re: xcore derived list of objects [message #1140423 is a reply to message #1140023] Wed, 16 October 2013 06:46 Go to previous message
Tim Hinkes is currently offline Tim Hinkes
Messages: 4
Registered: October 2013
Junior Member
Thank you
It works Smile

Previous Topic:Switch between editable and readonly for an EMF property
Next Topic:EMF disable to open old model versions
Goto Forum:
  


Current Time: Wed Jul 30 17:20:00 EDT 2014

Powered by FUDForum. Page generated in 0.10776 seconds