Makefile: insert Lanterna resources at the right place
[jvcard.git] / src / be / nikiroo / jvcard / launcher / CardResult.java
CommitLineData
5ad0e17e
NR
1package be.nikiroo.jvcard.launcher;
2
3import java.io.IOException;
4
5import be.nikiroo.jvcard.Card;
6
7/**
8 * This class is a placeholder for a {@link Card} result and some information
9 * about it.
10 *
11 * @author niki
12 *
13 */
14public class CardResult {
15 /**
16 * This interface represents the merge callback when the {@link Card}
17 * synchronisation is not able to process fully automatically.
18 *
19 * @author niki
20 *
21 */
22 public interface MergeCallback {
23 /**
24 * This method will be called when the local cache and the server both
25 * have changes. You need to review the proposed changes, or do your own
26 * merge, and return the final result. You can also cancel the merge
27 * operation by returning NULL.
28 *
29 * @param previous
30 * the previous version of the {@link Card}
31 * @param local
32 * the local cache version of the {@link Card}
33 * @param server
34 * the remote server version of the {@link Card}
35 * @param autoMerged
36 * the automatic merge result you should manually check
37 *
38 * @return the final merged result, or NULL for cancel
39 */
40 public Card merge(Card previous, Card local, Card server,
41 Card autoMerged);
42 }
43
44 private Card card;
45 private boolean remote;
46 private boolean synced;
47 private boolean changed;
48 private IOException exception;
49
50 /**
51 * Create a new {@link CardResult}.
52 *
53 * @param card
54 * the target {@link Card}
55 * @param remtote
56 * TRUE if it is linked to a remote server
57 * @param synced
58 * TRUE if it was synchronised
59 */
60 public CardResult(Card card, boolean remote, boolean synced, boolean changed) {
61 this.card = card;
62 this.synced = synced;
63 this.changed = changed;
64 }
65
66 /**
67 * Create a new {@link CardResult}.
68 *
69 * @param exception
70 * the synchronisation exception that occurred
71 */
72 public CardResult(IOException exception) {
73 this(null, true, false, false);
74 this.exception = exception;
75 }
76
77 /**
78 * Check if this {@link Card} is linked to a remote jVCard server.
79 *
80 * @return TRUE if it is
81 */
82 public boolean isRemote() {
83 return remote;
84 }
85
86 /**
87 * Check if the {@link Card} was synchronised.
88 *
89 * @return TRUE if it was
90 */
91 public boolean isSynchronised() {
92 return synced;
93 }
94
95 /**
96 * Check if this {@link Card} changed after the synchronisation.
97 *
98 * @return TRUE if it has
99 */
100 public boolean isChanged() {
101 return remote && changed;
102 }
103
104 /**
105 * Return the {@link Card}
106 *
107 * @return the {@link Card}
108 *
109 * @throws IOException
110 * in case of synchronisation issues
111 */
112 public Card getCard() throws IOException {
113 if (exception != null)
114 throw exception;
115
116 return card;
117 }
118}