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 anintarray of lengthgetMaxValue()+ 1so thatkvalues will requirek * 4bytes.- 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, from0tonumValues - 1.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Sets all counters to zero.intgetEntry(int index)Returns the counter value for the given index.intgetMaxValue()Returns the maximum allowed index.intgetNumUsedEntries()Returns the number of used entries (those entries with a counter value larger than zero).voidincreaseEntry(int index)Increases the counter value of the given index by one.voidsetEntry(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, from0tonumValues - 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:Histogram1DSets all counters to zero.- Specified by:
clearin interfaceHistogram1D
-
getEntry
public int getEntry(int index)
Description copied from interface:Histogram1DReturns the counter value for the given index.- Specified by:
getEntryin interfaceHistogram1D- Parameters:
index- the zero-based index of the desired counter value- Returns:
- the counter value
-
getMaxValue
public int getMaxValue()
Description copied from interface:Histogram1DReturns the maximum allowed index. The minimum is always 0.- Specified by:
getMaxValuein interfaceHistogram1D- Returns:
- the maximum index value
-
getNumUsedEntries
public int getNumUsedEntries()
Description copied from interface:Histogram1DReturns the number of used entries (those entries with a counter value larger than zero).- Specified by:
getNumUsedEntriesin interfaceHistogram1D- Returns:
- number of non-zero counter values
-
increaseEntry
public void increaseEntry(int index)
Description copied from interface:Histogram1DIncreases the counter value of the given index by one. Same semantics assetEntry(index, getEntry(index) + 1);- Specified by:
increaseEntryin interfaceHistogram1D- Parameters:
index- index into the histogram
-
setEntry
public void setEntry(int index, int newValue)Description copied from interface:Histogram1DSets one counter to a new value.- Specified by:
setEntryin interfaceHistogram1D- Parameters:
index- index of the counter to be changednewValue- new value for that counter
-
-