Skip to content
Snippets Groups Projects
Commit 446613f2 authored by ribeaudc's avatar ribeaudc
Browse files

add: - 'CompoundTerminable' and 'CompoundTriggerable'.

remove: - 'TimerHelper'.

SVN: 6771
parent 2801c498
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.utilities;
/**
* A <code>ITerminable</code> implementation which could accept several {@link ITerminable}.
*
* @author Christian Ribeaud
*/
public final class CompoundTerminable implements ITerminable
{
private final ITerminable[] terminables;
public CompoundTerminable(final ITerminable... terminables)
{
assert terminables != null : "Unspecified set of ITerminable";
this.terminables = terminables;
}
//
// ITerminable
//
public final boolean terminate()
{
boolean ok = true;
for (final ITerminable terminable : terminables)
{
ok = ok && terminable.terminate();
}
return ok;
}
}
/*
* Copyright 2007 ETH Zuerich, CISD
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,29 +16,31 @@
package ch.systemsx.cisd.common.utilities;
import java.util.Timer;
/**
* Helper methods for timer operations.
* A <code>ITriggerable</code> that chains a sequence of one or more {@link ITriggerable}s.
*
* @author Bernd Rinn
* @author Christian Ribeaud
*/
public class TimerHelper
public final class CompoundTriggerable implements ITriggerable
{
private final ITriggerable[] triggerables;
public CompoundTriggerable(final ITriggerable... triggerables)
{
assert triggerables != null : "Unspecified ITriggerable implementations.";
this.triggerables = triggerables;
}
//
// ITriggerable
//
/**
* Returns an {@link ITerminable} for the <var>timer</var>.
*/
public static ITerminable asTerminable(final Timer timer)
public final void trigger()
{
return new ITerminable()
{
public boolean terminate()
{
timer.cancel();
return true;
}
};
for (final ITriggerable triggerable : triggerables)
{
triggerable.trigger();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment