All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.mdl.util.TransStringSet1 Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

// @(#) $Id: TransStringSet1.java 2089 2007-11-28 13:56:13Z s3460 $
package at.spardat.xma.mdl.util;

import java.io.IOException;

import at.spardat.xma.mdl.MemoryEstimator;
import at.spardat.xma.serializer.XmaInput;
import at.spardat.xma.serializer.XmaOutput;

/**
 * A transactional string set that may contain at most one String.
 * 
 * @author YSD, 10.04.2003 10:23:45
 */
public class TransStringSet1 extends TransStringSet {

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#commit()
     */
    public void commit () {
        value_.commit();
    }

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#rollback()
     */
    public void rollback () {
        value_.rollback();
    }

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#changed()
     */
    public boolean changed () {
        return value_.changed();
    }

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#add(java.lang.String)
     */
    public boolean add (String key) {
        if (key == null) throw new IllegalArgumentException();
        if (key.equals(value_.get())) return false;
        value_.set(key);
        return true;
    }

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#remove(java.lang.String)
     */
    public boolean remove (String key) {
        if (key == null) throw new IllegalArgumentException();
        if (key.equals(value_.get())) {
            value_.set (null); return true;
        } else {
            return false;
        }
    }

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#clear()
     */
    public void clear () {
        value_.set(null);
    }

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#size()
     */
    public int size () {
        return value_.get()==null?0:1;
    }

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#getSome()
     */
    public String getSome () {
        return value_.get();
    }

    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#getAll()
     */
    public String[] getAll () {
        String selected = value_.get();
        String [] toReturn = new String[selected==null?0:1];
        if (selected != null) toReturn[0] = selected;
        return toReturn;
    }
    
    /**
     * @see at.spardat.xma.mdl.util.TransStringSet#contains(java.lang.String)
     */
    public boolean contains (String key) {
        if (key == null) return false;
        return key.equals(value_.get());
    }
    
    /**
     * @see at.spardat.xma.mdl.Synchronization#externalize(at.spardat.xma.serializer.XmaOutput, boolean)
     */
    public void externalize (XmaOutput xo, boolean forceFull) throws IOException {
        value_.externalize(xo, forceFull);
    }

    /**
     * @see at.spardat.xma.mdl.Synchronization#internalize(at.spardat.xma.serializer.XmaInput)
     */
    public void internalize (XmaInput in) throws IOException, ClassNotFoundException {
        value_.internalize(in);
    }
    
    /**
     * Produces a single row of information.
     * @see at.spardat.xma.mdl.util.Descriptive#describe(at.spardat.xma.mdl.util.DNode)
     */
    public void describe (DNode node) {
        value_.describe(node);
    }
    
    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof TransStringSet1)) return false;
        return value_.equals(((TransStringSet1)obj).value_);
    }
    
    /**
     * Estimates the number of bytes this object consumes in memory.
     */
    public int estimateMemory () {
        return MemoryEstimator.sizeOfObject(1) + value_.estimateMemory();
    }
    

    
    
    // holds the selection
    private TransString         value_ = new TransString();


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy