source: trunk/src/ws/fugue88/access/ContainmentAccessor.java

Last change on this file was 3, checked in by dsowen, 21 years ago

Copyright notice fixed.
Added containment accessor.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.3 KB
Line 
1/*
2 * This code is copyright (c) 2005 David Owen.  All rights not explicitly
3 * granted by the author are reserved.
4 *
5 * Created on Oct 4, 2005.
6 */
7package ws.fugue88.access;
8
9import java.util.Collection;
10
11/**
12 * Represents the containment property of a given collection and object.
13 *
14 * @author dsowen
15 */
16public class ContainmentAccessor implements Accessor {
17
18        public ContainmentAccessor(final Collection coll, final Object obj)
19        {
20                coll.getClass();
21
22                _coll = coll;
23                _obj = obj;
24        }
25
26        /**
27         * @return <code>Boolean.class</code>
28         */
29        public Class getType()
30        {
31                return Boolean.class;
32        }
33
34        /**
35         * Equivalent to <code>setValue(Boolean.FALSE);</code>.
36         */
37        public void clearValue()
38        {
39                setValue(Boolean.FALSE);
40        }
41
42        /**
43         * @return <code>true</code> iff the collection contains the object
44         */
45        public Object getValue()
46        {
47                return Boolean.valueOf(_coll.contains(_obj));
48        }
49
50        /**
51         * If <var>value </var> is <code>true</code> or <code>false</code>,
52         * ensures that the collection does or doesn't contain, respectively, the
53         * object.
54         */
55        public void setValue(final Object value)
56        {
57                if(((Boolean)value).booleanValue()) {
58                        if(!_coll.contains(_obj)) _coll.add(_obj);
59                } else {
60                        while(_coll.contains(_obj))
61                                _coll.remove(_obj);
62                }
63        }
64
65        private final Collection _coll;
66        private final Object _obj;
67}
Note: See TracBrowser for help on using the repository browser.