001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2010-2013 Pentaho and others 008// All Rights Reserved. 009*/ 010package mondrian.rolap.agg; 011 012import mondrian.util.Pair; 013 014import java.util.*; 015 016/** 017 * Implementation of a segment body which stores the data inside 018 * a dense primitive array of double precision numbers. 019 * 020 * @author LBoudreau 021 */ 022class DenseDoubleSegmentBody extends AbstractSegmentBody { 023 private static final long serialVersionUID = 5775717165497921144L; 024 025 private final double[] values; 026 private final BitSet nullValues; 027 028 /** 029 * Creates a DenseDoubleSegmentBody. 030 * 031 * <p>Stores the given array of cell values and null indicators; caller must 032 * not modify them afterwards.</p> 033 * 034 * @param nullValues A bit-set indicating whether values are null. Each 035 * position in the bit-set corresponds to an offset in the 036 * value array. If position is null, the corresponding 037 * entry in the value array will also be 0. 038 * @param values Cell values 039 * @param axes Axes 040 */ 041 DenseDoubleSegmentBody( 042 BitSet nullValues, 043 double[] values, 044 List<Pair<SortedSet<Comparable>, Boolean>> axes) 045 { 046 super(axes); 047 this.values = values; 048 this.nullValues = nullValues; 049 } 050 051 @Override 052 public Object getValueArray() { 053 return values; 054 } 055 056 @Override 057 public BitSet getNullValueIndicators() { 058 return nullValues; 059 } 060 061 @Override 062 protected int getSize() { 063 return values.length; // - nullValues.cardinality(); 064 } 065 066 @Override 067 protected Object getObject(int i) { 068 double value = values[i]; 069 if (value == 0d && nullValues.get(i)) { 070 return null; 071 } 072 return value; 073 } 074 075 @Override 076 public String toString() { 077 StringBuilder sb = new StringBuilder(); 078 sb.append("DenseDoubleSegmentBody(size="); 079 sb.append(values.length); 080 sb.append(", data="); 081 sb.append(Arrays.toString(values)); 082 sb.append(", notNullZeroValues=").append(nullValues); 083 sb.append(", axisValueSets="); 084 sb.append(Arrays.toString(getAxisValueSets())); 085 sb.append(", nullAxisFlags="); 086 sb.append(Arrays.toString(getNullAxisFlags())); 087 if (getAxisValueSets().length > 0) { 088 if (getAxisValueSets()[0].iterator().hasNext()) { 089 sb.append(", aVS[0]="); 090 sb.append(getAxisValueSets()[0].getClass()); 091 sb.append(", aVS[0][0]="); 092 sb.append(getAxisValueSets()[0].iterator().next().getClass()); 093 } 094 } 095 sb.append(")"); 096 return sb.toString(); 097 } 098} 099 100// End DenseDoubleSegmentBody.java