Given two strings representing locations, how can we identify if both are same or different locations.For eg. "Bangalore, Karnataka" and "Bangalore, India" are both same
location which is Bangalore.
I have a web-based application with a text-box for "location" and user can specify values as mentioned in the above example. Input values are stored into elasticsearch and later I need to find distinct locations. For that I am using Term Facet in elasticsearch but I getting two entries,"Bangalore, Karnataka" and "Bangalore, India". Somehow I need to identify that both are same locations.
I am looking forward for java based solution for this.
I would use a geo-coding Java API such GeoGoogle. It is open source. With that, you can call:
GeoUtils.distanceBetweenInKm(firstAddress.getCoordinate(), secondAddress.getCoordinate());
Related
I'm working on android i18n now. There are some strings.xml files in so many values-xxxx directories, but the product manager want to put these hole strings.xml files into the server, app get strings.xml File the rom network by a language-parameter dynamicly.But strings.xml is used in these ways: #string/xx, Widget.setText(R.string.xx), getString(R.string.xx), Toast.make(x, R.string.x, x) and so on... How to dynamic load android strings.xml easily? Or do you got a easier way to solve my problem? Thanks!
Frome one app I worked on:
After starting the app make an api call. The server responds with a JSON, containing all the strings. After parsing it, we can dynamically set all the strings in the right context or keep objects or even the json for getting the strings when required.
Hope this idea can help you.
i do understand that product manager wants to change this for a reason.
My Solution would be as follows:
Keep all string related to different language on server with different url pattern. In short url to get string should be like http://www.example.com/strings/{lang_param}/ example: http://www.example.com/strings/en/, http://www.example.com/strings/pt-br/ something like this.
Let server return JSON, where in key of strings would be same but the values changes based on url parameter i.e lang_param. Along with json server must return an identity has to indicate whether some strings items are changed or not. This identity hash must be kept in shared preference such that next time app boots-up you can query server check hash and if they are different mean some new changes are there get them in.
It is mandatory that you keep default strings.xml in internal memory of application using File file = new File(context.getFilesDir(), filename); given on https://developer.android.com/training/data-storage/files.html.
Once you get the new file update internal memory json file and create a utility method that parses this json. Please note that you need to maintain different hashes and json strings files based on different languages.
I am making an application which shows the nearby places of a given location. I take the location name and place types like museum,place of worship est. from the user and show the locations from that given type.
My problem is, I can't get some special places like Eiffel Tower because there is no such type. How can I get these kind of places ?
And these are the supported types: https://developers.google.com/places/supported_types
You probably use Nearby Search Requests, try Text Search Requests with query=attractions instead and don't forget to specify location and radius.
I have an analytics program that receives many values from a HTTP GET request and maps them into a table. My question pertains to changing the shorthand names I assigned to variables in the request into more full names before I write them to a log file. What is the best way for mapping the shorthand (e.g uid: KG) to the full names (User ID: KG )?
Currently I have a Map that puts all the relations in it ("uid": "User ID") on runtime. It uses a good number of calls to put every value in the map so I was wondering what is standard practice or most efficient, many put calls or is there a way to save a standard map to a file and load it in runtime?
Load a Properties object from a file is probably your best option. Instead of hard coding them in your program you can put them in a properties file like so:
uid=User ID
bid=Billy ID
...
THen load them using this API:
http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html
I am developing a program which has three JTextBox which my users can enter and check some text for right rule.
So I want add a ablitiy to my program that my users can add or remove their favorite text to a Favorite List and can create folder in Favorite list and put some text in it, such as Bookmark library in FireFox or other web browser.
I want use RandomAccessFile to save favorite list as a favorite source.
How do I implemet it? is there beter way to implement it? is there beter way from RandomAccessFile?
Can any one help me?
Thanks.
There could be lots of approaches. It all depends on what you want to achieve.
Consider using Java serialization mechanism. You can serialize a collection of bookmarks to a file. When your app starts, you deserialize it, and get the same collection data.
The advantages are: simple and easy implementation. The disadvantages: you can't look through stored bookmarks in a text editor or something. The same class hierarchy is to be used to load the serialized version.
XML is human-readable and provides easy interoperability. Other applications would be able to handle your list of bookmarks.
It usually takes more resources to parse the XML and load it to memory and then to create the internal object structures. Though you can use the DOM to traverse the tree all the time, it could be not as convenient as the internal data structure using specialized classes.
Random Access Files work best with fixed record sizes. It means all the fields of your bookmarks must be fixed-length. For example, the name of a bookmark is String. When you write it out to a file, you store it like an array of a fixed length, let's say 20. This automatically implies that if users give a bookmark the name which length is greater than 20, the remaining characters would be lost.
It is also easy to implement with the caveats above. Of course the records could be of variable length, but then you lose the random access to file because you cannot easily calculate the position of a specific record.
Firefox uses JSON for storing bookmarks and allows exporting to HTML. You can explore this too.
You can also store bookmarks, and things you want to keep between sessions in the Preferences,
see http://download.oracle.com/javase/6/docs/api/java/util/prefs/Preferences.html
I have three questions related to LDAP and Java.
is there any way to find the newly created users on the windows active directory using Java? Now I am get the all users from active directory loop through them and using the whencreated attribute for identify the new users.
same like previous one is there any way to find the users attributes that recently modified on active directory (like firstname changed or email changed like that) using Java? Currently I am identify using whenchanged attribute.
is there any way to identify the info about the user is locked/unlocked or he is in active/de-active like that?
LDAP search filters should give you what you need.
Use (&(objectClass=user)(whenCreated>=20110701000000.0Z)) to get user accounts created on or after July 1, 2011.
Use (&(objectClass=user)(whenChanged>=20110701000000.0Z)) to get user accounts changed on or after July 1, 2011.
Use (&(objectClass=user)(whenChanged>=20110701000000.0Z)(userAccountControl:1.2.840.113556.1.4.803:=2)) to get accounts changed on or after July 1, 2011 and that are disabled. Use a bitwise filter matching rule identifier to check for specific userAccountControl flags.
If these queries will be executed often, you might want to index the whenCreated and whenChanged attributes.
Active Directory does support notifying LDAP clients on change through persistent searches (note, however, the limit of 5 searches per connection). I haven't personally ever used this, but there are examples here, here, and here (in particular, notice that Active Directory apparently uses a different OID for these searches. Note that monitoring for ADDs is pretty straight-forward, but modifications will require some work on the part of your Java app, as Active Directory sends modify notifications on any modification operation, regardless of attribute.
#raddeman is exactly right regarding locks/unlocks and enabled/disabled. Simple bitwise operations on userAccountControl will help you get extract these values (e.g. userAccountControl & 2 == 2 indicates a user is disabled.
1)
LDAP is a protocol where you can not (what i know of) sort the result without doing it manually (in your case, in Java). Another thing that you might find is the value you searched for stored in its own field, as msSFU30MaxUidNumber in Active Directory to get the largest UNIX UID in the AD.
EDIT: As noted by #EJP, you can specify sorting if the LDAP-server supports it. In Java, look at javax.naming.ldap.SortControl
2) I think this is the same as 1.
3) Yes, look at the userAccountControl field. It contains values that could be found here: http://support.microsoft.com/kb/305144 such as ACCOUNTDISABLE (2).