OCL group by element attribute - acceleo

In Acceleo I have an OrderedSet of objects, where each object has a string as attribute.
I want to get a container(e.g. OrderedSet) of those strings, where each string is unique.

First, I collect all the strings into an collection ->collect(attribute). Then I convert to an Ordered Set ->asOrderedSet(). This will remove all duplicates.

A String is an (E)DataType rather than an (E)Class instance consequently it has no (e)container. You could do a total model search for all String-typed attributes and check their values - very expensive. Much better to revisit the OrderedSet construction so that the 'container' knowledge is not discarded requiring rediscovery.

Related

VSTO Outlook: Iterate over Outlook.OlDefaultFolders enumeration and store entry IDs in a list

I would like to iterate over Outlook.OlDefaultFolders enumeration and get the ID entry for each default Outlook folder and store them in a list of Entry IDs. How can I achieve this?
That sounds like a generic .net programming question and the answer depends on the .net target version you use for the product. There are several ways to iterate over the enumeration values, you can find all of them describes in the How to enumerate an enum thread. For exaple:
foreach (OlDefaultFolders defaultFolder in (OlDefaultFolders[]) Enum.GetValues(typeof(OlDefaultFolders)))
{
folder = namespace.GetDefaultFolder(defaultFolder);
}
Enumerations provide a convenient way to work with sets of related constants, and to associate constant values with names. To iterate through an enumeration, you can move it into an array using the GetValues method. You could also iterate through an enumeration using a foreach statement, using the GetNames or GetValues method to extract the string or numeric value.

Data structure for storing list of boolean values mapped to string names in vb

What would be a good (in terms of speed, code safety etc.) data structure for storing boolean values mapped to a list of string names vb? The strings are a list of length 22 with distinct names like "A201" "A202" etc.
<string, True>
<string, False>
<string, True>
<string, False>
I then need to loop through this list. Speed is essential as each iteration needs to be as quick as possible.
I was thinking, alternative to using a data structure, I could place the 22 strings inside an array and then set them to nothing, and loop through them to see which ones are not set to nothing, then process based only on the strings that are not set to nothing. I was just wondering whether a particular data structure would be a better solution and how the solutions would compare?
Thanks for the help.
I think I could remove the string from the original list for the ones that don't need any more work, then pass the updated list (containing the ones that need more work) to the re-loop when the first loop through the list is completed.

Using except operator with property condition

I have two lists with different objects. Both objects have a string property name that I need for comparing.
I need to know what values in list A are not contained in list B based on the name property.
Would the except operator work for this case?
What would be a optimal way to achive this in Linq?
Except operator removes items based on object equality. Although you could shoehorn your scenario into Except by passing an "equality comparer" that pays attention only to Name property, the resultant code would be hard to understand.
A better approach is to make a set of names that you wish to exclude, and use that set in your query:
var excludedNames = new HashSet<string>(listB.Select(item => item.Name));
var result = listA.Where(item => !excludedNames.Contains(item.Name)).ToList();

How to check whether a value exists in a Ruby structure?

I used to have a series of independent arrays (e.g. name(), id(), description() ). I used to be able to check whether a value existed in a specific array by doing name.include?("Mark")
Now that I moved to a MUCH MORE elegant way to manage different these independent arrays (here for background: How do I convert an Array with a JSON string into a JSON object (ruby)) I am trying to figure out how I do the same.
In short I put all the independent arrays in a single structure so that I can reference the content as object().name, object().id, object().description.
However I am missing now how I can check whether the object array has a value "Mark" in its name structure.
I have tried object.name.include?("Mark") but it doesn't quite like it.
I have also tried to use has_value?but that doesn't seem to be working either (likely because it used to be an hash before I imported it into the structure but right now is no longer a hash - see here: How do I convert an Array with a JSON string into a JSON object (ruby))
Thoughts? How can I check whether object.name contains a certain string?
Thanks.
If you want to find all customers called Mark you can write the following:
customers_named_mark = array_of_customers.select{|c| c.name == 'Mark' }
This will return a potentially empty array.
If you want to find the first customer named Mark, write
customer_named_mark = array_of_customers.detect{|c| c.name == 'Mark' }
This will return the first matching item or nil.

How can I retrieve object keys from a sequence in freemarker?

I have a list of objects that are returned as a sequence, I would like to retrieve the keys of each object so as to be able to display the object correctly. At the moment I try data?first?keys which seems to get something like the queries that return the objects (Not sure how to explain that last sentence either but img below shows what I'm trying to explain).
The objects amount of objects returned are correct (7) but displaying the keys for each object is my aim. The macro that attempts this is here (from the apache ofbiz development book chapter 8).
Seems like it my sequence is a list of hashes and as explained by Daniel Dekany this post:
The original problem is that, someHash[key] expects a
string as key. Because, the hash type of FTL, by definition, maps
string keys to arbitrary values. It's not the same as Java's Map.
(Note that to further complicate the matters, in FTL
someSequenceOrString[index] expects an integer index. So, the [] thing
is used for that too.) Now someBeanWrappedMap(key) has technically
nothing to do with all the []-s, it's just a method call, so it
accepts all kind of keys. If you have a Map with non-string keys, you
must use that.
Thanks D Dekany if you're on stack, this ended my half day frustration with the ftl template.

Resources