    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                ObjectDatasetBase result = ObjectDatasetBase.createFromObject(obj);
    096                ObjectDataset ds = new ObjectDataset(result.data, result.shape);
    097                if (result.shape.length == 0)
    098                        ds.setShape(result.shape); // special case of single item
    099                return ds;
    100        }
    101
    102        /**
    103         * @param shape
    104         * @return a dataset filled with ones
    105         */
    106        static ObjectDataset ones(final int... shape) {
    107                throw new UnsupportedOperationException("Unsupported method for class");
    108        }
    109
    110        @Override
    111        public boolean getElementBooleanAbs(int index) {
    112                throw new UnsupportedOperationException("Unsupported method for class");
    113        }
    114
    115        @Override
    116        public double getElementDoubleAbs(int index) {
    117                throw new UnsupportedOperationException("Unsupported method for class");
    118        }
    119
    120        @Override
    121        public long getElementLongAbs(int index) {
    122                throw new UnsupportedOperationException("Unsupported method for class");
    123        }
    124
    125        @Override
    126        public double getDouble() {
    127                throw new UnsupportedOperationException("Unsupported method for class");
    128        }
    129
    130        @Override
    131        public double getDouble(int i) {
    132                throw new UnsupportedOperationException("Unsupported method for class");
    133        }
    134
    135        @Override
    136        public double getDouble(int i, int j) {
    137                throw new UnsupportedOperationException("Unsupported method for class");
    138        }
    139
    140        @Override
    141        public double getDouble(int... pos) {
    142                throw new UnsupportedOperationException("Unsupported method for class");
    143        }
    144
    145        @Override
    146        public float getFloat() {
    147                throw new UnsupportedOperationException("Unsupported method for class");
    148        }
    149
    150        @Override
    151        public float getFloat(int i) {
    152                throw new UnsupportedOperationException("Unsupported method for class");
    153        }
    154
    155        @Override
    156        public float getFloat(int i, int j) {
    157                throw new UnsupportedOperationException("Unsupported method for class");
    158        }
    159
    160        @Override
    161        public float getFloat(int... pos) {
    162                throw new UnsupportedOperationException("Unsupported method for class");
    163        }
    164
    165        @Override
    166        public long getLong() {
    167                throw new UnsupportedOperationException("Unsupported method for class");
    168        }
    169
    170        @Override
    171        public long getLong(int i) {
    172                throw new UnsupportedOperationException("Unsupported method for class");
    173        }
    174
    175        @Override
    176        public long getLong(int i, int j) {
    177                throw new UnsupportedOperationException("Unsupported method for class");
    178        }
    179
    180        @Override
    181        public long getLong(int... pos) {
    182                throw new UnsupportedOperationException("Unsupported method for class");
    183        }
    184
    185        @Override
    186        public int getInt() {
    187                throw new UnsupportedOperationException("Unsupported method for class");
    188        }
    189
    190        @Override
    191        public int getInt(int i) {
    192                throw new UnsupportedOperationException("Unsupported method for class");
    193        }
    194
    195        @Override
    196        public int getInt(int i, int j) {
    197                throw new UnsupportedOperationException("Unsupported method for class");
    198        }
    199
    200        @Override
    201        public int getInt(int... pos) {
    202                throw new UnsupportedOperationException("Unsupported method for class");
    203        }
    204
    205        @Override
    206        public short getShort() {
    207                throw new UnsupportedOperationException("Unsupported method for class");
    208        }
    209
    210        @Override
    211        public short getShort(int i) {
    212                throw new UnsupportedOperationException("Unsupported method for class");
    213        }
    214
    215        @Override
    216        public short getShort(int i, int j) {
    217                throw new UnsupportedOperationException("Unsupported method for class");
    218        }
    219
    220        @Override
    221        public short getShort(int... pos) {
    222                throw new UnsupportedOperationException("Unsupported method for class");
    223        }
    224
    225        @Override
    226        public byte getByte() {
    227                throw new UnsupportedOperationException("Unsupported method for class");
    228        }
    229
    230        @Override
    231        public byte getByte(int i) {
    232                throw new UnsupportedOperationException("Unsupported method for class");
    233        }
    234
    235        @Override
    236        public byte getByte(int i, int j) {
    237                throw new UnsupportedOperationException("Unsupported method for class");
    238        }
    239
    240        @Override
    241        public byte getByte(int... pos) {
    242                throw new UnsupportedOperationException("Unsupported method for class");
    243        }
    244
    245        @Override
    246        public boolean getBoolean() {
    247                throw new UnsupportedOperationException("Unsupported method for class");
    248        }
    249
    250        @Override
    251        public boolean getBoolean(int i) {
    252                throw new UnsupportedOperationException("Unsupported method for class");
    253        }
    254
    255        @Override
    256        public boolean getBoolean(int i, int j) {
    257                throw new UnsupportedOperationException("Unsupported method for class");
    258        }
    259
    260        @Override
    261        public boolean getBoolean(int... pos) {
    262                throw new UnsupportedOperationException("Unsupported method for class");
    263        }
    264
    265        @Override
    266        public String getStringAbs(final int index) {
    267                return stringFormat instanceof MessageFormat ? stringFormat.format(data[index]) :
    268                                String.format("%s", data[index]);
    269        }
    270
    271        @Override
    272        public int[] minPos(boolean... ignoreInvalids) {
    273                throw new UnsupportedOperationException("Unsupported method for class");
    274        }
    275
    276        @Override
    277        public int[] maxPos(boolean... ignoreInvalids) {
    278                throw new UnsupportedOperationException("Unsupported method for class");
    279        }
    280
    281        @Override
    282        public boolean containsInfs() {
    283                return false;
    284        }
    285
    286        @Override
    287        public boolean containsNans() {
    288                return false;
    289        }
    290
    291        @Override
    292        public ObjectDataset iadd(Object o) {
    293                throw new UnsupportedOperationException("Unsupported method for class");
    294        }
    295
    296        @Override
    297        public ObjectDataset isubtract(Object o) {
    298                throw new UnsupportedOperationException("Unsupported method for class");
    299        }
    300
    301        @Override
    302        public ObjectDataset imultiply(Object o) {
    303                throw new UnsupportedOperationException("Unsupported method for class");
    304        }
    305
    306        @Override
    307        public ObjectDataset idivide(Object o) {
    308                throw new UnsupportedOperationException("Unsupported method for class");
    309        }
    310
    311        @Override
    312        public ObjectDataset iremainder(Object o) {
    313                throw new UnsupportedOperationException("Unsupported method for class");
    314        }
    315
    316        @Override
    317        public ObjectDataset ifloor() {
    318                throw new UnsupportedOperationException("Unsupported method for class");
    319        }
    320
    321        @Override
    322        public ObjectDataset ipower(Object o) {
    323                throw new UnsupportedOperationException("Unsupported method for class");
    324        }
    325
    326        @Override
    327        public double residual(Object o) {
    328                throw new UnsupportedOperationException("Unsupported method for class");
    329        }
    330}