Create CalendarPeriodAssociative using an adding function.<br>
PeriodAssociative are periods associated with an integer, result of the
add function.

@param periodsAndValues
@param addFunction
@return CalendarPeriodAssociative
356961
public <T> CalendarPeriodAssociative<T> MakeUpCalendarPeriodAssociative( List<Tree> trees, List<T> values, CalendarPeriodAssociative.AddFunction<T> addFunction )
	{
		if( trees.size() != values.size() )
		{
			assert false : "Calendar.MakeUpCalendarPeriodAssociative : trees and values should have the same size !";
			return null;
		}

		int nbPeriod = trees.size();
		if( nbPeriod == 0 )
			return new CalendarPeriodAssociative<T>();

		// get the first non empty period
		CalendarPeriodAssociative<T> res = null;
		int first = 0;
		do
		{
			Tree tree = trees.get( first );
			T value = values.get( first );

			// PeriodAssociative firstPeriodAndValue = periodsAndValues.get(
			// first );
			// Tree tree = Parse( firstPeriodAndValue.getFrom() );
			if( tree.getNbDays() == 0 )
			{
				first++;
				if( first >= nbPeriod )
					return new CalendarPeriodAssociative<T>();
				continue;
			}

			CalendarPeriod flat = tree.getFlat();
			res = new CalendarPeriodAssociative<T>();
			res.Init( flat, value );

			break;
		}
		while( true );

		if( res == null )
			return null; // no non-empty period

		for( int i = first + 1; i < nbPeriod; i++ )
		{
			Tree tree = trees.get( i );
			T value = values.get( i );

			if( tree.getNbDays() == 0 )
			{
				// echo "IGNORING N PERIOD $i (" . $periodsAndValues[$i][0] .
				// ") BECAUSE EMPTY<br>";
				continue;
			}

			CalendarPeriod flat = tree.getFlat();
			CalendarPeriodAssociative<T> assoc = new CalendarPeriodAssociative<T>();
			assoc.Init( flat, value );

			if( res.Add( assoc, addFunction ) == null )
				return null;
		}

		return res;
	}
729710
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
        for (int i = 0, isize = period.size(); i < isize; i++) {
            DurationFieldType type = period.getFieldType(i);
            int value = period.getValue(i);
            checkAndUpdate(type, values, value);
        }
        return values;
    }
1204166
public GroupOptions addGroupByFunction(Function function) {

		Assert.notNull(function, "Function for grouping must not be null.");
		groupByFunctions.add(function);
		return this;
	}
516532
public void addArgsFor(String[] variables, DifferentialFunction function) {
        if (function.getOwnName() == null)
            throw new ND4JIllegalStateException("Instance id can not be null. Function not initialized properly");

        //double check if function contains placeholder args
        for (val varName : variables) {
            if (isPlaceHolder(varName)) {
                placeHolderFunctions.add(function.getOwnName());
            }
        }

        //Add function if it doesn't exist
        //TODO could "not existing" be a bug sometimes?
        if(!ops.containsKey(function.getOwnName())){
            ops.put(function.getOwnName(), SameDiffOp.builder().name(function.getOwnName()).op(function).build());
        }

        //Update variable 'inputs to op' accounting for repeated inputs (like y = x+x)
        ops.get(function.getOwnName()).setInputsToOp(Arrays.asList(variables));     //Duplicate variables OK/required here

        for (String variableName : variables) {
            List<String> funcs = this.variables.get(variableName).getInputsForOp();
            if (funcs == null) {
                funcs = new ArrayList<>();
                this.variables.get(variableName).setInputsForOp(funcs);
            }
            if(!funcs.contains(function.getOwnName()))  //Avoid duplicates for function names.
                funcs.add(function.getOwnName());
        }
    }
1320763
public static long parsePositiveTimePeriod(String period)
   {
      long retval = parseTimePeriod(period);
      if (retval < 0)
      {
         throw new NumberFormatException("Negative input time period: '" + period + "'");
      }
      return retval;
   }
509540
public List<Period> _Merge( List<Period> pPeriods )
	{
		List<Period> result = new ArrayList<Period>();

		int count = pPeriods.size();
		if( count == 0 )
			return result;

		// copy the first period
		result.add( pPeriods.get( 0 ) );

		// init
		int resIdx = 0;
		int i = 1;

		while( i < count )
		{
			if( pPeriods.get( i ).getFrom().compareTo( CalendarFunctions.date_add_day( result.get( resIdx ).getTo(), 1 ) ) > 0 )
			{
				// period is disjointed, so add it
				result.add( pPeriods.get( i ) );
				resIdx++;
			}
			else
			{
				// period is jointed so merge
				result.get( resIdx ).setTo( CalendarFunctions.max_date( result.get( resIdx ).getTo(), pPeriods.get( i ).getTo() ) );
			}
			i++;
		}

		return result;
	}
985639
function icaltime_add(aDuration) {
      var mult = (aDuration.isNegative ? -1 : 1);

      // because of the duration optimizations it is much
      // more efficient to grab all the values up front
      // then set them directly (which will avoid a normalization call).
      // So we don't actually normalize until we need it.
      var second = this.second;
      var minute = this.minute;
      var hour = this.hour;
      var day = this.day;

      second += mult * aDuration.seconds;
      minute += mult * aDuration.minutes;
      hour += mult * aDuration.hours;
      day += mult * aDuration.days;
      day += mult * 7 * aDuration.weeks;

      this.second = second;
      this.minute = minute;
      this.hour = hour;
      this.day = day;

      this._cachedUnixTime = null;
    }
8783
public XMLGregorianCalendar newGMonthDay(int month, int day) {
        XMLGregorianCalendar cal=dataFactory.newXMLGregorianCalendar();
        cal.setMonth(month);
        cal.setDay(day);
        return cal;
    }
18891
static PlainDate doAdd(
        CalendarUnit unit,
        PlainDate context,
        long amount,
        int policy
    ) {

        switch (unit) {
            case MILLENNIA:
                return doAdd(
                    CalendarUnit.MONTHS,
                    context,
                    MathUtils.safeMultiply(amount, 12 * 1000),
                    policy);
            case CENTURIES:
                return doAdd(
                    CalendarUnit.MONTHS,
                    context,
                    MathUtils.safeMultiply(amount, 12 * 100),
                    policy);
            case DECADES:
                return doAdd(
                    CalendarUnit.MONTHS,
                    context,
                    MathUtils.safeMultiply(amount, 12 * 10),
                    policy);
            case YEARS:
                return doAdd(
                    CalendarUnit.MONTHS,
                    context,
                    MathUtils.safeMultiply(amount, 12),
                    policy);
            case QUARTERS:
                return doAdd(
                    CalendarUnit.MONTHS,
                    context,
                    MathUtils.safeMultiply(amount, 3),
                    policy);
            case MONTHS:
                long months =
                    MathUtils.safeAdd(context.getEpochMonths(), amount);
                return PlainDate.fromEpochMonths(
                    context,
                    months,
                    context.dayOfMonth,
                    policy);
            case WEEKS:
                return doAdd(
                    CalendarUnit.DAYS,
                    context,
                    MathUtils.safeMultiply(amount, 7),
                    policy);
            case DAYS:
                return addDays(context, amount);
            default:
                throw new UnsupportedOperationException(unit.name());
        }

    }
59461
function preparePeriod(period, value, year) {

    var range;
    var subUnit;
    var start;
    var length;
    var unit;

    switch (period) {
      case 'year':
        unit = 'month';
        break;
      case 'month':
        unit = 'dayOfYear';
        break;
      case 'dayOfYear':
        unit = 'hourOfYear';
        break;
    }

    var result = {
      year: year,
      period: period,
      unit: unit
    };

    var utc = moment().utc();

    if (year) {
      utc.year(year);
    } else {
      year = utc.year();
    }

    if (value || value ===0) {
      utc[period](value);
    } else {
      value = utc[period]();
    }

    result.value = value;
    result.period = period;

    switch (unit) {

      case 'month':
        switch (period) {
          case 'year':
            range = _.range(12);
            break;

          default:
        }

        subUnit = 'dayOfYear';
        break;

      case 'dayOfYear':

        switch (period) {
          case 'month':
            start = utc.month(value).date(1).dayOfYear();
            length = utc.month(value).daysInMonth();

            range = _.range(start, start + length);
            break;

          default:
        }

        subUnit = 'hourOfYear';
        break;

      case 'hourOfYear':

        switch (period) {
          case 'dayOfYear':
            start = utc.dayOfYear(value).hour(0).hourOfYear();
            length = 24;

            range = _.range(start, start + length);
            break;

          default:
        }
        break;
    }

    result.subUnit = subUnit;

    if (!range) {

      var err = new Error('Could not calculate the range');
      err.statusCode = 400;
      err.code = 'NO_RANGE_SET';

      throw err;
    }

    return {
      unit: unit,
      range: range,
      year: year,
      result: result
    };

  }
890361
private static Period create(int years, int months, int days) {
        if ((years | months | days) == 0) {
            return ZERO;
        }
        return new Period(years, months, days);
    }
686137
private void addMonth(int i) {
        Calendar cal = Calendar.getInstance();
        cal.set(getDisplayYear(), getDisplayMonth() - 1, 1);
        int month = cal.get(Calendar.MONTH) + 1;
        if (i > 0 && month == 12) {
            addYear(1);
        }

        if (i < 0 && month == 1) {
            addYear(-1);
        }
        cal.add(Calendar.MONTH, i);

        monthTextField.setText(String.valueOf(cal.get(Calendar.MONTH) + 1));

    }
168280
function(year, includeWeekends) {
    initialize(year);

    includeWeekends = includeWeekends || false;

    var self = this;
    var holidays = [];

    if (!includeWeekends) {
      self.year.discardWeekends();
    }

    Object.keys(self.year.holidays).forEach(function(month) {
      self.year.holidays[month].forEach(function(holiday) {
        holidays.push(holiday);
      });
    });

    return holidays;
  }
708695
@Override
    public ChronoPeriod plus(TemporalAmount amountToAdd) {
        if (amountToAdd instanceof ChronoPeriodImpl) {
            ChronoPeriodImpl amount = (ChronoPeriodImpl) amountToAdd;
            if (amount.getChronology().equals(getChronology())) {
                return new ChronoPeriodImpl(
                        chronology,
                        Jdk8Methods.safeAdd(years, amount.years),
                        Jdk8Methods.safeAdd(months, amount.months),
                        Jdk8Methods.safeAdd(days, amount.days));
            }
        }
        throw new DateTimeException("Unable to add amount: " + amountToAdd);
    }
1106387
public final boolean add(final Period period) {
        if (isUtc()) {
            period.setUtc(true);
        }
        else {
            period.setTimeZone(timezone);
        }
        return periods.add(period);
    }
762897
public static Date addSeconds(final Date date, final int addSeconds)
	{
		final Calendar dateOnCalendar = Calendar.getInstance();
		dateOnCalendar.setTime(date);
		dateOnCalendar.add(Calendar.SECOND, addSeconds);
		return dateOnCalendar.getTime();
	}
804171
public List<Period> _Combine( List<Period> periods1, List<Period> periods2 )
	{
		List<Period> result = new ArrayList<Period>();

		int count1 = periods1.size();
		int count2 = periods2.size();

		int i = 0;
		int j = 0;
		while( i < count1 && j < count2 )
		{
			if( periods1.get( i ).getFrom().compareTo( periods2.get( j ).from ) <= 0 )
			{
				result.add( periods1.get( i ) );
				i++;
			}
			else
			{
				result.add( periods2.get( j ) );
				j++;
			}
		}
		while( i < count1 )
		{
			result.add( periods1.get( i ) );
			i++;
		}
		while( j < count2 )
		{
			result.add( periods2.get( j ) );
			j++;
		}

		return result;
	}