Program: 111193
Project: 111193
Buggy source:
/** 
 * Calculates the legend positions and which legend title should be displayed or not. Important: the LegendBounds in the _Models should be set and correctly calculated before this function is called!
 * @param _Models The graph data which should have the BaseModel class as parent class.
 * @param _StartX Left starting point on the screen. Should be the absolute pixel value!
 * @param _Paint  The correctly set Paint which will be used for the text painting in the later process
 */
public static void calculateLegendInformation(List<? extends BaseModel> _Models,float _StartX,float _EndX,Paint _Paint){
  float lastX=_StartX;
  float textMargin=Utils.dpToPx(10.f);
  for (  BaseModel model : _Models) {
    if (!model.isIgnore()) {
      Rect textBounds=new Rect();
      RectF legendBounds=model.getLegendBounds();
      _Paint.getTextBounds(model.getLegendLabel(),0,model.getLegendLabel().length(),textBounds);
      model.setTextBounds(textBounds);
      float centerX=legendBounds.centerX();
      float centeredTextPos=centerX - (textBounds.width() / 2);
      float textStartPos=centeredTextPos - textMargin;
      if (lastX == _StartX) {
        model.setShowLabel(true);
        if (textStartPos + textMargin < _StartX) {
          model.setLegendLabelPosition((int)_StartX);
          lastX=textBounds.width();
        }
 else {
          model.setLegendLabelPosition((int)centeredTextPos);
          lastX=centerX + (textBounds.width() / 2);
        }
      }
 else       if (centeredTextPos + textBounds.width() > _EndX) {
        model.setShowLabel(false);
      }
 else {
        if (textStartPos < lastX) {
          if (lastX + textMargin < legendBounds.left) {
            model.setLegendLabelPosition((int)(lastX + textMargin));
            model.setShowLabel(true);
            lastX=lastX + textMargin + textBounds.width();
          }
 else {
            model.setShowLabel(false);
          }
        }
 else {
          model.setShowLabel(true);
          model.setLegendLabelPosition((int)centeredTextPos);
          lastX=centerX + (textBounds.width() / 2);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Calculates the legend positions and which legend title should be displayed or not. Important: the LegendBounds in the _Models should be set and correctly calculated before this function is called!
 * @param _Models The graph data which should have the BaseModel class as parent class.
 * @param _StartX Left starting point on the screen. Should be the absolute pixel value!
 * @param _Paint  The correctly set Paint which will be used for the text painting in the later process
 */
public static void calculateLegendInformation(List<? extends BaseModel> _Models,float _StartX,float _EndX,Paint _Paint){
  float textMargin=Utils.dpToPx(10.f);
  float lastX=_StartX;
  for (  BaseModel model : _Models) {
    if (!model.isIgnore()) {
      Rect textBounds=new Rect();
      RectF legendBounds=model.getLegendBounds();
      _Paint.getTextBounds(model.getLegendLabel(),0,model.getLegendLabel().length(),textBounds);
      model.setTextBounds(textBounds);
      float centerX=legendBounds.centerX();
      float centeredTextPos=centerX - (textBounds.width() / 2);
      float textStartPos=centeredTextPos - textMargin;
      if (lastX == _StartX) {
        model.setShowLabel(true);
        if (textStartPos + textMargin < _StartX) {
          model.setLegendLabelPosition((int)_StartX);
          lastX=textBounds.width();
        }
 else {
          model.setLegendLabelPosition((int)centeredTextPos);
          lastX=centerX + (textBounds.width() / 2);
        }
      }
 else       if (centeredTextPos + textBounds.width() > _EndX) {
        model.setShowLabel(false);
      }
 else {
        if (textStartPos < lastX) {
          if (lastX + textMargin < legendBounds.left) {
            model.setLegendLabelPosition((int)(lastX + textMargin));
            model.setShowLabel(true);
            lastX=lastX + textMargin + textBounds.width();
          }
 else {
            model.setShowLabel(false);
          }
        }
 else {
          model.setShowLabel(true);
          model.setLegendLabelPosition((int)centeredTextPos);
          lastX=centerX + (textBounds.width() / 2);
        }
      }
    }
  }
}