refactoring java code (1)
hi all,
I have a little trouble to refactoring to function from a same class
there the 2 functions
public Collection getRangeMarkers(int index, Layer layer){
Collection result =null;
Integer key =new Integer(index);
if (layer == Layer.FOREGROUND){
result = (Collection) this.foregroundRangeMarkers.get(key);
}
elseif (layer == Layer.BACKGROUND){
result = (Collection) this.backgroundRangeMarkers.get(key);
}
if (result !=null){
result = Collections.unmodifiableCollection(result);
}
return result;
}
public Collection getDomainMarkers(int index, Layer layer){
Collection result =null;
Integer key =new Integer(index);
if (layer == Layer.FOREGROUND){
result = (Collection) this.foregroundDomainMarkers.get(key);
}
elseif (layer == Layer.BACKGROUND){
result = (Collection) this.backgroundDomainMarkers.get(key);
}
if (result !=null){
result = Collections.unmodifiableCollection(result);
}
return result;
}
there is how there are declared
this.foregroundDomainMarkers =new HashMap();
this.backgroundDomainMarkers =new HashMap();
this.foregroundRangeMarkers =new HashMap();
this.backgroundRangeMarkers =new HashMap();
as we can see it's just a name who change, the behavior is exacly the same it's the data structure who change.
In c++ we can use template, in java?
it's not just two function, I have that all the time (and on big function).
thanks

