/*
 * JEF - Copyright 2009-2010 Jiyi (mr.jiyi@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jef.common.wrapper;

import java.util.Iterator;

import jef.common.ContinuedRange;

/**
 * 描述一个含头含尾的数字区间
 * @author Administrator
 *
 */
public class IntRange extends ContinuedRange<Integer> implements Iterable<Integer>{
	private static final long serialVersionUID = 8871503409414219286L;
	private int start;
	private int end;
	public IntRange(int start,int end){
		this.start=start;
		this.end=end;
	}
	
	public String toString() {
		return start + ".." + end;
	}
	
	
	public final boolean isBeginIndexInclusive() {
		return true;
	}
	
	public final boolean isEndIndexInclusive() {
		return true;
	}
	
	
	public Integer getEnd() {
		return end;
	}

	
	public Integer getStart() {
		return start;
	}
	
	public boolean contains(double num) {
		return num>=start && num<=end;
	}
	
	public boolean contains(float num) {
		return num>=start && num<=end;
	}
	
	public boolean contains(long num) {
		return num>=start && num<=end;
	}
	
	public Iterator<Integer> iterator(){
		return new Iterator<Integer>(){
			private int now=start;
			
			public boolean hasNext() {
				return now<=end;
			}

			
			public Integer next() {
				return now++;
			}

			
			public void remove() {
				throw new UnsupportedOperationException();
			}
			
		};
	}

	@Override
	public void extendTo(Integer date) {
		if(date<start){
			start=date;
		}else if(date>end){
			end=date;
		}
	}

	public int size() {
		return end-start+1;
	}
	
	public String[] toStartLimit(){
		int s=start - 1;
		if(s<0)s=0;
		return new String[]{String.valueOf(s),String.valueOf(end-s)};
	}
	
	/**
	 * 转换为SQL语句中的start和limit
	 * @return
	 */
	public int[] toStartLimitSpan(){
		int s=start - 1;
		if(s<0)s=0;
		return new int[]{s,end-s};
	}
	
}

@@ -2035,292 +2035,6 @@
 %0A%09%7D%0A
-%09%0A%09public String%5B%5D toStartLimit()%7B%0A%09%09int s=start - 1;%0A%09%09if(s%3C0)s=0;%0A%09%09return new String%5B%5D%7BString.valueOf(s),String.valueOf(end-s)%7D;%0A%09%7D%0A%09%0A%09/**%0A%09 * %E8%BD%AC%E6%8D%A2%E4%B8%BASQL%E8%AF%AD%E5%8F%A5%E4%B8%AD%E7%9A%84start%E5%92%8Climit%0A%09 * @return%0A%09 */%0A%09public int%5B%5D toStartLimitSpan()%7B%0A%09%09int s=start - 1;%0A%09%09if(s%3C0)s=0;%0A%09%09return new int%5B%5D%7Bs,end-s%7D;%0A%09%7D%0A%09%0A
 %7D%0A

Update versions.