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