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