source: josm/trunk/src/org/openstreetmap/josm/gui/io/UploadStrategySpecification.java@ 5832

Last change on this file since 5832 was 5832, checked in by stoecker, 11 years ago

i18n update and javadoc fixes

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4/**
5 * An UploadStrategySpecification consists of the parameter describing the strategy
6 * for uploading a collection of {@link org.openstreetmap.josm.data.osm.OsmPrimitive}.
7 *
8 * This includes:
9 * <ul>
10 * <li>a decision on which {@link UploadStrategy} to use</li>
11 * <li>the upload chunk size</li>
12 * <li>whether to close the changeset used after the upload</li>
13 * </ul>
14 */
15public class UploadStrategySpecification {
16 /** indicates that the chunk size isn't specified */
17 static public final int UNSPECIFIED_CHUNK_SIZE = -1;
18
19 private UploadStrategy strategy;
20 private int chunkSize;
21 private MaxChangesetSizeExceededPolicy policy;
22 private boolean closeChangesetAfterUpload;
23
24 /**
25 * Creates a new upload strategy with default values.
26 */
27 public UploadStrategySpecification() {
28 this.strategy = UploadStrategy.DEFAULT_UPLOAD_STRATEGY;
29 this.chunkSize = UNSPECIFIED_CHUNK_SIZE;
30 this.policy = null;
31 this.closeChangesetAfterUpload = true;
32 }
33
34 /**
35 * Clones another upload strategy. If other is null,assumes default
36 * values.
37 *
38 * @param other the other upload strategy
39 */
40 public UploadStrategySpecification(UploadStrategySpecification other) {
41 if (other == null) return;
42 this.strategy = other.strategy;
43 this.chunkSize = other.chunkSize;
44 this.policy = other.policy;
45 this.closeChangesetAfterUpload = other.closeChangesetAfterUpload;
46 }
47
48 /**
49 * Replies the upload strategy
50 * @return the upload strategy
51 */
52 public UploadStrategy getStrategy() {
53 return strategy;
54 }
55
56 public int getChunkSize() {
57 return chunkSize;
58 }
59
60 public static int getUnspecifiedChunkSize() {
61 return UNSPECIFIED_CHUNK_SIZE;
62 }
63
64 public MaxChangesetSizeExceededPolicy getPolicy() {
65 return policy;
66 }
67
68 public UploadStrategySpecification setStrategy(UploadStrategy strategy) {
69 this.strategy = strategy;
70 return this;
71 }
72
73 public UploadStrategySpecification setChunkSize(int chunkSize) {
74 this.chunkSize = chunkSize;
75 return this;
76 }
77
78 public UploadStrategySpecification setPolicy(MaxChangesetSizeExceededPolicy policy) {
79 this.policy = policy;
80 return this;
81 }
82
83 public UploadStrategySpecification setCloseChangesetAfterUpload(boolean closeChangesetAfterUpload) {
84 this.closeChangesetAfterUpload = closeChangesetAfterUpload;
85 return this;
86 }
87
88 public boolean isCloseChangesetAfterUpload() {
89 return closeChangesetAfterUpload;
90 }
91
92 public int getNumRequests(int numObjects) {
93 if (numObjects <=0) return 0;
94 switch(strategy) {
95 case INDIVIDUAL_OBJECTS_STRATEGY: return numObjects;
96 case SINGLE_REQUEST_STRATEGY: return 1;
97 case CHUNKED_DATASET_STRATEGY:
98 if (chunkSize == UNSPECIFIED_CHUNK_SIZE)
99 return 0;
100 else
101 return (int)Math.ceil((double)numObjects / (double)chunkSize);
102 }
103 // should not happen
104 return 0;
105 }
106
107 @Override
108 public int hashCode() {
109 final int prime = 31;
110 int result = 1;
111 result = prime * result + chunkSize;
112 result = prime * result + (closeChangesetAfterUpload ? 1231 : 1237);
113 result = prime * result + ((policy == null) ? 0 : policy.hashCode());
114 result = prime * result + ((strategy == null) ? 0 : strategy.hashCode());
115 return result;
116 }
117
118 @Override
119 public boolean equals(Object obj) {
120 if (this == obj)
121 return true;
122 if (obj == null)
123 return false;
124 if (getClass() != obj.getClass())
125 return false;
126 UploadStrategySpecification other = (UploadStrategySpecification) obj;
127 if (chunkSize != other.chunkSize)
128 return false;
129 if (closeChangesetAfterUpload != other.closeChangesetAfterUpload)
130 return false;
131 if (policy == null) {
132 if (other.policy != null)
133 return false;
134 } else if (!policy.equals(other.policy))
135 return false;
136 if (strategy == null) {
137 if (other.strategy != null)
138 return false;
139 } else if (!strategy.equals(other.strategy))
140 return false;
141 return true;
142 }
143}
Note: See TracBrowser for help on using the repository browser.