javolution.util.internal.set.SharedSetImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javolution-core-java-msftbx Show documentation
Show all versions of javolution-core-java-msftbx Show documentation
Only the Java Core part of Javolution library, with slight modifications for use in MSFTBX.
/*
* 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();
}
}