﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
12198	Create a possibility to attach plug-in specific data to an OSMPrimitive	g.idema@…	team	"I'm working on a Plug-in that compares buildings and addresses in OSM to their counterparts in the official Dutch government registry for buildings and addresses (BAG). The differences are shown using a stylesheet and the plug-in assists the user in updating the OSM data for objects he/she selects.

For this to work, I need a way to reference an object (building or address node) in the imported data from the related OSMPrimitive on the OSM layer. Currently, the only way to achieve this is with a HashMap, mapping the OSMPrimitive to the related object in the imported data.

It would be a great improvement if there was a way to add a reference directly from the OSMPrimitive.
The ideal way to achieve this would be to implement a Node or Way interface, but these are Objects in stead of interfaces.
The second-best way would be to extend the Node, Way or Relation, but these classes are final and therefore can not be extended. Simply removing the 'final' modifier from these classes wouldn't work either, because the collections were not written with this possibility in mind. For example the method setNodes() in Way is written as setNodes(List<Node>) in stead of setNodes(List<? extends Node).

There is however a relatively simple way to extend the OSMPrimitives without breaking the rest of the code.
Just add the following methods to the IPrimitive interface and implement them in the Abstract primitive class with a map:


{{{
Object getPluginData(Class<? extends Plugin> plugin);
void setPluginData(Class<? extends Plugin>, Object data);
}}}

Using the plugin class as a key prevents interference between plug-ins. The data object could contain anything. It's up to the plug-in whether and how to use it.

The implementation could be as simple as this:


{{{
private Map<Class<? extends Plugin>, Object data> pluginData;

@Override
Object getPluginData(Class<? extends Plugin> plugin) {
    if (pluginData == null) return null;
    return pluginData.get(plugin);
}

@Override
void setPluginData(Class<? extends Plugin> plugin, Object data) {
    if (pluginData == null) {
        // To save memory, don't create the map unless we need it.
        pluginData = new HashMap<>();
    }
    pluginData.put(plugin, data);
}

}}}
"	enhancement	closed	normal		Plugin		wontfix	OSMPrimitive extend	
