code: public CalendarPeriodAssociative<T> Trim( CalendarPeriodAssociative<T> calendarPeriod )
  	{
  		List<PeriodAssociative<T>> result = new ArrayList<PeriodAssociative<T>>();
  
  		int count1 = periods.size();
  		int count2 = calendarPeriod.getPeriods().size();
  
  		int i = 0;
  		int j = 0;
  
  		while( i < count1 && j < count2 )
  		{
  			// one of the periods begins after the end of the other
  			if( periods.get( i ).getFrom().compareTo( calendarPeriod.getPeriods().get( j ).getTo() ) > 0 )
  			{ // period 1 begins after period 2 finishes => period2 is
  				// eliminated !
  				j++;
  			}
  			else if( calendarPeriod.getPeriods().get( j ).getFrom().compareTo( periods.get( i ).getTo() ) > 0 )
  			{ // period 2 begins after end of period 1 => period 1 is eliminated
  				// !
  				i++;
  			}
  
  			// after that test, we can assume there is a non-void intersection
  			else
  			{
  				result.add( new PeriodAssociative<T>( CalendarFunctions.max_date( periods.get( i ).getFrom(), calendarPeriod.getPeriods().get( j ).getFrom() ), CalendarFunctions.min_date( periods.get( i ).getTo(), calendarPeriod.getPeriods().get( j ).getTo() ), periods.get( i )
  						.getValue() ) );
  
  				if( periods.get( i ).getTo().compareTo( calendarPeriod.getPeriods().get( j ).getTo() ) > 0 )
  					j++;
  				else
  					i++;
  			}
  		}
  
  		CalendarPeriodAssociative<T> res = new CalendarPeriodAssociative<T>();
  		res.setPeriods( result );
  
  		return res;
  	}
docs: $calendarPeriod