/***************************************************************
* jHepWork.
* Original Developer
* Dale Visser (dale@visser.name)
* S.Chekanov
* Based on nuclear reactor simulator software (open source)
**************************************************************/
/*
* Multiplet.java
*
* Created on February 14, 2001, 1:30 PM
*/
package jhpro.tseries;
import java.util.*;
import org.apache.commons.math3.util.FastMath;
/**
* Class designed to store peaks.
* @author jam & sergei
* @version
*/
public class Multiplet extends Vector {
/**
*
*/
private static final long serialVersionUID = 1L;
/** Creates new Multiplet */
public Multiplet() {
}
public Multiplet(Peak p){
this();
addPeak(p);
}
public Peak [] getAllPeaks(){
Object [] arr=toArray();
Peak [] rval = new Peak[arr.length];
for (int p = 0; p0){
for (int i=0;i max) large.addPeak(peak);
}
removeAll(large);//remove any peaks in small from this multiplet
return size();
}
/**
* Returns peak nearest given centroid if distance is less than the given tolerance.
*/
public Peak getPeakNear(double centroid, double tolerance){
double diff1= 2*tolerance;
double diff2;
Peak p1, p2;
Iterator it = (new TreeSet(this)).iterator();
if (it.hasNext()) {
p1 = (Peak)(it.next());
diff1=FastMath.abs(p1.getPosition()-centroid);
} else {
return null;
}
while (it.hasNext()){
p2 = (Peak)(it.next());
diff2 = FastMath.abs(p2.getPosition()-centroid);
if (diff2 < diff1) {
p1=p2;
diff1=diff2;
}
}
if (diff1 <= tolerance) {
return p1;
} else {
return null;
}
}
/**
* Returns a new multiplet containing only the last n peaks of this multiplet.
*/
public Multiplet lastPeaks(int n) {
Multiplet rval=new Multiplet();
for (int i=size()-n ; i < size(); i++) rval.addPeak(getPeak(i));
return rval;
}
static Multiplet combineMultiplets(Multiplet [] marray){
Multiplet rval = new Multiplet();
for (int i=0; i
Ads help maintain this website.