All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scudata.dm.Regions Maven / Gradle / Ivy

Go to download

SPL(Structured Process Language) A programming language specially for structured data computing.

There is a newer version: 20241126
Show newest version
package com.scudata.dm;

import java.util.ArrayList;

/**
 * ?????б???????????????????????߽?????
 * ????????????ʱ??ѹ?????????and??or??֣???????Ķ???????б??ٽ??кϲ?
 * @author WangXiaoJun
 *
 */
public class Regions {
	private ArrayList list = new ArrayList();
	
	public Regions() {
	}
	
	public Regions(Region region) {
		list.add(region);
	}
	
	public ArrayList getRegionList() {
		return list;
	}
	
	/**
	 * ??˳??????????????????Ҳ??ص?
	 * @param region
	 */
	public void addRegion(Region region) {
		list.add(region);
	}
	
	/**
	 * ????һ???????б?????????
	 * @param other ?????б?
	 * @return ?????????б??Ľ?
	 */
	public Regions and(Regions other) {
		Regions regions = new Regions();
		ArrayList list1 = this.list;
		ArrayList list2 = other.list;
		int size1 = list1.size();
		int size2 = list2.size();
		int i = 0, j = 0;
		
		while (i < size1 && j < size2) {
			Region r1 = list1.get(i);
			Region r2 = list2.get(j);
			if (r1.end < r2.start) {
				i++;
			} else if (r1.start > r2.end) {
				j++;
			} else {
				int start = r1.start < r2.start ? r2.start : r1.start;
				if (r1.end < r2.end) {
					i++;
					Region region = new Region(start, r1.end);
					regions.addRegion(region);
				} else if (r1.end == r2.end) {
					i++;
					j++;
					Region region = new Region(start, r1.end);
					regions.addRegion(region);
				} else {
					j++;
					Region region = new Region(start, r2.end);
					regions.addRegion(region);
				}
			}
		}
		
		return regions;
	}
	
	/**
	 * ????һ???????б?????????
	 * @param other ?????б?
	 * @return ?????????б??IJ?
	 */
	public Regions or(Regions other) {
		Regions regions = new Regions();
		ArrayList list1 = this.list;
		ArrayList list2 = other.list;
		int size1 = list1.size();
		int size2 = list2.size();
		int i = 0, j = 0;
		
		while (i < size1 && j < size2) {
			Region r1 = list1.get(i);
			Region r2 = list2.get(j);
			if (r1.end < r2.start) {
				i++;
				regions.addRegion(r1);
			} else if (r1.start > r2.end) {
				j++;
				regions.addRegion(r2);
			} else {
				i++;
				j++;
				int start = r1.start < r2.start ? r1.start : r2.start;
				int end = r1.end < r2.end ? r2.end : r1.end;
				Region region = new Region(start, end);
				regions.addRegion(region);
			}
		}
		
		for (; i < size1; ++i) {
			regions.addRegion(list1.get(i));
		}
		
		for (; j < size2; ++j) {
			regions.addRegion(list2.get(j));
		}
		
		return regions;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy