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

Last change on this file since 10446 was 10378, checked in by Don-vip, 8 years ago

Checkstyle 6.19: enable SingleSpaceSeparator and fix violations

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