if (insideIntervals.contains(newPoint.getPointAttributes())) {  pointClosesInterval(insideIntervals, newPoint, i);    currentPoint.getPointAttributes().addAttributes( newPoint.getPointAttributes().getAttributes());  } else { pointOpensInterval(insideIntervals, newPoint, i); insideIntervals.addAttributes(currentPoint.getIntervalAttributes().getAttributes()); currentPoint.getPointAttributes().addAttributes( newPoint.getPointAttributes().getAttributes());
for (AttributeType attributeType : newPoint.getPointAttributes().getAttributes()) { if (insideIntervals.contains(attributeType)) { pointClosesInterval(insideIntervals, attributeType, i); currentPoint.getPointAttributes().addAttribute(attributeType); } else { pointOpensInterval(insideIntervals, attributeType, i);   currentPoint.getPointAttributes().addAttribute(attributeType); }
    public void plotPoint(TimePoint newPoint) {        int timeLineSize = getNumberOfTimePoints();        Attributes insideIntervals = new Attributes();        for (int i = 0; i < timeLineSize; i++) {            TimePoint currentPoint = getTimeLinePosition(i);            if (newPoint.isAtSameTime(currentPoint)) {                if (insideIntervals.contains(newPoint.getPointAttributes())) {                    // the interval is open and we're going to close it right away                    pointClosesInterval(insideIntervals, newPoint, i);                    // TODO verificar isto! - apaguei, em principio e' redundante                    // currentPoint.getPointAttributes().removeAttributes(newPoint.getPointAttributes().getAttributes());                    // // remove the newPoint attributes from the current point                    currentPoint.getPointAttributes().addAttributes(                            newPoint.getPointAttributes().getAttributes());                    // since the time is the same we will not add the new point but use the current                } else { // the interval is not open, let's create it                    pointOpensInterval(insideIntervals, newPoint, i);                    insideIntervals.addAttributes(currentPoint.getIntervalAttributes().getAttributes());                    currentPoint.getPointAttributes().addAttributes(                            newPoint.getPointAttributes().getAttributes());                    // since the time is the same we will not add the new point but use the current                }                return;            } else if (newPoint.isBefore(currentPoint)) {                addPoint(i, newPoint);                // adds the point in this position and shifts the current point to the next position                // (i+1) se attrib ponto do novo ponto estao em intervalos abertos => intervalo vai-se                // fechar                if (insideIntervals.contains(newPoint.getPointAttributes())) {                    // inserted point only has 1 attribute                    pointClosesInterval(insideIntervals, newPoint, i);                } else { // novo intervalo                    pointOpensInterval(insideIntervals, newPoint, i);                }                return; // get off the for loop            } else {                // is after caso em q o intervalo ja esta' aberto faz o update do atributo no ponto                for (AttributeType attribute : currentPoint.getPointAttributes().getAttributes()) {                    if (insideIntervals.contains(attribute)) {                        newPoint.getIntervalAttributes().removeAttribute(attribute);                        // removes the current point attribute to new point interval attributes                        insideIntervals.removeAttribute(attribute);                    } else {                        if (newPoint.getPointAttributes().contains(DomainConstants.WORKED_ATTRIBUTES)                                && attribute.equals(AttributeType.MEAL) && i % 2 == 0 && i != 0) {                            currentPoint.getPointAttributes().addAttribute(attribute);                            currentPoint.getIntervalAttributes().addAttribute(attribute);                            newPoint.getPointAttributes().addAttribute(attribute);                            newPoint.getIntervalAttributes().removeAttribute(attribute);                        } else {                            newPoint.getIntervalAttributes().addAttribute(attribute);                            // adds the current point attribute to new point interval attributes                            insideIntervals.addAttribute(attribute);                        }                    }                }            }        }        TimePoint lastTimelinePoint = getTimeLinePosition(timeLineSize - 1);        // the newpoint is after the last point in the timeline        newPoint.setTime(lastTimelinePoint.getTime());        newPoint.setNextDay(lastTimelinePoint.isNextDay());        addPoint(timeLineSize - 1, newPoint);        // adds the point in this position and shifts the current point to the next position        // (i+1) se attrib ponto do novo ponto estao em intervalos abertos => intervalo vai-se        // fechar        if (insideIntervals.contains(newPoint.getPointAttributes())) {            // inserted point only has 1 attribute            pointClosesInterval(insideIntervals, newPoint, timeLineSize - 1);        } else { // novo intervalo            pointOpensInterval(insideIntervals, newPoint, timeLineSize - 1);        }    }