gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / src / main / java / org / gvsig / raster / cache / buffer / impl / stripecache / horizontal / CacheBandListHorz.java @ 991
History | View | Annotate | Download (2.71 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.gvsig.raster.cache.buffer.exception.WrongParameterException; |
6 |
import org.gvsig.raster.cache.buffer.impl.RasterBuffer; |
7 |
import org.gvsig.raster.cache.buffer.impl.stripecache.CacheBand; |
8 |
import org.gvsig.raster.cache.buffer.impl.stripecache.LRUAlgorithm; |
9 |
|
10 |
/**
|
11 |
* List of bands
|
12 |
*
|
13 |
* 21/10/2008
|
14 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
15 |
*/
|
16 |
public class CacheBandListHorz extends ArrayList<CacheBand> { |
17 |
private static final long serialVersionUID = 1L; |
18 |
|
19 |
/*
|
20 |
* (non-Javadoc)
|
21 |
* @see java.util.ArrayList#remove(int)
|
22 |
*/
|
23 |
public CacheBand remove(int pos) { |
24 |
CacheBand removedElement = super.remove(pos);
|
25 |
for (int i = pos; i < size(); i++) { |
26 |
CacheBand b = get(i); |
27 |
b.setBandNumber(b.getBandNumber() - 1);
|
28 |
} |
29 |
return removedElement;
|
30 |
} |
31 |
|
32 |
/**
|
33 |
* Add a new band in the selected position
|
34 |
* @param pos Position to add a band
|
35 |
* @param cache Cache
|
36 |
* @param lru LRUAlgorithm
|
37 |
* @param dataType
|
38 |
* @return Band added
|
39 |
*/
|
40 |
public CacheBand add(int pos, CacheHorzImpl cache, LRUAlgorithm lru, int dataType) { |
41 |
for (int i = pos; i < size(); i++) |
42 |
get(i).setBandNumber(get(i).getBandNumber() + 1);
|
43 |
switch(dataType) {
|
44 |
case RasterBuffer.TYPE_BYTE: ByteBand bb = new ByteBand(cache, lru, pos); |
45 |
add(pos, bb); |
46 |
return bb;
|
47 |
case RasterBuffer.TYPE_SHORT: ByteBand sb = new ByteBand(cache, lru, pos); |
48 |
add(pos, sb); |
49 |
return sb;
|
50 |
case RasterBuffer.TYPE_INT: ByteBand ib = new ByteBand(cache, lru, pos); |
51 |
add(pos, ib); |
52 |
return ib;
|
53 |
case RasterBuffer.TYPE_FLOAT: ByteBand fb = new ByteBand(cache, lru, pos); |
54 |
add(pos, fb); |
55 |
return fb;
|
56 |
case RasterBuffer.TYPE_DOUBLE: ByteBand db = new ByteBand(cache, lru, pos); |
57 |
add(pos, db); |
58 |
return db;
|
59 |
} |
60 |
return null; |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Swap bands according to positions selected in bandPosition parameter.
|
65 |
*
|
66 |
* @param bandPosition
|
67 |
* New order for the bands in the array. Each position in the array represent the old band
|
68 |
* .The number that it contains represent the new position of that band. For instance, an
|
69 |
* array with values {1, 0, 2, 3} means that it has four bands and the band number one is swaped
|
70 |
* with the band number zero. The bands two and three don't change its position in this example.
|
71 |
* @throws WrongParameterException
|
72 |
*/
|
73 |
public void swapBands(int[] bandPosition) throws WrongParameterException { |
74 |
CacheBandListHorz cbl = (CacheBandListHorz)this.clone();
|
75 |
for (int i = 0; i < bandPosition.length; i++) { |
76 |
CacheBand cb = cbl.get(bandPosition[i]); |
77 |
cb.setBandNumber(i); |
78 |
add(i, cb); |
79 |
remove(size() - 1);
|
80 |
} |
81 |
} |
82 |
} |