Tag Info

Hot answers tagged

12

Why is it confusing? The javadoc for HashMap.put clearly states: Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced. It clearly states what happens when you do a put with a key which was already in the map. The specific case of key == null behaves in the ...


9

Hash functions are used to convert the input (usually string) to a smaller fixed length (typically) "hashed value" which typically is used somewhat like a array index for the hash table. Ideally this value should be evenly spread throughout its range, and avoid any obvious/significant concentrations. A hash function is any algorithm or subroutine that ...


9

http://gadm.org/ seems to have exactly what you want (and more). GADM database of Global Administrative Areas GADM is a spatial database of the location of the world's administrative areas (or adminstrative boundaries) for use in GIS and similar software. Administrative areas in this database are countries and lower level subdivisions such as ...


9

map is a fairly well-rounded dictionary-type container that provides several advantages over std::list (linked lists) and std::vector (arrays). Although its not strictly specified, the performance constraints required on a map pretty much forces it to be implemented as some kind of self-balancing binary tree. So if its helpful to you to think about it in ...


9

Exagg'itive Summary (TM) You get a few things. Prototypal inheritance and cloning Dynamic addition of new properties Co-existence of objects of different versions (specification levels) of the same class. Objects belonging to the more recent versions (specification levels) will have extra "optional" properties. Introspection of properties, old and new ...


8

The definition from wikipedia seems correct and general enough: collection of unique keys and a collection of values, where each key is associated with one value (or set of values) Not a word about order. That should be perfectly fine, as there are many good ways to implement data structures that are perfect associative arrays, only without the ...


6

That's an excellent talk by someone who really knows what he's talking about. I recommend readers watch the entire thing. It's only 36 minutes long. One of his main points is that simplicity opens opportunities for change later on. Choosing a class to represent a Person provides the immediate benefit of creating a statically-verifiable API, as you ...


5

An adapter strategy sounds good enough for this case, i.e., define a common interface and then proceed to implement that interface for each provider. The choice for which map provider to use can be a configurable option in the settings. Also see Mapstraction, a JavaScript library that provides a common interface for several map providers, including Google, ...


4

There is an implementation of MVC objects in Google Maps JavaScript API V3. It allows map objects to store state and update their presentation automatically. There is a DEMO of moving and resizing a circle which may provide what you require. The full tutorial can be seen HERE


4

It seems to me that the main issue is only including nodes that add significant information about a road. i.e. without your GPS requirement, you could just store nodes at junctions and endings (which I think you call start/end nodes). Obviously including weight/costs etc. One way I can think of approaching this is to first, add all start/end nodes. This is ...


4

The Google Maps API licensing page explains this fairly well, to summarise, there are three types of license: Google Maps API The Google Maps API is a free service that lets you embed Google Maps in your freely accessible web pages or mobile apps. Your service must be freely and publicly accessible to end users. Google Maps API for Business Google ...


4

Your problem lends very nicely to the Command design pattern. So basically you will have a base Command interface and then there would be multiple CommandImpl classes that would implement that interface. The interface essentially needs to just have a a single method doCommand(Args args). You can have the arguments passed in via an instance of Args class. ...


4

The decompiler probably has problems in decompiling class names correctly that contain a $ symbol. The symbol you are searching for is named Predef$: import scala.Predef; import scala.Predef$; import scala.Tuple2; import scala.collection.immutable.Map; import scala.collection.mutable.WrappedArray; public class T { @SuppressWarnings({ "rawtypes", ...


4

The best way to approach this is to go to FP Complete's Hoogle and type in the signature you're looking for, (a -> Maybe b) -> [a] -> Maybe [b]. The first hit is a function called mapM which is exactly what you are looking for. In fact it works for all Monads, not just Maybe. (If you want to be even more general you can use traverse)


4

You want a function with this signature: (a -> Maybe b) -> [a] -> Maybe [b] Entering this into hoogle gives this possibility: Prelude mapM :: Monad m => (a -> m b) -> [a] -> m [b] A look at the Hackage documentation for mapM says it is the same as: mapM f = sequence . map f and that the definition of sequence is: sequence ...


3

Fairly straightforward steps: Include boilerplate generic warnings, as you might see in many other pieces of software, and include them as part of a license agreement for users to agree to before they use your software Add a specific clause to the license agreement, informing users that you are not responsible for the map data that you're providing, and ...


3

Google said in 2012 we will begin adding 3D models to entire metropolitan areas to Google Earth on mobile devices. This is possible thanks to a combination of our new imagery rendering techniques and computer vision that let us automatically create 3D cityscapes, complete with buildings, terrain and even landscaping, from 45-degree aerial ...


3

For most purposes the classes from the standard library are likely to outperform any quickly-put-together data structure / container / algorithm you will write. This is assuming you choose the right abstraction (std::vector and std::list have different trade-offs, for example). A lot of time and effort by a lot of smart people has gone into making those ...


3

Your solution 1 may be problematic, as the hashmap is static and will be initialised only once, and is shared by all instances of your class. Is this your intended behavior or you want each instance have its own map? If you one only one map, I would suggest to pass the set to the constructor instead of using a static one, for example: public class Data { ...


3

It depends on the map. Cartographic maps are projections of a (nearly) spherical surface onto a flat, two dimensional surface. That is: (X, Y) = Fproj(Lat, Long) where Fproj() is the projection function. For instance, for a standard Mercator projection with the X axis on the equator, and the Y axis at the 0 Meridian: X = Longitude Y = ln(tan(Latitude) + ...


2

This will require you to access some database(s) which hold maximum allowed speeds for each road. Looking to purchase such information can turn out to be quite costly, especially if you want to cover wide areas. Combining several different data sources can also result in some extra required effort. Probably it's best to use an existing service, like Google ...


2

I am not aware of any mapping libraries that support highlights outright but if you want to do this with Google Maps or Yahoo GeoService then you can simply record the latitude and longitude of the bounds of the highlight area in a database. On loading the map again, you can restore the highlight area from those bounds by rendering points using the ...


2

As far as I know, usage of Google Maps for desktop apps is forbidden. (Scratch that, it's now OK, so long as it's a publicly available and downloadable app - will rewrite this answer.) If you want this to run within a native desktop application - and not in a normal brower connecting to a web-app, though that could also be one way of doing it - you'll need ...


2

If you're using Python 2.x, then that's easily achievable by using cmp, although you have to modify your function to return -1 instead of 0. Something like this: def greater(a, b): if (a % b) % 2 == 0: return 1 return -1 x = [2,7,5,10,30,15] print(sorted(x, cmp=greater)) But if you're using Python 3.x, then it gets a bit more complicated ...


2

Well, you're no longer dependent on the order of the columns in the data, but you're now dependent on the column names. If someone adds a column to an extract, even if it's in the middle, you're better off, because your code won't break. If someone deletes or renames a column, you'll still have an issue. If it's more likely that someone will rename a ...


2

Whenever I find myself asking whether I should use a switch statement or OO-style polymorphism I refer to the Expression Problem. Basically, if you have different "cases" for your data and wand to support different "actions" (where each action does something different for each case) then its really hard to make a system that naturally lets you add both new ...


2

If you're really worried - talk to an insurance agent about an 'errors and omissions' policy - I didn't say buy one, just talk to them - you'll probably learn a lot and its cheaper than a lawyer - which, as previous posters observed, you're gonna need


2

It seems that you want to do polygon rasterization, where your "pixels" are your grid elements. An approach I would try (as chances are you will find ready-to-use algorithms to do that), is to use an in-memory rasterizer (e.g. Cairo), adjusting the filtering (and of course the coordinates of your polygons so they are expressed in grid units). You could ...


2

Nothing can beat Guava's ImmutableMap with its optimized memory consumption, but here are a pair of pure solutions: /* Name of the class has to be "Main" only if the class is public. */ class Ideone { private static final Map<Character, String> codes1; static { Map<Character, String> temp= new HashMap<Character, String>(); ...



Only top voted, non community-wiki answers of a minimum length are eligible