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

javolution.util.internal.set.SharedSetImpl Maven / Gradle / Ivy

Go to download

Only the Java Core part of Javolution library, with slight modifications for use in MSFTBX.

There is a newer version: 6.11.8
Show newest version
/*
 * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
 * Copyright (C) 2012 - Javolution (http://javolution.org/)
 * All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software is
 * freely granted, provided that this notice is preserved.
 */
package javolution.util.internal.set;

import javolution.util.internal.ReadWriteLockImpl;
import javolution.util.internal.collection.SharedCollectionImpl;
import javolution.util.service.SetService;

/**
 * A shared view over a set allowing concurrent access and sequential updates.
 */
public class SharedSetImpl extends SharedCollectionImpl implements
        SetService {

    private static final long serialVersionUID = 0x600L; // Version.

    public SharedSetImpl(SetService target) {
        super(target);
    }

    public SharedSetImpl(SetService target, ReadWriteLockImpl lock) {
        super(target, lock);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public SetService[] split(int n, boolean updateable) {
        SetService[] tmp;
        lock.readLock.lock();
        try {
            tmp = target().split(n, updateable); 
        } finally {
            lock.readLock.unlock();
        }
        SetService[] result = new SetService[tmp.length];
        for (int i = 0; i < tmp.length; i++) {
            result[i] = new SharedSetImpl(tmp[i], lock); // Shares the same locks.
        }
        return result;
    }
    
    @Override
    protected SetService target() {
        return (SetService) super.target();
    }    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy