Re: [ceylon-users] Hierachial enum

38 views
Skip to first unread message
Message has been deleted

Gavin King

unread,
Aug 27, 2016, 6:14:28 AM8/27/16
to ceylon...@googlegroups.com
I don't understand your goal here. What problem are you trying to solve?

On Sat, Aug 27, 2016 at 12:09 PM, Wojciech Potiopa
<wojciech...@gmail.com> wrote:
> Hi, i want to create an enum which will contain other enum and then i would
> be able to call like this
> EnumTwoObj enumTwoObj=enumOneObj.someContainer.enumTwoObj;
>
> Example:
>
> import ceylon.test {
> test
> }
>
> shared class EnumTest() {
>
> shared test
> void hierarchyEnumTest() {
> EnumTwo oneId=one.properties.id;
> EnumTwo oneName=one.properties.name;
>
> }
> }
>
> abstract class EnumOne() of one | two {}
> object two extends EnumOne() {}
> object one extends EnumOne() {
> // shared formal SomeContainer<EnumTwo> properties => ??????? ;
> }
>
> abstract class EnumTwo() of name | id {}
> object id extends EnumTwo() {}
> object name extends EnumTwo() {}
>
> Is this possible ?
> Cheers Wojciech
>
> --
> You received this message because you are subscribed to the Google Groups
> "ceylon-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ceylon-users...@googlegroups.com.
> To post to this group, send email to ceylon...@googlegroups.com.
> Visit this group at https://groups.google.com/group/ceylon-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ceylon-users/036fed71-d25a-4c5d-905c-f8a689074310%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Gavin King
ga...@ceylon-lang.org
http://profiles.google.com/gavin.king
http://ceylon-lang.org
http://hibernate.org
http://seamframework.org
Message has been deleted

Gavin King

unread,
Aug 27, 2016, 8:39:27 AM8/27/16
to ceylon...@googlegroups.com
How about:

shared object one {
shared class Properties {
shared new name {}
shared new id {}
}
}

Or even just

shared object one {
shared object properties {
shared object name {}
shared object id {}
}
}

Or do you desperately need them to be enumerated for some reason?


On Sat, Aug 27, 2016 at 2:22 PM, Wojciech Potiopa
<wojciech...@gmail.com> wrote:
> Hi Gavin thanks for answering, take a look at this
> https://github.com/jmurty/java-xmlbuilder
>
> Let have something like this with data presented as literals:
>
> XMLBuilder2.create("Doc").e("one").a("name", "Some value");
>
>
>
> I would like to present data not as literals but as constants, and to have
> changes proof code
>
> XMLBuilder2.create("Doc").e(one.string).a(one.properties.name.string,"Some
> Value")
>
>
> If i would have ten references to
>
> .e("one").a("name", "Some value");
>
> I can't refactore it properly and it's bug prone.
>
>
> Let say want to change one element string representation from "one" to
> "type".
> Then i just refine string property from one object
> String string = "type"
>
> In literal representation must to change every line...
>
> And now i want to have hierarchy to be able to do the same with second level
> objects in this case EnumTwo instances and be sure to referencing correct
> object not just name, because, there can be other representations in my Xml
> model with other name instances of other types. So first it would hard to
> import them and use them in the same file and secondly it is encapsulated
> better and less error prone when changes occurs.
> https://groups.google.com/d/msgid/ceylon-users/42800e68-5c03-4e6e-8c3a-d289d294c810%40googlegroups.com.

Gavin King

unread,
Aug 27, 2016, 8:45:24 AM8/27/16
to ceylon...@googlegroups.com
Perhaps something like this:



shared abstract class EnumOne() of one|two {}

shared object one extends EnumOne() {
shared object properties {
shared Properties name = Properties.name;
shared Properties id = Properties.id;
}
}
shared object two extends EnumOne() {}

shared class Properties of name|id {
Reply all
Reply to author
Forward
Message has been deleted
0 new messages