mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
provide LCC variants of built in delegate interfaces
This commit is contained in:
parent
65d533f5a6
commit
3930e1a05d
30
CS2JLibrary/src/CS2JNet/System/LCC/Action.java
Normal file
30
CS2JLibrary/src/CS2JNet/System/LCC/Action.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2007,2008,2009,2010 Rustici Software, LLC
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
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.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
package CS2JNet.System.LCC;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Action<T> {
|
||||
void invoke(T obj) throws Exception ;
|
||||
|
||||
List<Action<T>> getInvocationList() throws Exception ;
|
||||
|
||||
}
|
30
CS2JLibrary/src/CS2JNet/System/LCC/EventHandler.java
Normal file
30
CS2JLibrary/src/CS2JNet/System/LCC/EventHandler.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2007,2008,2009,2010 Rustici Software, LLC
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
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.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
package CS2JNet.System.LCC;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EventHandler<TEventArgs> {
|
||||
void invoke(Object sender, TEventArgs value) throws Exception ;
|
||||
|
||||
List<EventHandler<TEventArgs>> getInvocationList() throws Exception ;
|
||||
|
||||
}
|
30
CS2JLibrary/src/CS2JNet/System/LCC/Predicate.java
Normal file
30
CS2JLibrary/src/CS2JNet/System/LCC/Predicate.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2007,2008,2009,2010 Rustici Software, LLC
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
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.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
package CS2JNet.System.LCC;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Predicate<T> {
|
||||
boolean invoke(T obj) throws Exception ;
|
||||
|
||||
List<Predicate<T>> getInvocationList() throws Exception ;
|
||||
|
||||
}
|
84
CS2JLibrary/src/CS2JNet/System/LCC/__MultiAction.java
Normal file
84
CS2JLibrary/src/CS2JNet/System/LCC/__MultiAction.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
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.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
|
||||
package CS2JNet.System.LCC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import CS2JNet.JavaSupport.util.ListSupport;
|
||||
|
||||
/**
|
||||
* @author keving
|
||||
*
|
||||
*/
|
||||
public class __MultiAction<T> implements Action<T> {
|
||||
|
||||
public void invoke(T obj) throws Exception {
|
||||
List<Action<T>> copy, members = this.getInvocationList();
|
||||
synchronized (members)
|
||||
{
|
||||
copy = new LinkedList<Action<T>>(members);
|
||||
}
|
||||
for (Action<T> d : copy)
|
||||
{
|
||||
d.invoke(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Action<T>> _invocationList = new ArrayList<Action<T>>();
|
||||
public static <T>Action<T> combine(Action<T> a, Action<T> b) throws Exception {
|
||||
if (a == null)
|
||||
return b;
|
||||
|
||||
if (b == null)
|
||||
return a;
|
||||
|
||||
__MultiAction<T> ret = new __MultiAction<T>();
|
||||
ret._invocationList = a.getInvocationList();
|
||||
ret._invocationList.addAll(b.getInvocationList());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static <T>Action<T> remove(Action<T> a, Action<T> b) throws Exception {
|
||||
if (a == null || b == null)
|
||||
return a;
|
||||
|
||||
List<Action<T>> aInvList = a.getInvocationList();
|
||||
List<Action<T>> newInvList = ListSupport.removeFinalStretch(aInvList, b.getInvocationList());
|
||||
if (aInvList == newInvList)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
__MultiAction<T> ret = new __MultiAction<T>();
|
||||
ret._invocationList = newInvList;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Action<T>> getInvocationList() throws Exception {
|
||||
return _invocationList;
|
||||
}
|
||||
|
||||
|
||||
}
|
84
CS2JLibrary/src/CS2JNet/System/LCC/__MultiEventHandler.java
Normal file
84
CS2JLibrary/src/CS2JNet/System/LCC/__MultiEventHandler.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
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.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
|
||||
package CS2JNet.System.LCC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import CS2JNet.JavaSupport.util.ListSupport;
|
||||
|
||||
/**
|
||||
* @author keving
|
||||
*
|
||||
*/
|
||||
public class __MultiEventHandler<TEventArgs> implements EventHandler<TEventArgs> {
|
||||
|
||||
public void invoke(Object other, TEventArgs e) throws Exception {
|
||||
List<EventHandler<TEventArgs>> copy, members = this.getInvocationList();
|
||||
synchronized (members)
|
||||
{
|
||||
copy = new LinkedList<EventHandler<TEventArgs>>(members);
|
||||
}
|
||||
for (EventHandler<TEventArgs> d : copy)
|
||||
{
|
||||
d.invoke(other, e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<EventHandler<TEventArgs>> _invocationList = new ArrayList<EventHandler<TEventArgs>>();
|
||||
public static <TEventArgs>EventHandler<TEventArgs> combine(EventHandler<TEventArgs> a, EventHandler<TEventArgs> b) throws Exception {
|
||||
if (a == null)
|
||||
return b;
|
||||
|
||||
if (b == null)
|
||||
return a;
|
||||
|
||||
__MultiEventHandler<TEventArgs> ret = new __MultiEventHandler<TEventArgs>();
|
||||
ret._invocationList = a.getInvocationList();
|
||||
ret._invocationList.addAll(b.getInvocationList());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static <TEventArgs>EventHandler<TEventArgs> remove(EventHandler<TEventArgs> a, EventHandler<TEventArgs> b) throws Exception {
|
||||
if (a == null || b == null)
|
||||
return a;
|
||||
|
||||
List<EventHandler<TEventArgs>> aInvList = a.getInvocationList();
|
||||
List<EventHandler<TEventArgs>> newInvList = ListSupport.removeFinalStretch(aInvList, b.getInvocationList());
|
||||
if (aInvList == newInvList)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
__MultiEventHandler<TEventArgs> ret = new __MultiEventHandler<TEventArgs>();
|
||||
ret._invocationList = newInvList;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public List<EventHandler<TEventArgs>> getInvocationList() throws Exception {
|
||||
return _invocationList;
|
||||
}
|
||||
|
||||
|
||||
}
|
86
CS2JLibrary/src/CS2JNet/System/LCC/__MultiPredicate.java
Normal file
86
CS2JLibrary/src/CS2JNet/System/LCC/__MultiPredicate.java
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
|
||||
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.
|
||||
|
||||
Author(s):
|
||||
|
||||
Kevin Glynn (kevin.glynn@twigletsoftware.com)
|
||||
*/
|
||||
|
||||
package CS2JNet.System.LCC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import CS2JNet.JavaSupport.util.ListSupport;
|
||||
|
||||
/**
|
||||
* @author keving
|
||||
*
|
||||
*/
|
||||
public class __MultiPredicate<T> implements Predicate<T> {
|
||||
|
||||
public boolean invoke(T obj) throws Exception {
|
||||
List<Predicate<T>> copy, members = this.getInvocationList();
|
||||
synchronized (members)
|
||||
{
|
||||
copy = new LinkedList<Predicate<T>>(members);
|
||||
}
|
||||
boolean ret = false;
|
||||
for (Predicate<T> d : copy)
|
||||
{
|
||||
ret = d.invoke(obj);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<Predicate<T>> _invocationList = new ArrayList<Predicate<T>>();
|
||||
public static <T>Predicate<T> combine(Predicate<T> a, Predicate<T> b) throws Exception {
|
||||
if (a == null)
|
||||
return b;
|
||||
|
||||
if (b == null)
|
||||
return a;
|
||||
|
||||
__MultiPredicate<T> ret = new __MultiPredicate<T>();
|
||||
ret._invocationList = a.getInvocationList();
|
||||
ret._invocationList.addAll(b.getInvocationList());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static <T>Predicate<T> remove(Predicate<T> a, Predicate<T> b) throws Exception {
|
||||
if (a == null || b == null)
|
||||
return a;
|
||||
|
||||
List<Predicate<T>> aInvList = a.getInvocationList();
|
||||
List<Predicate<T>> newInvList = ListSupport.removeFinalStretch(aInvList, b.getInvocationList());
|
||||
if (aInvList == newInvList)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
__MultiPredicate<T> ret = new __MultiPredicate<T>();
|
||||
ret._invocationList = newInvList;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Predicate<T>> getInvocationList() throws Exception {
|
||||
return _invocationList;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user