Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [smila-dev] new datamodel iterating thru Map and Seq

> asXX

yes, I'll do

> But keep in mind that this also assumes internal knowledge by the caller... the cast/invalidtype exception is just moved from outside to inside.
exactly! this then is our internal code a user doesn't need to know/think about what (impl.) types may I cast but only what types are semantically used where.


Thomas Menzel @ brox IT-Solutions GmbH


-----Original Message-----
From: smila-dev-bounces@xxxxxxxxxxx [mailto:smila-dev-bounces@xxxxxxxxxxx] On Behalf Of Andreas.Weber@xxxxxxxxxxxxx
Sent: Montag, 28. März 2011 13:36
To: smila-dev@xxxxxxxxxxx
Subject: Re: [smila-dev] new datamodel iterating thru Map and Seq

1a)  ok, but I'd prefer the method names: asValue(), asMap(), asSeq(). Looks more stringent to me, cause we already have the as-Methods on Value level.
But keep in mind that this also assumes internal knowledge by the caller... the cast/invalidtype exception is just moved from outside to inside.

2)  +1

Cheers,
 Andreas

-----Ursprüngliche Nachricht-----
Von: smila-dev-bounces@xxxxxxxxxxx [mailto:smila-dev-bounces@xxxxxxxxxxx] Im Auftrag von Thomas Menzel
Gesendet: Montag, 28. März 2011 12:27
An: Smila project developer mailing list
Betreff: [smila-dev] new datamodel iterating thru Map and Seq

hi,

a little proposal regarding the new DM:

motivation/use case:
often a seq is used to store N objects of the same type, so I chose the seq as the prim. use case here but it applies to Maps as well.
with the current DM iterating thru a seq is more cumbersome than it needs to be.

when iterating thru a seq. we  need code like so:

    for (Any field : indexFields) {
      String value = ((Value) field).asString();
      ...
    }

or

    for (int i = 0; i < indexFields.size(); i++) {
      final String stringValue = indexFields.getStringValue(i);
      ...
    }

which is not so nice b/c 
- it casts the type, assuming internal knowledge not visible thru the API.
- the new for(type : iterable) is better to read/less error prone/better template-able  than the indexed version


proposal 1
I propose to either provide 
a) Any.getValue/Map/Seq() methods OR
b) push the asXXX methods from Value to Any

for invalid cases we just throw the InvalidValTypeEx.

the new code would look like so depending on the chosen solution.
    
    for (Any any : indexFields) {
      String value = any.getValue().asString();
      ...
    }

    for (Any any : indexFields) {
      String value = any.asString();
      ...
    }

moving the asXXX methods into the any interface results in less verbose code but kind of blurs the intentional design of having diff. object types.

proposal 2
in addition I suggest common converter methods in a util class or at the Seq/Map types to convert all contained any objects into one of the basic types String, Long, ...

e.g. List<String> : Map.asStrings ();


if u give me a +1 i would impl 1.a) and 2.


Thomas Menzel @ brox IT-Solutions GmbH


_______________________________________________
smila-dev mailing list
smila-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/smila-dev
_______________________________________________
smila-dev mailing list
smila-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/smila-dev


Back to the top