A Path object comes with many methods that changes it (moveTo(), lineTo(), cubicTo(), arcTo(), reset(), etc.).
Is there a way to freeze the object once you have it the way you want it, before you pass it onward?
Something along the line of CGPath in objective-c?
No. Immutable means that once the constructor for an object has completed execution that instance can't be altered.
Still, you can subclass Path and add pseudo-immutability yourself if that's really needed but there is no built-in mechanism out of the box.
Not ideal, but an alternative solution to the problem you are describing is to copy of the original Path using the constructor:
Path copy = new Path(originalPath);
Then, you can pass the copy the other thread without worrying if they change it while you are reading the original Path.
Related
I want to replace the data behind an existing source. This is trivial in javascript:
map.getSource('trace').setData(data);
See https://docs.mapbox.com/mapbox-gl-js/example/live-update-feature/
That method does not exist in Android. Once I have set a value, I can't replace it (nothing changes if I do):
GeoJsonSource mySource;
mySource.setGeoJson("some json data");
To delete and readd the source, I'd have to remove the layer using the source first: https://github.com/mapbox/mapbox-gl-native/issues/12526
Since I'm getting a fully functioning Style object from the server, removing, recreating and readding the layer/source at the correct position is tedious to say the least.
Above code actually works, but to reset my layer I used:
mySource.setGeoJson("");
Setting the source to empty String breaks something. Afterwards the GeoJson can not be set to something meaningful again. So to reset data, I'll have to use the visibility attribute of a layer. Replacing meaningful GeoJson with meaningful GeoJson works just fine.
The setGeoJson methods work correctly with any valid Geometry to add data (e.g. Point, MultiPoint).
Then, to clear or initialize the source without "breaking" the layer you can use:
mySource.setGeoJson(FeatureCollection.fromFeatures(new ArrayList<Feature>()));
I was wondering what the difference between database.getReference("foo/bar/123") and database.getReference("foo").child("bar").child("123") is?
I'm assuming that the later one will load the complete "foo" object whereas database.getReference("foo/bar/123") just loads the "123" object?
Is my assumption correct or what is the correct / most efficient way to only load data of "123"?
The two are equivalent. You can inspect this manually this by printing the toString() format for both References.
References are cheap - there's nothing inefficient about either solution. Neither one has yet loaded any data. A Reference is just a pointer to a location in the database.
It should not make a difference, a reference is not actually accessed when instantiated. This is the most relevant document I can find,
https://firebase.google.com/docs/reference/node/firebase.database.Reference
The docs don't say it explicitly, but requests are only performed when using the .set() or .on() methods
There are scenarios in feature files wherein I've use the text "Foo" and on click its open a new page. this text sometime changes to "Foo1" or "Foo2" or to something else. to avoid line by line change in feature file for "Foo" to "Foo1" or "Foo2" is there any way that I can globally declare variable in top/bottom of the feature file where I can set the required text in variable on fly and I shall start executing my test instantly?
This change exist in many feature files and around 1000 lines in feature file. To get solution for this, I try on setting environment variables but I couldn't reach all the way till end this issue to solve. So can anyone help me on this?
Thanks in advance
What if you do the replacement in your step implementation instead? Then you could have the desired value in a separate file or pass it as arguments. That way you don't need to hard code the values.
Could scenario outlines help you in any way or is the value only changing depending on external changes?
My first thought was scenario outlines like #homaxto said.
Then I thought you might want to affect it by which system you are connected to. You can do this through configuration. I have done this with Fig_Newton.
You can either set an environment varaible or use one in the commandline. Or you can use #hook type tags. With a hook tag, you can have a tag at the top of a feature file that you can use to set a variable that affects how the steps operate (but it needs to be handled inside the step).
I realized that when calling "createFile", it creates a new file even if its title is an already existing title.
What am doing now is to search for the file first and if i can't find it, i create it. Two methods for a simple problem.
There is a better way to create a file overriding it if already it exists?
Google Drive is actually a 'flat' model, where every object is identified by it's unique ID.
So, when an object (file/folder) is created, it gets a unique ID. The object may/not have content. Everything else is 'metadata'. The tree structure of popular OSs is actually 'faked' by metadata links (parent links). That means in Google Drive you may have multiple children with the same metadata (title/name) in a parent object. And you may also have multiple parents for any child object (single object appears in multiple parents' folders).
All this rant means one thing for your situation:
Once you create a file/folder and get hold of it's ID, 'creation of a new file with the same name' can be accomplished by modifying it's content and/or metadata (you can see a typical example here).
If you take the path of delete/create (which is also possible, but had not been until recently), you are actually:
1/ modifying the original file/folder's 'trashed/deleted' metadata
2/ creating a brand new object with a different ID
Think twice before you select the method you use. UPDATE method is a 'one-step', approach preferable in async environment (create MUST wait for successful delete). On the other hand, if you use DELETE/CREATE approach you may be able to take advantage of the fact that 'trashed' object will be around for a while.
Good Luck
I think files are uniquely identified by their ID in the Drive API. Therefore you have no way to control for the title using the drive API itself. So doing it yourself is probably the way to go.
EDIT: The ID is what is important with all that synchronisation happening. A title could change easily therefore using it as a unique identifier would be a bad idea. Hence the unique ID.
What you could do if the file already exists is either remove it and replace it by the new one (bad idea I would say) or simply add an extra number at the end of the new file that will be added to the folder.
I'm looking for a way of passing an object that I didn't create and cannot modify to implement parcelable in android. I was given a jar file that placed into the project by building a path to it. Now i need to pass the object created from activity to activity so that I may use the contents of the jar file. Right now it is set up so I define it as static, which probably isn't the best way. The only other option I can think of is using putSerializable but I've heard that puts strain on the system. So, what are my other options?
The main problem you have here is if that class has non-accessable private fields (through getters), then you cannot get this data to parcel it. If all private fields are accessable, then you might have several possibilities:
Extending it with a Parcelable subclass (as suggested by Simon in the comments).
Wrapping it in another Parcelable object.
Converting it to an already Parcelable object (e.g. any implementation of Map)
Note that if the object itself is not very big then the performance drop between parcelling and serializing shouldn't be noticeable. So I would go for Serializing and if the performance is not satisfactory then consider other options.