Skip to content

Commit b84adfc

Browse files
committed
AbstractRequestParam implementation and changing code of existing Params implementation
1 parent c00df71 commit b84adfc

File tree

8 files changed

+156
-48
lines changed

8 files changed

+156
-48
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.loopj.android.http.abstracts;
2+
3+
import com.loopj.android.http.interfaces.RequestParamInterface;
4+
5+
abstract public class AbstractRequestParam<T> implements RequestParamInterface<T> {
6+
7+
public AbstractRequestParam(T value) {
8+
setValue(value);
9+
}
10+
11+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.loopj.android.http.impl;
2+
3+
import com.loopj.android.http.abstracts.AbstractRequestParam;
4+
5+
import org.jetbrains.annotations.Nullable;
6+
7+
public class DoubleParam extends AbstractRequestParam<Double> {
8+
9+
Double value;
10+
11+
public DoubleParam(Double value) {
12+
super(value);
13+
}
14+
15+
@Nullable
16+
@Override
17+
public Double getValue() {
18+
return value;
19+
}
20+
21+
@Override
22+
public void setValue(Double value) {
23+
this.value = value;
24+
}
25+
26+
@Nullable
27+
@Override
28+
public String getStringValue() {
29+
return value == null ? null : value.toString();
30+
}
31+
}
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
package com.loopj.android.http.impl;
22

3-
import com.loopj.android.http.interfaces.RequestParamInterface;
3+
import com.loopj.android.http.abstracts.AbstractRequestParam;
44

5-
import java.io.File;
5+
import org.jetbrains.annotations.Nullable;
66

7-
public class FileParam implements RequestParamInterface<File> {
7+
import java.io.File;
88

9-
@Override
10-
public File getValue() {
11-
return null;
12-
}
9+
public class FileParam extends AbstractRequestParam<File> {
1310

14-
@Override
15-
public void setValue(File value) {
11+
File value;
1612

13+
public FileParam(File value) {
14+
super(value);
1715
}
1816

17+
@Nullable
1918
@Override
20-
public String getJsonValue() {
21-
return null;
19+
public File getValue() {
20+
return value;
2221
}
2322

2423
@Override
25-
public String getMultipartValue() {
26-
return null;
24+
public void setValue(File value) {
25+
this.value = value;
2726
}
2827

28+
@Nullable
2929
@Override
30-
public String getFormValue() {
31-
return null;
30+
public String getStringValue() {
31+
throw new UnsupportedOperationException("Not Yet Implemented");
3232
}
33+
3334
}
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
package com.loopj.android.http.impl;
22

3-
import com.loopj.android.http.interfaces.RequestParamInterface;
3+
import com.loopj.android.http.abstracts.AbstractRequestParam;
44

55
import org.apache.http.HeaderElement;
6+
import org.jetbrains.annotations.Nullable;
67

7-
public class HeaderParam implements RequestParamInterface<HeaderElement> {
8+
public class HeaderParam extends AbstractRequestParam<HeaderElement> {
89

9-
@Override
10-
public HeaderElement getValue() {
11-
return null;
12-
}
13-
14-
@Override
15-
public void setValue(HeaderElement value) {
10+
HeaderElement value;
1611

12+
public HeaderParam(HeaderElement value) {
13+
super(value);
1714
}
1815

16+
@Nullable
1917
@Override
20-
public String getJsonValue() {
21-
return null;
18+
public HeaderElement getValue() {
19+
return value;
2220
}
2321

2422
@Override
25-
public String getMultipartValue() {
26-
return null;
23+
public void setValue(HeaderElement value) {
24+
this.value = value;
2725
}
2826

27+
@Nullable
2928
@Override
30-
public String getFormValue() {
31-
return null;
29+
public String getStringValue() {
30+
return value == null ? null : String.format("%s: %s", value.getName(), value.getValue());
3231
}
3332
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.loopj.android.http.impl;
2+
3+
import com.loopj.android.http.abstracts.AbstractRequestParam;
4+
5+
import org.jetbrains.annotations.Nullable;
6+
7+
public class IntegerParam extends AbstractRequestParam<Integer> {
8+
9+
Integer value;
10+
11+
public IntegerParam(Integer value) {
12+
super(value);
13+
}
14+
15+
@Nullable
16+
@Override
17+
public Integer getValue() {
18+
return value;
19+
}
20+
21+
@Override
22+
public void setValue(Integer value) {
23+
this.value = value;
24+
}
25+
26+
@Nullable
27+
@Override
28+
public String getStringValue() {
29+
return value == null ? null : value.toString();
30+
}
31+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
package com.loopj.android.http.impl;
22

3-
import com.loopj.android.http.interfaces.RequestParamInterface;
3+
import com.loopj.android.http.abstracts.AbstractRequestParam;
4+
5+
import org.jetbrains.annotations.Nullable;
46

57
import java.io.InputStream;
68

7-
public class StreamParam implements RequestParamInterface<InputStream> {
9+
public class StreamParam extends AbstractRequestParam<InputStream> {
810

9-
@Override
10-
public InputStream getValue() {
11-
return null;
12-
}
13-
14-
@Override
15-
public void setValue(InputStream value) {
11+
InputStream value;
1612

13+
public StreamParam(InputStream value) {
14+
super(value);
1715
}
1816

17+
@Nullable
1918
@Override
20-
public String getJsonValue() {
21-
return null;
19+
public InputStream getValue() {
20+
return value;
2221
}
2322

2423
@Override
25-
public String getMultipartValue() {
26-
return null;
24+
public void setValue(InputStream value) {
25+
this.value = value;
2726
}
2827

28+
@Nullable
2929
@Override
30-
public String getFormValue() {
31-
return null;
30+
public String getStringValue() {
31+
throw new UnsupportedOperationException("Not Yet Implemented");
3232
}
3333
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.loopj.android.http.impl;
2+
3+
import com.loopj.android.http.abstracts.AbstractRequestParam;
4+
5+
import org.jetbrains.annotations.Nullable;
6+
7+
public class StringParam extends AbstractRequestParam<String> {
8+
9+
String value;
10+
11+
public StringParam(String value) {
12+
super(value);
13+
}
14+
15+
@Nullable
16+
@Override
17+
public String getValue() {
18+
return value;
19+
}
20+
21+
@Override
22+
public void setValue(String value) {
23+
this.value = value;
24+
}
25+
26+
@Nullable
27+
@Override
28+
public String getStringValue() {
29+
return value;
30+
}
31+
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.loopj.android.http.interfaces;
22

3+
import org.jetbrains.annotations.Nullable;
4+
35
import java.io.Serializable;
46

57
public interface RequestParamInterface<T> extends Serializable {
68

9+
@Nullable
710
T getValue();
11+
812
void setValue(T value);
9-
String getJsonValue();
10-
String getMultipartValue();
11-
String getFormValue();
13+
14+
@Nullable
15+
String getStringValue();
1216

1317
}

0 commit comments

Comments
 (0)