Implements an Axis of an NCube. When modeling, think of an axis as a 'condition' or decision point. An input variable (like 'X:1' in a cartesian coordinate system) is passed in, and the Axis's job is to locate the column that best matches the input, as quickly as possible.
Five types of axes are supported, DISCRETE, RANGE, SET, NEAREST, and RULE. DISCRETE matches discrete values with .equals(). Locates items in O(1) RANGE matches [low, high) values in O(Log n) time. SET matches repeating DISCRETE and RANGE values in O(Log n) time. NEAREST finds the column matching the closest value to the input. Runs in O(Log n) for Number and Date types, O(n) for String, Point2D, Point3D, LatLon. RULE fires all conditions that evaluate to true. Runs in O(n).
Modifiers | Name | Description |
---|---|---|
static interface |
Axis.AxisRefProvider |
Implement to provide data for this Axis |
Modifiers | Name | Description |
---|---|---|
protected static long |
BASE_AXIS_ID |
|
static int |
DISPLAY |
|
static java.lang.String |
DONT_CARE |
|
protected static long |
MAX_COLUMN_ID |
|
static int |
SORTED |
|
protected boolean |
fireAll |
|
protected long |
id |
|
protected java.util.Map<java.lang.String, java.lang.Object> |
metaProps |
Constructor and description |
---|
Axis
(java.lang.String name, AxisType type, AxisValueType valueType, boolean hasDefault, int order = SORTED, long id = 1, boolean fireAll = true) Use this constructor for non-rule Axes. |
Axis
(java.lang.String name, long id, boolean hasDefault, Axis.AxisRefProvider axisRefProvider) Use this constructor to create a 'reference' axis. |
Type Params | Return Type | Name and description |
---|---|---|
|
Column |
addColumn(java.lang.Comparable value, java.lang.String colName = null, java.lang.Long suggestedId = null, java.util.Map<java.lang.String, java.lang.Object> colMetaProps = null) Add a new Column to this axis. |
|
Column |
addColumn(Column column) Add a Column from another Axis to this Axis. |
|
protected Column |
addColumnInternal(Column column) |
|
void |
addMetaProperties(java.util.Map<java.lang.String, java.lang.Object> props) Add a Map of meta properties all at once. |
|
boolean |
areAxisPropsEqual(java.lang.Object o)
|
|
void |
breakReference() Break the reference to the other axis. |
|
protected void |
clearIndexes() |
|
void |
clearMetaProperties() Remove all meta properties associated to this Axis. |
|
boolean |
contains(java.lang.Comparable value) @param value to test against this Axis |
|
protected Column |
createColumnFromValue(java.lang.Comparable value, java.lang.Long suggestedId, java.util.Map<java.lang.String, java.lang.Object> metaProperties = null) Given the passed in 'raw' value, get a Column from the passed in value, which entails converting the 'raw' value to the correct type, promoting the value to the appropriate internal value for comparison, and so on. |
|
protected Column |
deleteColumn(java.lang.Comparable value) This method deletes a column from an Axis. |
|
protected Column |
deleteColumnById(long colId) |
|
Column |
findColumn(java.lang.Comparable value) Locate the column (value) along an axis. |
|
Column |
findColumnByName(java.lang.String colName) Locate a column on an axis using the 'name' meta property. |
|
java.util.List<Column> |
findColumns(java.util.Map<java.lang.String, java.lang.Object> requiredProps) Find all rule Columns which have meta-properties that match all of the passed in required meta-properties. |
|
java.util.List<Column> |
findColumns(groovy.lang.Closure closure) Pass the Axis (this) to the passed in Closure. |
|
java.util.List<Column> |
findColumns(java.util.Collection<java.lang.String> orchestration) Find all Columns which have a name (meta-property name) in the passed in Collection. |
|
java.lang.String |
getAxisPropString()
|
|
Column |
getColumnById(long colId) Use Column id to retrieve column (hash map lookup), O(1) |
|
int |
getColumnOrder() @return SORTED (0) or DISPLAY (1) which indicates whether the getColumns() and getColumnsWithoutDefault() methods will return the columns in sorted order or display order (user order). |
|
java.util.List<Column> |
getColumns()
|
|
java.util.List<Column> |
getColumnsWithoutDefault()
|
|
protected long |
getDefaultColId() |
|
Column |
getDefaultColumn() @return Column (the default Column instance whose column.value is null) or null if there is no default column. |
|
protected static java.lang.String |
getDisplayColumnName(Column column) Return a display-friendly String for the passed in column. |
|
long |
getId() @return long id of this Axis |
|
java.util.Map<java.lang.String, java.lang.Object> |
getMetaProperties() @return Map (case insensitive keys) containing meta (additional) properties for the n-cube. |
|
java.lang.Object |
getMetaProperty(java.lang.String key) Fetch the value associated to the passed in Key from the MetaProperties (if any exist). |
|
java.lang.String |
getName()
|
|
protected long |
getNextColId() @return long next id for use on a new Column. |
|
protected int |
getRangeToColSize() This method is only for testing purposes |
|
java.lang.String |
getReferenceAxisName() @return String name of referenced cube axis (or null if this is not a reference axis) |
|
java.lang.String |
getReferenceCubeName() @return String name of referenced cube (or null if this is not a reference axis) |
|
ApplicationID |
getReferencedApp() @return ApplicationID of the referenced cube (if this Axis is a reference Axis, or null otherwise). |
|
protected java.util.List<Column> |
getRuleColumnsStartingAt(java.lang.String ruleName) Fetch Columns on a rule axis where the passed in name is the first rule desired. |
|
ApplicationID |
getTransformApp() @return ApplicationID of the transformer cube (if this Axis is a reference Axis and it specifies a transformer cube, otherwise null). |
|
java.lang.String |
getTransformCubeName() @return String name of referenced cube (or null if this is not a reference axis) |
|
AxisType |
getType() @return AxisType of this Axis, which is one of: DISCRETE, RANGE, SET, NEAREST, RULE |
|
protected java.lang.Comparable |
getValueToLocateColumn(Column column) Get a Comparable value that can be used to locate a Column on this axis. |
|
AxisValueType |
getValueType() @return AxisValueType of this Axis, which is one of: STRING, LONG, BIG_DECIMAL, DOUBLE, DATE, EXPRESSION, COMPARABLE |
|
boolean |
hasDefaultColumn() @return boolean true if this Axis has a default column, false otherwise. |
|
boolean |
isFireAll() @return boolean true if this RULE axis is set to fire all conditions that evaluate to true, false otherwise. |
|
boolean |
isReference()
|
|
boolean |
isReferenceTransformed() @return boolean true if this Axis is a reference Axis AND there is a transformer app specified for the reference. |
|
protected Column |
locateDeltaColumn(Column source) Find the Column on 'this' axis which has the same ID as the passed in axis. |
|
void |
makeReference(ApplicationID refAppId, java.lang.String refCubeName, java.lang.Object refAxisName) |
|
static java.lang.Comparable |
promoteValue(AxisValueType srcValueType, java.lang.Comparable value) Convert passed in value to a similar value of the highest type. |
|
protected void |
reindex(long newId = getId() Re-index the axis (optionally assign new ID to the axis). |
|
java.lang.Object |
removeMetaProperty(java.lang.String key) Remove a meta-property entry |
|
void |
removeTransform() Remove transform from reference axis. |
|
void |
setColumnOrder(int order) Set the ordering for the axis. |
|
void |
setFireAll(boolean fireAll) Set the 'fire-all' mode - true to have all conditions that evaluate to true have the associated cell execute, false for only the first condition that is true to have it's associated cell execute. |
|
void |
setId(long id) Set long id of this Axis |
|
java.lang.Object |
setMetaProperty(java.lang.String key, java.lang.Object value) Set (add / overwrite) a Meta Property associated to this axis. |
|
protected void |
setName(java.lang.String name) |
|
protected void |
setType(AxisType newType) |
|
protected void |
setValueType(AxisValueType newValueType) |
|
int |
size()
|
|
java.lang.Comparable |
standardizeColumnValue(java.lang.Comparable value) This method takes the input value (could be Number, String, Range, etc.) |
|
java.lang.String |
toString() |
|
void |
updateColumn(long colId, java.lang.Comparable value, java.lang.String name = null, int order = -1i) Update (change) the value of an existing column. |
|
java.util.Set<java.lang.Long> |
updateColumns(java.util.Collection<Column> newCols, boolean allowPositiveColumnIds = false) Update (merge) columns on this Axis from the passed in Collection. |
|
protected java.lang.Object |
updateMetaProperties(java.util.Map<java.lang.String, java.lang.Object> newMetaProperties, java.lang.String cubeName, groovy.lang.Closure dropOrphans) |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Use this constructor for non-rule Axes.
name
- String Axis nametype
- AxisType (DISCRETE, RANGE, SET, NEAREST, RULE)valueType
- AxisValueType (STRING, LONG, BIG_DECIMAL, DOUBLE, DATE, EXPRESSION, COMPARABLE)hasDefault
- boolean set to true to have a Default column that will match when no other columns matchorder
- SORTED or DISPLAY (insertion order)id
- long id of Axis. Ask n-cube for max ID, then add 1 to it, and use that.fireAll
- boolean if set to true, all conditions that evaluate to true will have their associated
statements executed. If set to false, the first condition that evaluates to true will be executed, but
then no conditions on the RULE axis will be evaluated.Use this constructor to create a 'reference' axis. This allows a single MASTER DATA axis to be referenced by many other axes without repeating the columnar data.
name
- String Axis nameid
- long id of Axis. Ask n-cube for max ID, then add 1 to it, and use that.axisRefProvider
- implementer is expected to load(this), e.g. load this axis completely, setting
all fields, etc.Add a new Column to this axis. It will be added at the end in terms of display order. If the axis is SORTED, it will be returned in sorted order if getColumns() or getColumnsWithoutDefault() are called.
value
- Comparable value to add to this Axis.colName
- The name of the column (useful for Rule axes. Any column can be given a name). Optional.suggestedId
- Long use the suggested ID if possible. This allows an axis to be recreated
from persistent storage and have the same IDs. Optional.Add a Column from another Axis to this Axis. It will attempt to use the ID that is already on the Column, ignoring the Axis portion of the ID. If there is a conflict, it will then use an ID deterministically generated from the value of the column.
column
- Column to addAdd a Map of meta properties all at once.
props
- Map of meta properties to add
Break the reference to the other axis. After calling this method, this axis will be a copy of the axis to which it had pointed.
Remove all meta properties associated to this Axis.
value
- to test against this AxisGiven the passed in 'raw' value, get a Column from the passed in value, which entails converting the 'raw' value to the correct type, promoting the value to the appropriate internal value for comparison, and so on.
value
- Comparable typically a primitive, but can also be an n-cube Range, RangeSet, CommandCell,
or 2D, 3D, or LatLon.suggestedId
- Long suggested column ID. Can be null or 0, in which case an ID will be generated. If not,
then the ID will be used (only the column portion, not the Axis ID portion). If that matches an existing ID
on the Axis, then an ID will be generated.This method deletes a column from an Axis. It is intentionally package scoped because there are two parts to deleting a column - this removes the column from the Axis, the other part removes the Cells that reference the column (that is within NCube).
value
- Comparable value used to identify the column to delete.Locate the column (value) along an axis.
value
- Comparable - A value that can be checked against the axisLocate a column on an axis using the 'name' meta property. If the value passed in matches no names, then null will be returned. Note: This is a case-insensitive match.
colName
- String name of column to locateFind all rule Columns which have meta-properties that match all of the passed in required meta-properties. In order for a Column to be selected, all keys in the requiredProps Map must match (case-insensitively) keys in the meta-properties map of the Column, and the values must match each other. If a value is the special value Axis.DONT_CARE, then only the key must be present, no comparison is performed on the value.
requiredProps
- Map of String key / value pair criteria Pass the Axis (this) to the passed in Closure. The closure is expected to take one argument, this
Axis, and return a List
Example:
axis.findColumns { Axis axis -> List columns = []; ... ; return columns }
Closure
- that takes a single Axis argument and returns a List of Column instances.@return
- A List
Find all Columns which have a name (meta-property name) in the passed in Collection. The Columns are returned based on the order in the passed in Collection. A Column could be returned more than once.
orchestration
- Collection of String names used to select Columns.
Use Column id to retrieve column (hash map lookup), O(1)
Return a display-friendly String for the passed in column.
Fetch the value associated to the passed in Key from the MetaProperties (if any exist). If none exist, null is returned.
This method is only for testing purposes
Fetch Columns on a rule axis where the passed in name is the first rule desired. All columns until the ends will also be selected.
ruleName
- String name of rule to locate.
Get a Comparable value that can be used to locate a Column on this axis. The passed in column may be from another Axis (as in merging an axis from another cube). This API will return the name or ID if this Axis is a RULE axis, otherwise it will return getValueThatMatches() API.
column
- Column source
Find the Column on 'this' axis which has the same ID as the passed in axis. If not found, then check for Column with the same value (or name in case of RULE axis).
Convert passed in value to a similar value of the highest type. If the valueType is not the same basic type as the value passed in, intelligent conversions will happen, and the result will be of the requested type. An intelligent conversion example - String to date, it will parse the String attempting to convert it to a date. Or a String to a long, it will try to parse the String as a long. Long to String, it will .toString() the long, and so on.
Re-index the axis (optionally assign new ID to the axis).
newId
- long optional new axis idRemove a meta-property entry
Remove transform from reference axis.
Set the ordering for the axis.
order
- int SORTED (0) or DISPLAY (1).Set the 'fire-all' mode - true to have all conditions that evaluate to true have the associated cell execute, false for only the first condition that is true to have it's associated cell execute.
Set long id of this Axis
Set (add / overwrite) a Meta Property associated to this axis.
key
- String key name of meta propertyvalue
- Object value to associate to key
This method takes the input value (could be Number, String, Range, etc.) and 'promotes' it to the same type as the Axis.
value
- Comparable value to promote (to highest of it's type [e.g., short to long])Update (change) the value of an existing column. This entails not only changing the value, but resorting the axis's columns (columns are always in sorted order for quick retrieval). The display order of the columns is not rebuilt, because the column is changed in-place (e.g., changing Mon to Monday does not change it's display order.)
colId
- long Column ID to updatevalue
- 'raw' value to set into the new column (will be up-promoted).order
- int (optional) new display order for columnUpdate (merge) columns on this Axis from the passed in Collection. Columns that exist on both axes, will have their values updated. Columns that exist on this axis, but not exist in the 'newCols' will be deleted (and returned as a Set of deleted Columns). Columns that exist in newCols but not on this are new columns. NOTE: The columns field within the newCols axis are NOT in sorted order as they normally are within the Axis class. Instead, they are in display order (this order is typically set forth by a UI).