• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

smartsheet / smartsheet-java-sdk / #50

02 Oct 2023 04:35PM UTC coverage: 56.752% (+0.03%) from 56.722%
#50

push

github-actions

web-flow
Checkstyle fixes and refactor DefaultHttpClient#request (#72)

* Correct additional checkstyle issues and refactor DefaultHttpClient#request

* Reduce checkstyle errors to 5

* Update to add supressions instead of removing rules

45 of 45 new or added lines in 5 files covered. (100.0%)

3875 of 6828 relevant lines covered (56.75%)

0.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.52
/src/main/java/com/smartsheet/api/models/DateObjectValue.java
1
/*
2
 * Copyright (C) 2023 Smartsheet
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.smartsheet.api.models;
18

19
import com.smartsheet.api.models.enums.ObjectValueType;
20

21
import java.text.ParseException;
22
import java.text.SimpleDateFormat;
23
import java.util.Date;
24

25
public class DateObjectValue implements ObjectValue {
26
    public static final String ABSTRACT_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
27
    public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
28
    public static final String DATE_FORMAT = "yyyy-MM-dd";
29
    private ObjectValueType objectType;
30
    private String value;
31
    private Date date;
32

33
    /**
34
     * Get DateObjectValue from date
35
     */
36
    public static DateObjectValue fromDate(ObjectValueType objectValueType, Date date) {
37
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(getFormatPattern(objectValueType));
×
38
        String value = simpleDateFormat.format(date);
×
39

40
        return new DateObjectValue(objectValueType, value);
×
41
    }
42

43
    /**
44
     * Constructor
45
     */
46
    public DateObjectValue(ObjectValueType objectType, String value) {
1✔
47
        this.objectType = objectType;
1✔
48
        this.value = value;
1✔
49
    }
1✔
50

51
    @Override
52
    public ObjectValueType getObjectType() {
53
        return objectType;
1✔
54
    }
55

56
    /**
57
     * Set the Object Type
58
     */
59
    public DateObjectValue setObjectType(ObjectValueType objectType) {
60
        this.objectType = objectType;
×
61
        return this;
×
62
    }
63

64
    public String getValue() {
65
        return value;
1✔
66
    }
67

68
    /**
69
     * Set the value
70
     */
71
    public DateObjectValue setValue(String value) {
72
        this.value = value;
×
73
        return this;
×
74
    }
75

76
    /**
77
     * Convert to a Date
78
     */
79
    public Date toDate() throws ParseException {
80
        if (date == null && value != null) {
1✔
81
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(getFormatPattern(objectType));
1✔
82
            date = simpleDateFormat.parse(value);
1✔
83
        }
84
        return date;
1✔
85
    }
86

87
    private static String getFormatPattern(ObjectValueType objectValueType) {
88
        if (objectValueType != null) {
1✔
89
            switch (objectValueType) {
1✔
90
                case ABSTRACT_DATETIME:
91
                    return ABSTRACT_DATETIME_FORMAT;
×
92
                case DATETIME:
93
                    return DATETIME_FORMAT;
1✔
94
                case DATE:
95
                    return DATE_FORMAT;
×
96

97
                default:
98
                    // Throw IllegalArgumentException
99
                    break;
100
            }
101
        }
102

103
        throw new IllegalArgumentException("Unsupported objectValueType: " + objectValueType);
×
104
    }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc