KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > buddyreplication > GravitateResult


1 package org.jboss.cache.buddyreplication;
2
3 import org.jboss.cache.Fqn;
4 import org.jboss.cache.Node;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.List JavaDoc;
8
9 public class GravitateResult
10 {
11    private boolean dataFound;
12
13    /**
14     * Represents one <code>Node</code> in the subtree rooted
15     * at <code>fqn</code>.
16     */

17    private List JavaDoc<Node> subtree;
18
19    private byte marshalledData[];
20
21    private Fqn buddyBackupRegion;
22
23    public static GravitateResult noDataFound()
24    {
25       return new GravitateResult(false, null, null, null);
26    }
27
28    public static GravitateResult subtreeResult(List JavaDoc<Node> subtree, Fqn fqn)
29    {
30       return new GravitateResult(true, subtree, null, fqn);
31    }
32
33    public static GravitateResult marshalledResult(byte[] marshalledData, Fqn fqn)
34    {
35       return new GravitateResult(true, null, marshalledData, fqn);
36    }
37
38    private GravitateResult(boolean dataFound, List JavaDoc<Node> subtree, byte[] marshalledData, Fqn buddyBackupRegion)
39    {
40       this.dataFound = dataFound;
41       this.subtree = subtree;
42       this.marshalledData = marshalledData;
43       this.buddyBackupRegion = buddyBackupRegion;
44    }
45
46    /**
47     * @return the buddyBackupRegion
48     */

49    public Fqn getBuddyBackupRegion()
50    {
51       return buddyBackupRegion;
52    }
53
54    /**
55     * @return true if data was found
56     */

57    public boolean getDataFound()
58    {
59       return dataFound;
60    }
61
62    /**
63     * @return the marshalledData
64     */

65    public byte[] getMarshalledData()
66    {
67       return marshalledData;
68    }
69
70    /**
71     * @return the subtree
72     */

73    public List JavaDoc<Node> getSubtree()
74    {
75       return subtree;
76    }
77
78    public String JavaDoc toString()
79    {
80       return "Result dataFound=" + dataFound +
81               " subtree=" + subtree +
82               " data=" + marshalledData +
83               " fqn=" + buddyBackupRegion;
84    }
85
86    /**
87     * Converts the data to some weird format.
88     */

89    public List JavaDoc asList()
90    {
91       List JavaDoc l = new ArrayList JavaDoc();
92       l.add(dataFound);
93       if (dataFound)
94       {
95          if (marshalledData != null)
96             l.add(marshalledData);
97          else
98             l.add(subtree);
99          l.add(buddyBackupRegion);
100       }
101       return l;
102    }
103
104 }
105
Popular Tags