Revision 2321 org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/properties/MultiProviderStatistics.java

View differences:

MultiProviderStatistics.java
27 27
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
28 28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29 29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
30 31
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
31 32
import org.gvsig.raster.impl.provider.RasterProvider;
32 33

  
......
39 40
public class MultiProviderStatistics extends AbstractStatistics {
40 41
	protected Statistics[]                 statList      = null;
41 42
	protected int                          nBands        = 0;
43
	protected boolean                      forceToRecalc = false;
44
	protected RasterProvider               provider      = null;
42 45

  
43 46
	/**
44 47
	 * Constructor
......
49 52
	/**
50 53
	 * Constructor
51 54
	 */
52
	public MultiProviderStatistics(RasterProvider provider) {
53
		statList = new Statistics[]{provider.getStatistics()};
54
		this.nBands = provider.getBandCount();
55
	public MultiProviderStatistics(List<RasterProvider> providerList, RasterProvider provider) {
56
		this(providerList);
57
		this.provider = provider;
55 58
	}
56 59
	
57 60
	/**
58 61
	 * Constructor
59 62
	 */
60
	public MultiProviderStatistics(RasterProvider[] providerList) {
63
	@SuppressWarnings("unused")
64
	private MultiProviderStatistics(RasterProvider[] providerList) {
61 65
		statList = new Statistics[providerList.length];
62 66
		
63 67
		for(int i = 0; i < providerList.length; i ++) {
......
69 73
	/**
70 74
	 * Constructor
71 75
	 */
72
	public MultiProviderStatistics(List<RasterProvider> providerList) {
76
	private MultiProviderStatistics(List<RasterProvider> providerList) {
73 77
		statList = new Statistics[providerList.size()];
74 78
		for(int i = 0; i < providerList.size(); i ++) {
75 79
			if(providerList.get(i) != null) {
......
82 86
	/**
83 87
	 * Constructor
84 88
	 */
85
	public MultiProviderStatistics(Statistics[] statList, int nBands) {
89
	@SuppressWarnings("unused")
90
	private MultiProviderStatistics(Statistics[] statList, int nBands) {
86 91
		this.nBands = nBands;
87 92
		this.statList = statList;
88 93
		for(int nDataset = 0; nDataset < statList.length; nDataset ++) {
......
113 118
	 * Calcula las estadisticas recorriendo todo el fichero.
114 119
	 */
115 120
	public void calculate(double scale)throws FileNotOpenException, RasterDriverException, ProcessInterruptedException {
116
//		long t2;
117
//		long t1 = new Date().getTime();
121
		if (!forceToRecalc) {
122
			if (!isCalculated()) {
123
				try {
124
					provider.loadObjectFromRmf(SimpleProviderStatistics.class, this);
125
				} catch (RmfSerializerException e) {
126
					// Si no se puede cargar del RMF, recalcularemos las estadisticas.
127
				}
128
			}
129
			if (isCalculated())
130
				return;
131
		}
132
		
118 133
		for(int nDataset = 0; nDataset < statList.length; nDataset ++) {
119 134
			statList[nDataset].calculate(scale);
120 135
		}
......
126 141
		}
127 142

  
128 143
		calculated = true;
129
//		t2 = new Date().getTime();
130
//		System.out.println("Estadisticas MultiFile: " + ((t2 - t1) / 1000D) + ", secs.");
144
		forceToRecalc = false;
145
		try {
146
			provider.saveObjectToRmf(Statistics.class, this);
147
		} catch (RmfSerializerException e) {
148
			// No salva a rmf
149
		}
150
		
131 151
	}
132 152
	
133
	/*
134
	 * (non-Javadoc)
135
	 * @see org.gvsig.raster.impl.dataset.properties.AbstractStatistics#resetPercent()
136
	 */
137 153
	public void resetPercent() {
138 154
		for (int i = 0; i < statList.length; i++) {
139 155
			statList[i].resetPercent();
140 156
		}
141 157
	}
142 158

  
143
	/*
144
	 * (non-Javadoc)
145
	 * @see org.gvsig.raster.impl.dataset.properties.AbstractStatistics#getPercent()
146
	 */
147 159
	public int getPercent() {
148 160
		int sum = 0;
149 161
		for (int i = 0; i < statList.length; i++) {
......
152 164
		return sum / statList.length;
153 165
	}
154 166

  
155
	/**
156
	 * Cuando se llama a este m?todo fuerza que la siguiente petici?n de estad?sticas
157
	 * no sea le?da de RMF y sean recalculadas por completo.
158
	 * @param forceToRecalc
159
	 */
160 167
	public void forceToRecalc() {
161
		for(int i = 0; i < statList.length; i ++)
162
			statList[i].forceToRecalc();
168
		this.forceToRecalc = true;
163 169
	}
164 170

  
165 171
	/**
......
211 217
		return calculated;
212 218
	}
213 219

  
214
	/*
215
	 * (non-Javadoc)
216
	 * @see org.gvsig.raster.impl.store.properties.AbstractStatistics#getBandCount()
217
	 */
218 220
	public int getBandCount() {
219 221
		if(bandCount <= 0) {
220 222
			for(int i = 0; i < statList.length; i ++)
......
223 225
		return bandCount;
224 226
	}
225 227
	
226
	/*
227
	 * (non-Javadoc)
228
	 * @see org.gvsig.raster.impl.store.properties.AbstractStatistics#setBandCount(int)
229
	 */
230 228
	public void setBandCount(int bandCount) {
231 229
		this.bandCount = bandCount;
232 230
	}
......
240 238
		return statList != null ? statList.length :0;
241 239
	}
242 240

  
243
	/*
244
	 * (non-Javadoc)
245
	 * @see org.gvsig.fmap.dal.coverage.store.props.Statistics#cloneStatistics()
246
	 */
247 241
	public Statistics cloneStatistics() {
248 242
		MultiProviderStatistics s = new MultiProviderStatistics();
249 243
		s.statList = statList;

Also available in: Unified diff