001/*- 002 ******************************************************************************* 003 * Copyright (c) 2011, 2016 Diamond Light Source Ltd. 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Peter Chang - initial API and implementation and/or initial documentation 011 *******************************************************************************/ 012 013package org.eclipse.january.dataset; 014 015import java.text.MessageFormat; 016 017/** 018 * Extend dataset for objects 019 */ 020public class ObjectDataset extends ObjectDatasetBase { 021 // pin UID to base class 022 private static final long serialVersionUID = Dataset.serialVersionUID; 023 024 /** 025 * Create a null dataset 026 */ 027 ObjectDataset() { 028 super(); 029 } 030 031 /** 032 * Create a null-filled dataset of given shape 033 * @param shape 034 */ 035 ObjectDataset(final int... shape) { 036 super(shape); 037 } 038 039 /** 040 * Create a dataset using given data 041 * @param data 042 * @param shape (can be null to create 1D dataset) 043 */ 044 ObjectDataset(final Object[] data, int... shape) { 045 super(data, shape); 046 } 047 048 /** 049 * Copy a dataset 050 * @param dataset 051 */ 052 ObjectDataset(final ObjectDataset dataset) { 053 super(dataset); 054 } 055 056 /** 057 * Cast a dataset to this class type 058 * @param dataset 059 */ 060 ObjectDataset(final Dataset dataset) { 061 super(dataset); 062 } 063 064 @Override 065 public ObjectDataset getView(boolean deepCopyMetadata) { 066 ObjectDataset view = new ObjectDataset(); 067 copyToView(this, view, true, deepCopyMetadata); 068 view.setData(); 069 return view; 070 } 071 072 @Override 073 public ObjectDataset clone() { 074 return new ObjectDataset(this); 075 } 076 077 @Override 078 public ObjectDataset getSlice(SliceIterator siter) { 079 ObjectDatasetBase base = super.getSlice(siter); 080 081 ObjectDataset slice = new ObjectDataset(); 082 copyToView(base, slice, false, false); 083 slice.setData(); 084 return slice; 085 } 086 087 /** 088 * Create a dataset from an object which could be a Java list, array (of arrays...) 089 * or Number. Ragged sequences or arrays are padded with zeros. 090 * 091 * @param obj 092 * @return dataset with contents given by input 093 */ 094 static ObjectDataset createFromObject(final Object obj) { 095 if (obj == null) { // special case 096 ObjectDataset ds = new ObjectDataset(new Object[] {null}); 097 ds.setShape(); 098 return ds; 099 } 100 101 ObjectDatasetBase result = ObjectDatasetBase.createFromObject(obj); 102 ObjectDataset ds = new ObjectDataset(result.data, result.shape); 103 if (result.shape.length == 0) { 104 ds.setShape(result.shape); // special case of single item 105 } 106 return ds; 107 } 108 109 /** 110 * @param shape 111 * @return a dataset filled with ones 112 */ 113 static ObjectDataset ones(final int... shape) { 114 throw new UnsupportedOperationException("Unsupported method for class"); 115 } 116 117 @Override 118 public boolean getElementBooleanAbs(int index) { 119 throw new UnsupportedOperationException("Unsupported method for class"); 120 } 121 122 @Override 123 public double getElementDoubleAbs(int index) { 124 throw new UnsupportedOperationException("Unsupported method for class"); 125 } 126 127 @Override 128 public long getElementLongAbs(int index) { 129 throw new UnsupportedOperationException("Unsupported method for class"); 130 } 131 132 @Override 133 public double getDouble() { 134 throw new UnsupportedOperationException("Unsupported method for class"); 135 } 136 137 @Override 138 public double getDouble(int i) { 139 throw new UnsupportedOperationException("Unsupported method for class"); 140 } 141 142 @Override 143 public double getDouble(int i, int j) { 144 throw new UnsupportedOperationException("Unsupported method for class"); 145 } 146 147 @Override 148 public double getDouble(int... pos) { 149 throw new UnsupportedOperationException("Unsupported method for class"); 150 } 151 152 @Override 153 public float getFloat() { 154 throw new UnsupportedOperationException("Unsupported method for class"); 155 } 156 157 @Override 158 public float getFloat(int i) { 159 throw new UnsupportedOperationException("Unsupported method for class"); 160 } 161 162 @Override 163 public float getFloat(int i, int j) { 164 throw new UnsupportedOperationException("Unsupported method for class"); 165 } 166 167 @Override 168 public float getFloat(int... pos) { 169 throw new UnsupportedOperationException("Unsupported method for class"); 170 } 171 172 @Override 173 public long getLong() { 174 throw new UnsupportedOperationException("Unsupported method for class"); 175 } 176 177 @Override 178 public long getLong(int i) { 179 throw new UnsupportedOperationException("Unsupported method for class"); 180 } 181 182 @Override 183 public long getLong(int i, int j) { 184 throw new UnsupportedOperationException("Unsupported method for class"); 185 } 186 187 @Override 188 public long getLong(int... pos) { 189 throw new UnsupportedOperationException("Unsupported method for class"); 190 } 191 192 @Override 193 public int getInt() { 194 throw new UnsupportedOperationException("Unsupported method for class"); 195 } 196 197 @Override 198 public int getInt(int i) { 199 throw new UnsupportedOperationException("Unsupported method for class"); 200 } 201 202 @Override 203 public int getInt(int i, int j) { 204 throw new UnsupportedOperationException("Unsupported method for class"); 205 } 206 207 @Override 208 public int getInt(int... pos) { 209 throw new UnsupportedOperationException("Unsupported method for class"); 210 } 211 212 @Override 213 public short getShort() { 214 throw new UnsupportedOperationException("Unsupported method for class"); 215 } 216 217 @Override 218 public short getShort(int i) { 219 throw new UnsupportedOperationException("Unsupported method for class"); 220 } 221 222 @Override 223 public short getShort(int i, int j) { 224 throw new UnsupportedOperationException("Unsupported method for class"); 225 } 226 227 @Override 228 public short getShort(int... pos) { 229 throw new UnsupportedOperationException("Unsupported method for class"); 230 } 231 232 @Override 233 public byte getByte() { 234 throw new UnsupportedOperationException("Unsupported method for class"); 235 } 236 237 @Override 238 public byte getByte(int i) { 239 throw new UnsupportedOperationException("Unsupported method for class"); 240 } 241 242 @Override 243 public byte getByte(int i, int j) { 244 throw new UnsupportedOperationException("Unsupported method for class"); 245 } 246 247 @Override 248 public byte getByte(int... pos) { 249 throw new UnsupportedOperationException("Unsupported method for class"); 250 } 251 252 @Override 253 public boolean getBoolean() { 254 throw new UnsupportedOperationException("Unsupported method for class"); 255 } 256 257 @Override 258 public boolean getBoolean(int i) { 259 throw new UnsupportedOperationException("Unsupported method for class"); 260 } 261 262 @Override 263 public boolean getBoolean(int i, int j) { 264 throw new UnsupportedOperationException("Unsupported method for class"); 265 } 266 267 @Override 268 public boolean getBoolean(int... pos) { 269 throw new UnsupportedOperationException("Unsupported method for class"); 270 } 271 272 @Override 273 public String getStringAbs(final int index) { 274 return stringFormat instanceof MessageFormat ? stringFormat.format(data[index]) : 275 String.format("%s", data[index]); 276 } 277 278 @Override 279 public int[] minPos(boolean... ignoreInvalids) { 280 throw new UnsupportedOperationException("Unsupported method for class"); 281 } 282 283 @Override 284 public int[] maxPos(boolean... ignoreInvalids) { 285 throw new UnsupportedOperationException("Unsupported method for class"); 286 } 287 288 @Override 289 public boolean containsInfs() { 290 return false; 291 } 292 293 @Override 294 public boolean containsNans() { 295 return false; 296 } 297 298 @Override 299 public ObjectDataset iadd(Object o) { 300 throw new UnsupportedOperationException("Unsupported method for class"); 301 } 302 303 @Override 304 public ObjectDataset isubtract(Object o) { 305 throw new UnsupportedOperationException("Unsupported method for class"); 306 } 307 308 @Override 309 public ObjectDataset imultiply(Object o) { 310 throw new UnsupportedOperationException("Unsupported method for class"); 311 } 312 313 @Override 314 public ObjectDataset idivide(Object o) { 315 throw new UnsupportedOperationException("Unsupported method for class"); 316 } 317 318 @Override 319 public ObjectDataset iremainder(Object o) { 320 throw new UnsupportedOperationException("Unsupported method for class"); 321 } 322 323 @Override 324 public ObjectDataset ifloor() { 325 throw new UnsupportedOperationException("Unsupported method for class"); 326 } 327 328 @Override 329 public ObjectDataset ipower(Object o) { 330 throw new UnsupportedOperationException("Unsupported method for class"); 331 } 332 333 @Override 334 public double residual(Object o) { 335 throw new UnsupportedOperationException("Unsupported method for class"); 336 } 337}