1
//////////////////////////////////////////////////////////////////////
3
// JCSP ("CSP for Java") Libraries //
4
// Copyright (C) 1996-2008 Peter Welch and Paul Austin. //
5
// 2001-2004 Quickstone Technologies Limited. //
7
// This library is free software; you can redistribute it and/or //
8
// modify it under the terms of the GNU Lesser General Public //
9
// License as published by the Free Software Foundation; either //
10
// version 2.1 of the License, or (at your option) any later //
13
// This library is distributed in the hope that it will be //
14
// useful, but WITHOUT ANY WARRANTY; without even the implied //
15
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
16
// PURPOSE. See the GNU Lesser General Public License for more //
19
// You should have received a copy of the GNU Lesser General //
20
// Public License along with this library; if not, write to the //
21
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, //
22
// Boston, MA 02111-1307, USA. //
24
// Author contact: P.H.Welch@kent.ac.uk //
27
//////////////////////////////////////////////////////////////////////
29
package org.jcsp.lang;
31
import org.jcsp.util.ints.ChannelDataStoreInt;
34
* This class provides static factory methods for constructing
35
* various different types of int channel objects. There are also methods
36
* for constructing arrays of identical int channels.
38
* The current implementation constructs "safe" channels which have separate
39
* delegate objects for their read and write ends. This stops a
40
* <code>ChannelInputInt</code> from being cast into a <code>ChannelOutputInt</code>
41
* object. The <code>SafeChannelIntFactory</code> class is used to construct the
44
* Non-safe channels can be constructed by using an instance of the
45
* <code>StandardChannelIntFactory</code> class. The channels produced by this
46
* factory have read and write ends implemented by the same object. This is
47
* is more efficient (there are two extra objects and delegate method calls)
48
* but could lead to errors if users make incorrect casts.
50
* @deprecated To create integer channels, use the methods in the Channel class.
52
* @author Quickstone Technologies Limited
54
public class ChannelInt
57
* Private constructor to stop users from instantiating this class.
61
//this class should not be instantiated
65
* The factory to be used by this class. The class should implement
66
* ChannelIntFactory, ChannelIntArrayFactory, BufferedChannelIntFactory and BufferedChannelIntArrayFactory.
68
private static final StandardChannelIntFactory factory = new StandardChannelIntFactory();
71
/* Methods that are the same as the Factory Methods */
74
* Constructs and returns a <code>One2OneChannelInt</code> object.
76
* @return the channel object.
78
* @see org.jcsp.lang.ChannelIntFactory#createOne2One()
80
public static One2OneChannelInt createOne2One()
82
return factory.createOne2One();
86
* Constructs and returns an <code>Any2OneChannelInt</code> object.
88
* @return the channel object.
90
* @see org.jcsp.lang.ChannelIntFactory#createAny2One()
92
public static Any2OneChannelInt createAny2One()
94
return factory.createAny2One();
98
* Constructs and returns a <code>One2AnyChannelInt</code> object.
100
* @return the channel object.
102
* @see org.jcsp.lang.ChannelIntFactory#createOne2Any()
104
public static One2AnyChannelInt createOne2Any()
106
return factory.createOne2Any();
110
* Constructs and returns an <code>Any2AnyChannelInt</code> object.
112
* @return the channel object.
114
* @see org.jcsp.lang.ChannelIntFactory#createAny2Any()
116
public static Any2AnyChannelInt createAny2Any()
118
return factory.createAny2Any();
122
* Constructs and returns an array of <code>One2OneChannelInt</code>
125
* @param n the size of the array of channels.
126
* @return the array of channels.
128
* @see org.jcsp.lang.ChannelIntArrayFactory#createOne2One(int)
130
public static One2OneChannelInt[] createOne2One(int n)
132
return factory.createOne2One(n);
136
* Constructs and returns an array of <code>Any2OneChannelInt</code>
139
* @param n the size of the array of channels.
140
* @return the array of channels.
142
* @see org.jcsp.lang.ChannelIntArrayFactory#createAny2One(int)
144
public static Any2OneChannelInt[] any2oneArray(int n)
146
return factory.createAny2One(n);
150
* Constructs and returns an array of <code>One2AnyChannelInt</code>
153
* @param n the size of the array of channels.
154
* @return the array of channels.
156
* @see org.jcsp.lang.ChannelIntArrayFactory#createOne2Any(int)
158
public static One2AnyChannelInt[] createOne2Any(int n)
160
return factory.createOne2Any(n);
164
* Constructs and returns an array of <code>Any2AnyChannelInt</code>
167
* @param n the size of the array of channels.
168
* @return the array of channels.
170
* @see org.jcsp.lang.ChannelIntArrayFactory#createAny2Any(int)
172
public static Any2AnyChannelInt[] createAny2Any(int n)
174
return factory.createAny2Any(n);
178
* Constructs and returns a <code>One2OneChannelInt</code> object which
179
* uses the specified <code>ChannelDataStoreInt</code> object as a buffer.
181
* @param buffer the <code>ChannelDataStoreInt</code> to use.
182
* @return the buffered channel.
184
* @see org.jcsp.lang.BufferedChannelIntFactory#createOne2One(ChannelDataStoreInt)
185
* @see org.jcsp.util.ints.ChannelDataStoreInt
187
public static One2OneChannelInt createOne2One(ChannelDataStoreInt buffer)
189
return factory.createOne2One(buffer);
193
* Constructs and returns a <code>Any2OneChannelInt</code> object which
194
* uses the specified <code>ChannelDataStoreInt</code> object as a buffer.
196
* @param buffer the <code>ChannelDataStoreInt</code> to use.
197
* @return the buffered channel.
199
* @see org.jcsp.lang.BufferedChannelIntFactory#createAny2One(ChannelDataStoreInt)
200
* @see org.jcsp.util.ints.ChannelDataStoreInt
202
public static Any2OneChannelInt createAny2One(ChannelDataStoreInt buffer)
204
return factory.createAny2One(buffer);
208
* Constructs and returns a <code>One2AnyChannelInt</code> object which
209
* uses the specified <code>ChannelDataStoreInt</code> object as a buffer.
211
* @param buffer the <code>ChannelDataStoreInt</code> to use.
212
* @return the buffered channel.
214
* @see org.jcsp.lang.BufferedChannelIntFactory#createOne2Any(ChannelDataStoreInt)
215
* @see org.jcsp.util.ints.ChannelDataStoreInt
217
public static One2AnyChannelInt createOne2Any(ChannelDataStoreInt buffer)
219
return factory.createOne2Any(buffer);
223
* Constructs and returns a <code>Any2AnyChannelInt</code> object which
224
* uses the specified <code>ChannelDataStoreInt</code> object as a buffer.
226
* @param buffer the <code>ChannelDataStoreInt</code> to use.
227
* @return the buffered channel.
229
* @see org.jcsp.lang.BufferedChannelIntFactory#createAny2Any(ChannelDataStoreInt)
230
* @see org.jcsp.util.ints.ChannelDataStoreInt
232
public static Any2AnyChannelInt createAny2Any(ChannelDataStoreInt buffer)
234
return factory.createAny2Any(buffer);
238
* Constructs and returns an array of <code>One2OneChannelInt</code> objects
239
* which use the specified <code>ChannelDataStoreInt</code> object as a
242
* @param buffer the <code>ChannelDataStoreInt</code> to use.
243
* @param n the size of the array of channels.
244
* @return the array of buffered channels.
246
* @see org.jcsp.lang.BufferedChannelIntArrayFactory#createOne2One(ChannelDataStoreInt, int)
247
* @see org.jcsp.util.ints.ChannelDataStoreInt
249
public static One2OneChannelInt[] createOne2One(ChannelDataStoreInt buffer, int n)
251
return factory.createOne2One(buffer, n);
255
* Constructs and returns an array of <code>Any2OneChannelInt</code> objects
256
* which use the specified <code>ChannelDataStoreInt</code> object as a
259
* @param buffer the <code>ChannelDataStoreInt</code> to use.
260
* @param n the size of the array of channels.
261
* @return the array of buffered channels.
263
* @see org.jcsp.lang.BufferedChannelIntArrayFactory#createAny2One(ChannelDataStoreInt, int)
264
* @see org.jcsp.util.ints.ChannelDataStoreInt
266
public static Any2OneChannelInt[] any2oneArray(ChannelDataStoreInt buffer, int n)
268
return factory.createAny2One(buffer, n);
272
* Constructs and returns an array of <code>One2AnyChannelInt</code> objects
273
* which use the specified <code>ChannelDataStoreInt</code> object as a
276
* @param buffer the <code>ChannelDataStoreInt</code> to use.
277
* @param n the size of the array of channels.
278
* @return the array of buffered channels.
280
* @see org.jcsp.lang.BufferedChannelIntArrayFactory#createOne2Any(ChannelDataStoreInt, int)
281
* @see org.jcsp.util.ints.ChannelDataStoreInt
283
public static One2AnyChannelInt[] createOne2Any(ChannelDataStoreInt buffer, int n)
285
return factory.createOne2Any(buffer, n);
289
* Constructs and returns an array of <code>Any2AnyChannelInt</code> objects
290
* which use the specified <code>ChannelDataStoreInt</code> object as a
293
* @param buffer the <code>ChannelDataStoreInt</code> to use.
294
* @param n the size of the array of channels.
295
* @return the array of buffered channels.
297
* @see org.jcsp.lang.BufferedChannelIntArrayFactory#createAny2Any(ChannelDataStoreInt, int)
298
* @see org.jcsp.util.ints.ChannelDataStoreInt
300
public static Any2AnyChannelInt[] createAny2Any(ChannelDataStoreInt buffer, int n)
302
return factory.createAny2Any(buffer, n);
306
* Constructs and returns an array of input channel ends, each of which can be shared by multiple
307
* concurrent readers. The returned array, <code>r</code>, is constructed such that
308
* <code>r[i] = c[i].in ()</code> for <code>0 <= i < c.length</code>.
310
* @param c the array of channel to obtain input ends from.
311
* @return the array of channel input ends.
313
public static SharedChannelInputInt[] getInputArray(Any2AnyChannelInt[] c)
315
SharedChannelInputInt[] in = new SharedChannelInputInt[c.length];
316
for (int i = 0; i < c.length; i++)
322
* Constructs and returns an array of input channel ends, each of which can be used as guards
323
* in an <code>Alternative</code>. The returned array, <code>r</code>, is constructed such that
324
* <code>r[i] = c[i].in ()</code> for <code>0 <= i < c.length</code>.
326
* @param c the array of channel to obtain input ends from.
327
* @return the array of channel input ends.
329
public static AltingChannelInputInt[] getInputArray(Any2OneChannelInt[] c)
331
AltingChannelInputInt[] in = new AltingChannelInputInt[c.length];
332
for (int i = 0; i < c.length; i++)
338
* Constructs and returns an array of input channel ends, each of which can be shared by multiple
339
* concurrent readers. The returned array, <code>r</code>, is constructed such that
340
* <code>r[i] = c[i].in ()</code> for <code>0 <= i < c.length</code>.
342
* @param c the array of channel to obtain input ends from.
343
* @return the array of channel input ends.
345
public static SharedChannelInputInt[] getInputArray(One2AnyChannelInt[] c)
347
SharedChannelInputInt[] in = new SharedChannelInputInt[c.length];
348
for (int i = 0; i < c.length; i++)
354
* Constructs and returns an array of input channel ends, each of which can be used as guards
355
* in an <code>Alternative</code>. The returned array, <code>r</code>, is constructed such that
356
* <code>r[i] = c[i].in ()</code> for <code>0 <= i < c.length</code>.
358
* @param c the array of channel to obtain input ends from.
359
* @return the array of channel input ends.
361
public static AltingChannelInputInt[] getInputArray(One2OneChannelInt[] c)
363
AltingChannelInputInt[] in = new AltingChannelInputInt[c.length];
364
for (int i = 0; i < c.length; i++)
370
* Constructs and returns an array of output channel ends, each of which can be shared by multiple
371
* concurrent writers. The returned array, <code>r</code>, is constructed such that
372
* <code>r[i] = c[i].out ()</code> for <code>0 <= i < c.length</code>.
374
* @param c the array of channel to obtain output ends from.
375
* @return the array of output input ends.
377
public static SharedChannelOutputInt[] getOutputArray(Any2AnyChannelInt[] c)
379
SharedChannelOutputInt[] in = new SharedChannelOutputInt[c.length];
380
for (int i = 0; i < c.length; i++)
386
* Constructs and returns an array of output channel ends, each of which can be shared by multiple
387
* concurrent writers. The returned array, <code>r</code>, is constructed such that
388
* <code>r[i] = c[i].out ()</code> for <code>0 <= i < c.length</code>.
390
* @param c the array of channel to obtain output ends from.
391
* @return the array of output input ends.
393
public static SharedChannelOutputInt[] getOutputArray(Any2OneChannelInt[] c)
395
SharedChannelOutputInt[] in = new SharedChannelOutputInt[c.length];
396
for (int i = 0; i < c.length; i++)
402
* Constructs and returns an array of output channel ends, each of which can only be used by a
403
* single writer. The returned array, <code>r</code>, is constructed such that
404
* <code>r[i] = c[i].out ()</code> for <code>0 <= i < c.length</code>.
406
* @param c the array of channel to obtain output ends from.
407
* @return the array of output input ends.
409
public static ChannelOutputInt[] getOutputArray(One2AnyChannelInt[] c)
411
ChannelOutputInt[] in = new ChannelOutputInt[c.length];
412
for (int i = 0; i < c.length; i++)
418
* Constructs and returns an array of output channel ends, each of which can only be used by a
419
* single writer. The returned array, <code>r</code>, is constructed such that
420
* <code>r[i] = c[i].out ()</code> for <code>0 <= i < c.length</code>.
422
* @param c the array of channel to obtain output ends from.
423
* @return the array of output input ends.
425
public static ChannelOutputInt[] getOutputArray(One2OneChannelInt[] c)
427
ChannelOutputInt[] in = new ChannelOutputInt[c.length];
428
for (int i = 0; i < c.length; i++)