if (position == -1 || position > (bot - top)) return bot;
int p = -1; for (int i = 0; i < components.length; i++) { int l = getLayer(components[i]); if (l > layer) index++;  else if (l == layer) { p++; if (p < position) index++;
  protected int insertIndexForLayer(int layer, int position)  {    Integer lobj = getObjectForLayer (layer);    if (! layers.containsKey(lobj))      layers.put (lobj, new Integer (0));    int[] range = layerToRange (lobj);    if (range[0] == range[1])        return range[0];	    int top = range[0];    int bot = range[1];    if (position == -1 || position > (bot - top))        return bot;    else        return top + position;  }