public LinkedList<interval> getIntervals(IntervalDescription desc, LinkedList<instant> currInstants)
    {
    	LinkedList<interval> newIntervals = new LinkedList<interval>();
    	//NUMERIC
    	if(desc.subType.equalsIgnoreCase("Numeric"))
    	{
    		   		
    		//Si la descripción no posee una segunda abstracción (sólo tiene min/max separation)
	    	if(desc.direction.equalsIgnoreCase("None"))
	    	{
	    		if(currInstants.size()<1)
	    		{
	    			this.intervalsList.add(newIntervals);
	    			return newIntervals;
	    		}
	    		else if(currInstants.size()==1)
	    		{
	    			instant first = currInstants.getFirst();
	    			interval interval = new interval(this.id, first.name, null, first.date, first.date, desc);
	    			IntervalResult intRes = new IntervalResult(first.result, first.date);
	    			interval.Results.add(intRes);
	    			if(desc.minLength < 1)
	    			{
	    				newIntervals.add(interval);
	    			}
	    		}
	    		else
	    		{
	    			while(currInstants.size()>0)
	    			{
		    			instant first = currInstants.remove();
		    			interval interval = new interval(this.id, first.name, null, first.date, first.date, desc);
		    			IntervalResult intRes = new IntervalResult(first.result, first.date);
		    			interval.Results.add(intRes);
		    			
		    			/*
		        		 * Variables for conditions
		        		 * Instantiate stats to calculate them if necessary
		        		 * 
		        		 * Check for each instant if condition is met, in order to cut the interval if it is not.
		        		 * Anyway, check the final interval for conditions, cause subintervals may not comply, but overall yes.
		        		 * 
		        		 * For now (and simplicity), we'll check just the final interval without minding for subintervals.
		        		 * 
		        		 */
		        		
		    			
		    			double condMin = first.result;
		    			double condMax = first.result;
		    			double condAvg = first.result;
		    			double condMedian = first.result;
		    			double condTotal = 1;
		    			
		    			LinkedList<Double> condResults = new LinkedList<Double>();
		    			condResults.add(first.result);
		    			
		    			while(currInstants.size()>0)
		    			{
		    				instant next = currInstants.remove();
		    				
		    				if((next.date.getTime()-first.date.getTime()) < (desc.maxSeparation*60*60*1000))
		    				{
		    					interval.End = next.date;
		    					IntervalResult nextIntRes = new IntervalResult(next.result, next.date);
		    					interval.Results.add(nextIntRes);
		    					if(next.result < condMin)
			    				{
			    					condMin = next.result;
			    				}
			    				if(next.result > condMin)
			    				{
			    					condMax = next.result;
			    				}
			    				condAvg += next.result;
			    				condResults.add(next.result);
			    				condTotal++;
		    				}
		    				else
		    				{
		    					
		    					/*
		    					 * Check if there are any conditions
		    					 * and test them to see if interval should be added.
		    					 */
		    					
		    					condAvg = (double)(condAvg/condTotal);
		    					
		    					if(condResults.size() % 2 == 0)
		    					{
		    						condMedian = condResults.get(condResults.size()/2);
		    					}
		    					else
		    					{
		    						condMedian = condResults.get((int)Math.floor(condResults.size()/2)) + condResults.get((int)Math.ceil(condResults.size()/2));
		    					}
		    					
		    					if(desc.conditions.size() > 0)
		    					{
		    						if(meetsCondition(desc, condMin, condMax, condAvg, condMedian, interval))
		    						{
		    							newIntervals.add(interval);
		    						}
		    					}
		    					else
		    					{
		    						newIntervals.add(interval);
		    					}
		    					interval = new interval(this.id, next.name, null, next.date, next.date, desc);
		    	    			IntervalResult nextIntRes = new IntervalResult(next.result, next.date);
		    	    			interval.Results.add(nextIntRes);
		    	    			
		    	    			condMin = next.result;
				    			condMax = next.result;
				    			condAvg = next.result;
				    			condMedian = next.result;
				    			condTotal = 1;
				    			
				    			condResults = new LinkedList<Double>();
				    			condResults.add(next.result);
		    				}
		    			}
		    			
		    			if( (desc.minLength*60*60*1000) <=  (interval.Results.getLast().date.getTime() - interval.Results.getFirst().date.getTime()) )
		    			{
			    			if(desc.conditions.size() > 0)
	    					{
	    						if(meetsCondition(desc, condMin, condMax, condAvg, condMedian, interval))
	    						{
	    							newIntervals.add(interval);
	    						}
	    					}
	    					else
	    					{
	    						newIntervals.add(interval);
	    					}
		    			}
		    			
	    			}
	    			
	    		}
	    	}
	    	else
	    	{
	    		if(currInstants.size()<1)
	    		{
	    			return newIntervals;
	    		}
	    		else if(currInstants.size()==1)
	    		{
	    			instant first = currInstants.getFirst();
	    			interval interval = new interval(this.id, first.name, null, first.date, first.date, desc);
	    			IntervalResult intRes = new IntervalResult(first.result, first.date);
	    			interval.Results.add(intRes);
	    			newIntervals.add(interval);
	    		}
	    		else
	    		{
	    			while(currInstants.size()>0)
	    			{
		    			instant first = currInstants.remove();
		    			interval interval = new interval(this.id, first.name, null, first.date, first.date, desc);
		    			IntervalResult intRes = new IntervalResult(first.result, first.date);
		    			interval.Results.add(intRes);
		    			double res1 = first.result;
		    			
		    			double condMin = first.result;
		    			double condMax = first.result;
		    			double condAvg = first.result;
		    			double condMedian = first.result;
		    			double condTotal = 1;
		    			
		    			LinkedList<Double> condResults = new LinkedList<Double>();
		    			condResults.add(first.result);
		    			
		    			while(currInstants.size()>0)
		    			{
		    				instant next = currInstants.remove();
		    				
		    				/*
		    				 * Segunda abstracción:
		    				 * Si se cumple la condición de corte, entonces se interrumple el intervalo
		    				 * sin importar el tiempo, y se genera uno nuevo.
		    				 */
		    				double res2 = next.result;
                			double ds1 = res2-res1;
                			
                			BigDecimal subs1 = new BigDecimal(ds1);
                			subs1 = subs1.setScale(2, BigDecimal.ROUND_HALF_UP);
                			ds1 = subs1.doubleValue();
                			
                			double ds2 = res1*desc.percDifference/100;
                			BigDecimal subs2 = new BigDecimal(ds2);
                			subs2 = subs2.setScale(2, BigDecimal.ROUND_HALF_UP);
                			ds2 = subs2.doubleValue();
		    				
                			boolean secondAbscondition = (ds1) >= desc.absDifference || (ds1) >= ds2;
                			if(desc.direction.equalsIgnoreCase("Decrease"))
                			{
                				secondAbscondition = (-1*ds1) >= desc.absDifference || (-1*ds1) >= ds2;
                			}
                			else if(desc.direction.equalsIgnoreCase("Any"))
                			{
                				secondAbscondition = (ds1) >= desc.absDifference || (ds1) >= ds2 || (-1*ds1) >= desc.absDifference || (-1*ds1) >= ds2;
                			}
                			
                			//Si está dentro del tiempo y NO cumple las condiciones de corte,
                			//entonces se agrega al intervalo.
		    				if((next.date.getTime()-first.date.getTime()) < (desc.maxSeparation*60*60*1000)
		    					&& !(secondAbscondition)
		    				)
		    				{
		    					interval.End = next.date;
		    					IntervalResult nextIntRes = new IntervalResult(next.result, next.date);
		    					interval.Results.add(nextIntRes);
		    					
		    					if(next.result < condMin)
			    				{
			    					condMin = next.result;
			    				}
			    				if(next.result > condMin)
			    				{
			    					condMax = next.result;
			    				}
			    				condAvg += next.result;
			    				condResults.add(next.result);
			    				condTotal++;
		    					
		    				}
		    				else //Si está fuera de tiempo o cumple las condiciones de corte, se corta y empieza un intervalo nuevo.
		    				{
		    					
		    					condAvg = (double)(condAvg/condTotal);
		    					
		    					if(condResults.size() % 2 == 0)
		    					{
		    						condMedian = condResults.get(condResults.size()/2);
		    					}
		    					else
		    					{
		    						condMedian = condResults.get((int)Math.floor(condResults.size()/2)) + condResults.get((int)Math.ceil(condResults.size()/2));
		    					}
		    					
		    					if(desc.conditions.size() > 0)
		    					{
		    						if(meetsCondition(desc, condMin, condMax, condAvg, condMedian, interval))
		    						{
		    							newIntervals.add(interval);
		    						}
		    					}
		    					else
		    					{
		    						newIntervals.add(interval);
		    					}
		    					
		    					interval = new interval(this.id, next.name, null, next.date, next.date, desc);
		    	    			IntervalResult nextIntRes = new IntervalResult(next.result, next.date);
		    	    			interval.Results.add(nextIntRes);
		    	    			
		    	    			condMin = next.result;
				    			condMax = next.result;
				    			condAvg = next.result;
				    			condMedian = next.result;
				    			condTotal = 1;
				    			
				    			condResults = new LinkedList<Double>();
				    			condResults.add(next.result);
		    				}
		    			}
		    			
		    			condAvg = (double)(condAvg/condTotal);
    					
    					if(condResults.size() % 2 == 0)
    					{
    						condMedian = condResults.get(condResults.size()/2);
    					}
    					else
    					{
    						condMedian = condResults.get((int)Math.floor(condResults.size()/2)) + condResults.get((int)Math.ceil(condResults.size()/2));
    					}
    					
    					if(desc.conditions.size() > 0)
    					{
    						if(meetsCondition(desc, condMin, condMax, condAvg, condMedian, interval))
    						{
    							newIntervals.add(interval);
    						}
    					}
    					else
    					{
    						newIntervals.add(interval);
    					}
		    			
	    			}
	    			
	    		}
	    	}
    	}
    	else if(desc.subType.equalsIgnoreCase("Categorical")) //CATEGORICAL
    	{
    		if(currInstants.size()<1)
    		{
    			return newIntervals;
    		}
    		else if(currInstants.size()==1)
    		{
    			instant first = currInstants.getFirst();
    			interval interval = new interval(this.id, first.name, null, first.date, first.date, desc);
    			IntervalResult intRes = new IntervalResult(first.strResult, first.date);
    			interval.Results.add(intRes);
    			newIntervals.add(interval);
    		}
    		else
    		{
    			while(currInstants.size()>0)
    			{
	    			instant first = currInstants.remove();
	    			interval interval = new interval(this.id, first.name, null, first.date, first.date, desc);
	    			IntervalResult intRes = new IntervalResult(first.strResult, first.date);
	    			interval.Results.add(intRes);
	    			while(currInstants.size()>0)
	    			{
	    				instant next = currInstants.remove();
	    				if((next.date.getTime()-first.date.getTime()) < (desc.maxSeparation*60*60*1000))
	    				{
	    					interval.End = next.date;
	    					IntervalResult nextIntRes = new IntervalResult(next.strResult, next.date);
	    					interval.Results.add(nextIntRes);
	    				}
	    				else
	    				{
	    					newIntervals.add(interval);
	    					interval = new interval(this.id, next.name, null, next.date, next.date, desc);
	    	    			IntervalResult nextIntRes = new IntervalResult(next.strResult, next.date);
	    	    			interval.Results.add(nextIntRes);
	    				}
	    			}
	    			newIntervals.add(interval);
    			}   			
    		}
    	}
    	else if(desc.subType.equalsIgnoreCase("Procedural") || desc.subType.equalsIgnoreCase("Microbiological") || desc.subType.equalsIgnoreCase("PoeMedical") || desc.subType.equalsIgnoreCase("Note")) //CATEGORICAL
    	{
    		if(currInstants.size()<1)
    		{
    			return newIntervals;
    		}
    		else if(currInstants.size()==1)
    		{
    			instant first = currInstants.getFirst();
    			interval interval = new interval(this.id, first.name, null, first.date, first.date, desc);
    			IntervalResult intRes = new IntervalResult(first.strResult, first.date);
    			interval.Results.add(intRes);
    			newIntervals.add(interval);
    		}
    		else
    		{
    			while(currInstants.size()>0)
    			{
	    			instant first = currInstants.remove();
	    			interval interval = new interval(this.id, first.name, null, first.date, first.date, desc);
	    			IntervalResult intRes = new IntervalResult(first.strResult, first.date);
	    			interval.Results.add(intRes);
	    			while(currInstants.size()>0)
	    			{
	    				instant next = currInstants.remove();
	    				if((next.date.getTime()-first.date.getTime()) < (desc.maxSeparation*60*60*1000))
	    				{
	    					interval.End = next.date;
	    					IntervalResult nextIntRes = new IntervalResult(next.strResult, next.date);
	    					interval.Results.add(nextIntRes);
	    				}
	    				else
	    				{
	    					newIntervals.add(interval);
	    					interval = new interval(this.id, next.name, null, next.date, next.date, desc);
	    	    			IntervalResult nextIntRes = new IntervalResult(next.strResult, next.date);
	    	    			interval.Results.add(nextIntRes);
	    				}
	    			}
	    			newIntervals.add(interval);
    			}   			
    		}
    	}
    	this.intervalsList.add(newIntervals);
    	return newIntervals;
    }