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

com.scudata.dm.comparator.ArrayComparator2 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.comparator;

import java.util.Comparator;

import com.scudata.common.ICloneable;

/**
 * ????Ƚ?????null??????С????
 * @author WangXiaoJun
 *
 */
public class ArrayComparator2 implements Comparator, ICloneable {
	private final CommonComparator []comparators;
	private final int len;
	
	public ArrayComparator2(CommonComparator []comparators, int len) {
		this.comparators = comparators;
		this.len = len;
	}

	public Object deepClone() {
		CommonComparator []cmps = new CommonComparator[len];
		for (int i = 0; i < len; ++i) {
			cmps[i] = (CommonComparator)comparators[i].deepClone();
		}
		
		return new ArrayComparator2(cmps, len);
	}
	
	public int compare(Object o1, Object o2) {
		Object []a1 = (Object[])o1;
		Object []a2 = (Object[])o2;
		
		for (int i = 0; i < len; ++i) {
			int cmp = comparators[i].compare(a1[i], a2[i]);
			if (cmp != 0) {
				return cmp;
			}
		}
		
		return 0;
	}
}