File: Customers7.java

package info (click to toggle)
libjibx1.2-java 1.2.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,260 kB
  • sloc: java: 75,013; xml: 14,068; makefile: 17
file content (179 lines) | stat: -rw-r--r-- 6,072 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
Copyright (c) 2003, Dennis M. Sosnoski
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
 * Neither the name of JiBX nor the names of its contributors may be used
   to endorse or promote products derived from this software without specific
   prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package simple;

import java.util.Iterator;

public class Customers7
{
    private DerivedCollection collection = new DerivedCollection();
    
    private void setCustomerCount(int count) {
        if (count > 0) {
            collection.setCustomerCount(count);
        } else {
            collection = null;
        }
    }
	
	private int getCustomerCount() {
        if (collection == null) {
            return 0;
        } else {
            return collection.getCustomerCount();
        }
	}
	
	private void wrappedAddCustomer(Object obj) {
		collection.addCustomer((CustomerInterface)obj);
	}
    
    private boolean wrappedHasCustomer() {
        return collection != null && collection.hasCustomer();
    }
    
    private Iterator wrappedGetCustomerIterator() {
        return new CustomerIterator(collection);
    }
    
    private static class CustomerCollection {
        
        private int fillPosition;
        private CustomerInterface[] customers;
        
        protected void setCustomerCount(int count) {
            customers = new Customer[count];
            fillPosition = 0;
        }
        
        protected int getCustomerCount() {
            return fillPosition;
        }
        
        protected void addCustomer(CustomerInterface obj) {
            customers[fillPosition++] = obj;
        }
        
        protected boolean hasCustomer() {
            return fillPosition > 0;
        }
        
        protected CustomerInterface getCustomer(int index) {
            return customers[index];
        }
        
        protected Iterator getCustomerIterator() {
            return new CustomerIterator(this);
        }
    }
    
    private static class DerivedCollection extends CustomerCollection {
    }
    
    private static class CustomerIterator implements Iterator {
        
        private final CustomerCollection collection;
        int nextIndex;
        
        private CustomerIterator(CustomerCollection coll) {
            collection = coll;
            nextIndex = 0;
        }

        public boolean hasNext() {
            return collection != null && nextIndex < collection.fillPosition;
        }

        public Object next() {
            if (nextIndex < collection.fillPosition) {
                return collection.getCustomer(nextIndex++);
            } else {
                return null;
            }
        }

        public void remove() {
            throw new UnsupportedOperationException("No remove support");
        }
    }
    
    public static CustomerInterface createCustomer() {
        return new Customer();
    }
    
    public interface CustomerInterface
    {
        public Name getName();
        public boolean isName();
        public void flagName(boolean flag);
        public String getStreet1();
        public String getCity();
        public String getState();
        public String getZip();
        public void setName(Name name);
        public void setStreet1(String street1);
        public void setCity(String city);
        public void setState(String state);
        public void setZip(String zip);
        public boolean isExtra();
        public void flagExtra(boolean flag);
        public boolean isSkipped();
        public void flagSkipped(boolean flag);
    }
    
    public interface ExtendedCustomerInterface extends CustomerInterface {}
	
	public static class Customer implements ExtendedCustomerInterface
	{
		private Name name;
        private boolean ifName;
		private String street1;
		private String city;
		private String state;
		private String zip;
        private boolean extra;
        private boolean skipped;
        public Name getName() { return name; }
        public boolean isName() { return ifName; }
        public void flagName(boolean flag) { ifName = flag; }
        public String getStreet1() { return street1; }
        public String getCity() { return city; }
        public String getState() { return state; }
        public String getZip() { return zip; }
        public void setName(Name name) { this.name = name; }
        public void setStreet1(String street1) { this.street1 = street1; }
        public void setCity(String city) { this.city = city; }
        public void setState(String state) { this.state = state; }
        public void setZip(String zip) { this.zip = zip; }
        public boolean isExtra() { return extra; }
        public void flagExtra(boolean flag) { extra = flag; }
        public boolean isSkipped() { return skipped; }
        public void flagSkipped(boolean flag) { skipped = flag; }
	}
}