Package net.sourceforge.jiu.color.data
Class ArrayHistogram1D
- java.lang.Object
-
- net.sourceforge.jiu.color.data.ArrayHistogram1D
-
- All Implemented Interfaces:
Histogram1D
public class ArrayHistogram1D extends Object implements Histogram1D
A one-dimensional histogram data class that stores its counters in memory. Counters are stored in anint
array of lengthgetMaxValue()
+ 1
so thatk
values will requirek * 4
bytes.- Author:
- Marco Schmidt
-
-
Field Summary
Fields Modifier and Type Field Description private int[]
data
-
Constructor Summary
Constructors Constructor Description ArrayHistogram1D(int numValues)
Creates a histogram with the argument's number of values, from0
tonumValues - 1
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Sets all counters to zero.int
getEntry(int index)
Returns the counter value for the given index.int
getMaxValue()
Returns the maximum allowed index.int
getNumUsedEntries()
Returns the number of used entries (those entries with a counter value larger than zero).void
increaseEntry(int index)
Increases the counter value of the given index by one.void
setEntry(int index, int newValue)
Sets one counter to a new value.
-
-
-
Constructor Detail
-
ArrayHistogram1D
public ArrayHistogram1D(int numValues)
Creates a histogram with the argument's number of values, from0
tonumValues - 1
.- Parameters:
numValues
- the number of counters in the histogram; must be one or larger- Throws:
IllegalArgumentException
- if the argument is smaller than one
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:Histogram1D
Sets all counters to zero.- Specified by:
clear
in interfaceHistogram1D
-
getEntry
public int getEntry(int index)
Description copied from interface:Histogram1D
Returns the counter value for the given index.- Specified by:
getEntry
in interfaceHistogram1D
- Parameters:
index
- the zero-based index of the desired counter value- Returns:
- the counter value
-
getMaxValue
public int getMaxValue()
Description copied from interface:Histogram1D
Returns the maximum allowed index. The minimum is always 0.- Specified by:
getMaxValue
in interfaceHistogram1D
- Returns:
- the maximum index value
-
getNumUsedEntries
public int getNumUsedEntries()
Description copied from interface:Histogram1D
Returns the number of used entries (those entries with a counter value larger than zero).- Specified by:
getNumUsedEntries
in interfaceHistogram1D
- Returns:
- number of non-zero counter values
-
increaseEntry
public void increaseEntry(int index)
Description copied from interface:Histogram1D
Increases the counter value of the given index by one. Same semantics assetEntry(index, getEntry(index) + 1);
- Specified by:
increaseEntry
in interfaceHistogram1D
- Parameters:
index
- index into the histogram
-
setEntry
public void setEntry(int index, int newValue)
Description copied from interface:Histogram1D
Sets one counter to a new value.- Specified by:
setEntry
in interfaceHistogram1D
- Parameters:
index
- index of the counter to be changednewValue
- new value for that counter
-
-