Skip to main content


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] Wed, 16 October 2013 01:13 Go to next message
Tim Hinkes is currently offline Tim HinkesFriend
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 04:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
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/
Re: xcore derived list of objects [message #1140423 is a reply to message #1140023] Wed, 16 October 2013 10:46 Go to previous message
Tim Hinkes is currently offline Tim HinkesFriend
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: Thu Apr 25 20:57:36 GMT 2024

Powered by FUDForum. Page generated in 0.03356 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top