~ubuntu-branches/ubuntu/precise/jcsp/precise

« back to all changes in this revision

Viewing changes to src/org/jcsp/plugNplay/Tail.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-06-20 18:12:26 UTC
  • Revision ID: james.westby@ubuntu.com-20100620181226-8yg8d9rjjjiuy7oz
Tags: upstream-1.1-rc4
ImportĀ upstreamĀ versionĀ 1.1-rc4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////
 
2
//                                                                  //
 
3
//  JCSP ("CSP for Java") Libraries                                 //
 
4
//  Copyright (C) 1996-2008 Peter Welch and Paul Austin.            //
 
5
//                2001-2004 Quickstone Technologies Limited.        //
 
6
//                                                                  //
 
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       //
 
11
//  version.                                                        //
 
12
//                                                                  //
 
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     //
 
17
//  details.                                                        //
 
18
//                                                                  //
 
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.                                     //
 
23
//                                                                  //
 
24
//  Author contact: P.H.Welch@kent.ac.uk                             //
 
25
//                                                                  //
 
26
//                                                                  //
 
27
//////////////////////////////////////////////////////////////////////
 
28
 
 
29
package org.jcsp.plugNplay;
 
30
 
 
31
import org.jcsp.lang.*;
 
32
 
 
33
/**
 
34
 * The output stream is the tail of its input stream.
 
35
 * <H2>Process Diagram</H2>
 
36
 * <p><img src="doc-files/Tail1.gif"></p>
 
37
 * <H2>Description</H2>
 
38
 * The first Object (i.e. <i>head</i>) of its input stream is not forwarded.
 
39
 * The rest (i.e. <i>tail</i>) is copied through unchanged.
 
40
 * <P>
 
41
 * Two inputs are needed before any output
 
42
 * is produced but, thereafter, one output is produced for each input.
 
43
 * <P>
 
44
 * <H2>Channel Protocols</H2>
 
45
 * <TABLE BORDER="2">
 
46
 *   <TR>
 
47
 *     <TH COLSPAN="3">Input Channels</TH>
 
48
 *   </TR>
 
49
 *   <TR>
 
50
 *     <TH>in</TH>
 
51
 *     <TD>java.lang.Object</TD>
 
52
 *     <TD>
 
53
 *       The in Channel can accept data of any Class.
 
54
 *     </TD>
 
55
 *   </TR>
 
56
 *   <TR>
 
57
 *     <TH COLSPAN="3">Output Channels</TH>
 
58
 *   </TR>
 
59
 *   <TR>
 
60
 *     <TH>out</TH>
 
61
 *     <TD>java.lang.Object</TD>
 
62
 *     <TD>
 
63
 *       The out Channel will send data of the same type
 
64
 *       as that sent down the in Channel.
 
65
 *     </TD>
 
66
 *   </TR>
 
67
 * </TABLE>
 
68
 * <P>
 
69
 * <H2>Implementation Note</H2>
 
70
 * The implementation uses an {@link Identity} process for the copy loop:
 
71
 * <PRE>
 
72
 *   public void run () {
 
73
 *     in.read ();                        // accept, but discard, the first item
 
74
 *     new Identity (in, out).run ();     // copy the rest of the stream
 
75
 *   }
 
76
 * </PRE>
 
77
 *
 
78
 * @author P.H. Welch and P.D. Austin
 
79
 */
 
80
 
 
81
public final class Tail implements CSProcess
 
82
{
 
83
   /** The input Channel */
 
84
   private ChannelInput in;
 
85
   
 
86
   /** The output Channel */
 
87
   private ChannelOutput out;
 
88
   
 
89
   /**
 
90
    * Construct a new Tail process with the input Channel in and the
 
91
    * output Channel out.
 
92
    *
 
93
    * @param in the input Channel
 
94
    * @param out the output Channel
 
95
    */
 
96
   public Tail(ChannelInput in, ChannelOutput out)
 
97
   {
 
98
      this.in = in;
 
99
      this.out = out;
 
100
   }
 
101
   
 
102
   /**
 
103
    * The main body of this process.
 
104
    */
 
105
   public void run()
 
106
   {
 
107
      in.read();
 
108
      new Identity(in, out).run();
 
109
   }
 
110
}