What is difference between LinkedHashSet and FilterSet(Guava) - guava

When I trace legacy code, I found something very strange. I can get all the data values from LinkedHashSet, not from the other(FilterSet).
Although data can be seen in unfiltered, but in iteration, I cannot get the required data. Is it because of the predicate? How to get all the data from unfiltered ones?
I found that guava is used in the implementation of utilities class in my project.
What is the difference of these two sets? Any help is greatly appreciated.
Set<A<? extends B, ?>> attributes;

Sets.filter returns a private implementation type called FilteredSet that is a view of another set, restricting its output to only the elements of the original set that have some particular property.
There is deliberately no way to get out the original unfiltered data.

Related

scala for mapbox vector tiles - getting an 'id' field into the Features written to vector tiles

I'm writing MapBox vector tiles using geotrellis vectorpipe.
see here for the basic flow: https://geotrellis.github.io/vectorpipe/usage.html
Typically GeoJson Features can have an id field, so that Features can be rolled up into FeatureCollections. I need to make use of this field, but vectorpipe doesn't (natively) have this capability.
This is the Feature type used, and you can see it only has space for 1) a Geometry and 2) a data object D (which ends up populating properties in the output). There is no spot for an id.
https://geotrellis.github.io/scaladocs/latest/index.html#geotrellis.vector.Feature
Upstream there's a method called writeFeatureJsonWithID() that does let you inject an id field into a Feature when writing GeoJson.
https://github.com/locationtech/geotrellis/blob/master/vector/src/main/scala/geotrellis/vector/io/json/FeatureFormats.scala#L41-L49
My question is this:
I have worked through the vectorpipe code (https://github.com/geotrellis/vectorpipe), and I can't figure out if/where the data ever exists as GeoJson in a way where I can override and inject the id, maybe using the writeFeatureJsonWithID() or something I write explicitly. A lot of conversions are implicit, but it also may never explicitly sit as json.
Any ideas for how to get an id field in the final GeoJson written to vector tiles?
EDIT
Right now I think the trick is going to be finding a way to override .unfeature() method here:
https://github.com/locationtech/geotrellis/blob/master/vectortile/src/main/scala/geotrellis/vectortile/Layer.scala
The problem is that the internal.vector_tile.Tile is private, so I can construct it without forking the project.
Ended up having to fork geotrellis, hard-code a metadata => id function in Layer.unfeature() and compile locally to include in my project. Not ideal, but it works fine.
Also opened an issue here: https://github.com/locationtech/geotrellis/issues/2884

How to get an OrderedSet of OccurrenceSpecifications from a Lifeline in QVTo?

From the diagram on page 570 of the UML spec I concluded that a Lifeline should have the events property, holding an OrderedSet(OcurrenceSpecification). Unfortunately it is not there, at least in the QVTo implementation that I use.
All I have is the coveredBy property, serving me with an (unordered) Set(InteractionFragment). Since my transformation relies on the correct order of MessageOcurrenceSpecification I somehow need to implement myself what I expected to be implemented by the missing events property.
This is what I have so far:
helper Lifeline::getEvents (): OrderedSet(OccurrenceSpecification) {
return self.coveredBy->selectByKind(OccurrenceSpecification)->sortedBy(true);
}
Obviously sortedBy(true) does not get me far, but I don't know any further. Who can help?
All I could find so far were other people struggling with the same issue years ago, but no solution:
https://www.eclipse.org/forums/index.php/m/1049555/
https://www.eclipse.org/forums/index.php/m/1050025/
https://www.eclipse.org/forums/index.php/m/1095764/
Based on the answer by Vincent combined with input from a colleague of mine I came up with the following solution for QVTo:
-- -----------------------------------------------------------------------------
-- Polyfill for the missing Lifeline::events property
query Lifeline::getEvents (): OrderedSet(OccurrenceSpecification) {
return self.interaction.fragment
->selectByKind(OccurrenceSpecification)
->select(os: OccurrenceSpecification | os.covered->includes(self))
->asOrderedSet();
}
I don't know if it is possible, using directly coveredBy to get an ordered collection. As coveredBy is unordered, if you access it directly by the feature, you will have an unpredictible order and if you try to access it using the eGet(...) stuff, the same result will occur.
However, if I understood correctly, there is a "trick" that could work.
It relies on the assumption that each OccurrenceSpecification instance you need is held by the same Interaction that contains the Lifeline and uses the way EMF stores contained elements. Actually, each contained element is always kind of 'ordered' relatively to its parent (and for each collection so EMF can find elements back when XMI references are expressed using the element position in collections). So, the idea would be to access all the elements contained by the Interaction that owns the lifeline and filter the ones that are contained in coveredBy.
Expression with Acceleo
This is easy to write in MTL/Acceleo. In know you don't use it, but it illustrates what the expression does:
# In Acceleo:
# 'self' is the lifeline instance
self.interaction.eAllContents(OccurrenceSpecification)->select(e | self.coveredBy->includes(e))->asOrderedSet()
with self.interaction we retrieve the Interaction, then we get all the contained elements with eAllContents(...) and we filter the ones that are in the self.coveredBy collection.
But it is way less intuitive in QVT as eAllContents(...) does not exist. Instead you have to gain access to eContents() which is defined on EObject and returns an EList which is transtyped to a Sequence (in QVT,eAllContents() returns a ETreeIterator which is not transtyped by the QVT engine).
So, how to gain access to eContents() in the helper? There is two solutions:
Solution 1: Using the emf.tools library
The emf.tools library give you the ability to use asEObject() which casts your object in a pure EObject and give you more methods to access to (as eClass() for example...etc).
import emf.tools; -- we import the EMF tools library
modeltype UML ...; -- all your metamodel imports and stuffs
...
helper Lifeline::getEvents (): OrderedSet(OccurrenceSpecification) {
return self.interaction.asEObject().eContents()[OccurrenceSpecification]->select(e | self.coveredBy->includes(e))->asOrderedSet();
}
Solution 2: Using oclAstype(...)
If for some reason emf.tools cannot be accessed, you can still cast to an EObject using oclAsType(...).
modeltype UML ...; -- all your metamodel imports and stuffs
modeltype ECORE "strict" uses ecore('http://www.eclipse.org/emf/2002/Ecore'); -- you also register the Ecore metamodel
...
helper Lifeline::getEvents (): OrderedSet(OccurrenceSpecification) {
return self.interaction.oclAsType(EObject).eContents()[OccurrenceSpecification]->select(e | self.coveredBy->includes(e))->asOrderedSet();
}
Limitation
Ok, let's be honest here, this solution seems to work on the quick tests I performed, but I'm not a 100% sure that you will have all the elements you want as this code relies on the strong assumption that every OccurrenceSpecification you need are in the same Interaction as the Liteline instance. If you are sure that all the coveredBy elements you need are in the Interaction (I think they should be), then, that's not the sexiest solution, but it should do the work.
EDIT>
The solution proposed by hielsnoppe is more eleguant than the one I presented here and should be prefered.
You are correct. The Lifeline::events property is clearly shown on the diagram and appears in derived models such as UML.merged.uml.
Unfortunately Eclipse QVTo uses the Ecore projection of the UML metamodel to UML.ecore where unnavigable opposites are pruned. (A recent UML2Ecore enhancement allows the name to be persisted as an EAnnotation.) However once the true property name "events" has been pruned the implicit property name "OccurrenceSpecification" should work.
All associations are navigable in both directions in OCL, so this loss is a bug. (The new Pivot-based Eclipse OCL goes back to the primary UML model in order to avoid UML2Ecore losses. Once Eclipse QVTo migrates to the Pivot OCL you should see the behavior you expected.)

Best way to compare EXPECT result with our true records in Jasmine testing framework?

What are the ways to compare the expect results with our true records using Jasmine Testing Framework?
One of the way is to use a static values within expect Parameters which is good for very basic values... But it has several limitations like it does not compare objects at runtime...
How to compare objects at runtime for its validity...???
EDIT :
it("Read JSON record with Id.", function(){
result = Database.selectRecordById (STORE_ID, id3);
expect(result).toEqual(aRecord); //cValue
});
Here is the code. Now my problem is to compare the result value to aRecord. I will get result from method Database.selectRecordById. For now i am using a static value of aRecord. I want some other way which is more reliable so that my aRecord becomes dynamic. One thing i thought is to make a database which will contain all true values... but then i manually have to see that... What could be other alternative.??
As far as I see there is nothing wrong with static values for comparing result. That is how we usually do unit testing both in Java and in JavaScript.
The actual value is what you get from the actual database/method call and the expected value is a static value. The less 'moving parts' you have here, the better. If you were to dynamically load the expected values, that can go wrong as well and you do not want your tests failing if your application because your test data load was wrong. It is also a lot more cumbersome to maintain.
Hope I did not misunderstand your question.

Share data between Activities/Presenters in GWT

II want to share data between Activities (which are my presenters) without passing the data with the Place. How can I do that?
If the data really isn't all that large I'd try and encode it in the Place: then your users can bookmark/distribute URLs that lead right into the guts of the application (link to a specific product, search filter, etc).
Quite some ways. A simple way is -
you could create a public static field in some class and use that in all of your presenters . (This method obviously has strings attached and must be used carefully)
Jai

How to convert Objective C textual (po) representation to real object

In xcode you can use po object to see a textual representation of a given object. Is it possible to convert from this textual representation to a real objective c object?
Thanks
I suppose you could parse out the address, assign it to a pointer, and retrieve the object from memory that way, but that IS A HORRIBLY BAD IDEA AND YOU SHOULD NEVER DO THAT.
Real question: what are you trying to do?
I have a project that may inspire you, its on GitHub and its called NDJSON. Basically it uses runtime introspection to get properties an object has and set those properties using a json key of the same value. You could do something like that but get the property values instead of set. To help in situation where the type can not be determined like the type of objects to go in a collection or to map a json key to differently named property I have defined an informal protocol that has some methods that return dictionary mapping json key to property names or class to use for property name, there are also method to return a list of json keys to ignore or alternatively the only keys to accept. If you look at my code on git hub there is a class called NDJSONDeserializer which contains this logic. There is a function called getTypeNameFromPropertyAttributes() which parses out the string result of Apples runtime method property_getAttributes() which you will want to look at.
No, the representation you see from po <instance> is the result of -[<instance> debugDescription], which by default returns -[<instance> description], as described in http://developer.apple.com/mac/library/technotes/tn2004/tn2124.html.
Unless the instance you're dealing with just happens to provide a description which is a serialized form of itself, you're SOL. Most objects don't.
The real question, as Dave points out is, what are you trying to do? po only works in the gdb console, so I assume this is a debugging issue. In that case, do you know that the gdb console supports sending messages to instances? So you can do:
po [<myInstance> methodReturningAnOtherObject]
or
po [<myInstance> valueForKeyPath:#"some.long.key.path"]
to follow the object graph from within the debugger console.