public Domain cap(Domain d) {
		if (!(d instanceof IntDomain))
			return EMPTY;
		IntDomain new_d = new IntDomain();
		IntDomain d0 = this;
		IntDomain d1 = (IntDomain) d;
		try {
			int[] interval;
			int min0, max0, min1, max1;
			int i0 = 0;
			int i1 = 0;
			while (i0 < d0.intervals.size() && i1 < d1.intervals.size()) {
				interval = d0.intervals.get(i0);
				min0 = interval[0];
				max0 = interval[1];
				interval = d1.intervals.get(i1);
				min1 = interval[0];
				max1 = interval[1];
				if (max0 < min1) {
					i0++;
					continue;
				}
				if (max1 < min0) {
					i1++;
					continue;
				}
				interval = new int[2];
				interval[0] = Math.max(min0, min1);
				interval[1] = Math.min(max0, max1);
				new_d.intervals.add(interval);
				if (max0 <= max1)
					i0++;
				if (max1 <= max0)
					i1++;
			}
		} catch (IndexOutOfBoundsException e) {
		}
		new_d.updateSize();
		new_d.updateMinMax();
		if (new_d.isEmpty())
			return EMPTY;
		return new_d;
	}