package edu.vt.marian.search; import java.util.*; import java.io.*; import edu.vt.marian.common.*; /** Scaled Weighted Object Set. A transformation of some other WtdObjSet where every element has been scaled by the same factor. @author Robert France @see WtdObjSet */ public class ScaledWtdObjSet implements WtdObjSet { protected Debug debug; protected WtdObjSet set; protected Weight scFactor; /** Enumeration for a Scaled Weighted Object Set.
NOTE: We presume that the base Enumeration is creating new WtdObjs for distribution to the outside world. Thus we only need to scale them, not copy them. Nor do we need to copy the baseEnumeration in the constructor, as it is ours and ours alone.
In this implementation, each Enumeration does its own scaling. This is potentially wasteful if the set spawns many Enumerations. We don't really expect this to happen, but if it does some cache should be added.
Synchronization Note: baseEnumeration should alrady be synchronizing
calls to all at-risk methods, so this does not.
@author Robert France
@see WtdObjSetEnumeration
*/
public class Enum implements WtdObjSetEnumeration
{
protected WtdObjSetEnumeration baseEnum;
public Enum(WtdObjSetEnumeration baseEnumeration)
{
baseEnum = baseEnumeration;
}
public Object nextElement() throws NoSuchElementException
{
WtdObj nextObj = (WtdObj) baseEnum.nextElement();
nextObj.scale(scFactor);
return( nextObj );
}
public boolean hasMoreElements()
{
return( baseEnum.hasMoreElements() );
}
public void skip(int k)
{
baseEnum.skip(k);
}
public int sample(int num, WtdObjBag sampleBag)
{
int base = sampleBag.size();
int Err = baseEnum.sample(num, sampleBag);
int i; // We cannot simply use
for (i=base; i