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

aspectran / aspectran / #4407

17 Jul 2025 08:32AM CUT coverage: 34.843% (-0.1%) from 34.982%
#4407

push

github

topframe
Update

0 of 148 new or added lines in 5 files covered. (0.0%)

6 existing lines in 1 file now uncovered.

14406 of 41346 relevant lines covered (34.84%)

0.35 hits per line

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

0.0
/core/src/main/java/com/aspectran/core/activity/FlashMap.java
1
/*
2
 * Copyright (c) 2008-present The Aspectran Project
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
package com.aspectran.core.activity;
17

18
import com.aspectran.utils.ObjectUtils;
19
import com.aspectran.utils.ToStringBuilder;
20
import com.aspectran.utils.annotation.jsr305.NonNull;
21
import com.aspectran.utils.annotation.jsr305.Nullable;
22

23
import java.io.Serial;
24
import java.util.HashMap;
25

26
/**
27
 * A FlashMap provides a way for one request to store attributes intended for
28
 * use in another. This is most commonly needed when redirecting from one URL
29
 * to another -- for example, the Post/Redirect/Get pattern. A FlashMap is saved before
30
 * the redirect (typically in the session) and is made available after the
31
 * redirect and removed immediately.
32
 *
33
 * <p>A FlashMap can be set up with a request path and request parameters to
34
 * help identify the target request. Without this information, a FlashMap is
35
 * made available to the next request, which may or may not be the intended
36
 * recipient. On a redirect, the target URL is known and a FlashMap can be
37
 * updated with that information. This is done automatically when the
38
 * {@code org.springframework.web.servlet.view.RedirectView} is used.
39
 *
40
 * <p>Note: annotated controllers will usually not use FlashMap directly.
41
 * See {@code org.springframework.web.servlet.mvc.support.RedirectAttributes}
42
 * for an overview of using flash attributes in annotated controllers.
43
 * @see FlashMapManager
44
 * @since 8.4.0
45
 */
46
public final class FlashMap extends HashMap<String, Object> implements Comparable<FlashMap> {
×
47

48
    @Serial
49
    private static final long serialVersionUID = -4459013870858137422L;
50

51
    @Nullable
52
    private String targetRequestName;
53

54
    private long expirationTime = -1;
×
55

56
    /**
57
     * Return the target URL path (or {@code null} if none specified).
58
     */
59
    @Nullable
60
    public String getTargetRequestName() {
61
        return targetRequestName;
×
62
    }
63

64
    /**
65
     * Provide a Translet name to help identify the target request for this FlashMap.
66
     */
67
    public void setTargetRequestName(@Nullable String requestName) {
68
        this.targetRequestName = requestName;
×
69
    }
×
70

71
    /**
72
     * Return the expiration time for the FlashMap or -1 if the expiration
73
     * period has not started.
74
     */
75
    public long getExpirationTime() {
76
        return expirationTime;
×
77
    }
78

79
    /**
80
     * Set the expiration time for the FlashMap. This is provided for serialization
81
     * purposes but can also be used instead {@link #startExpirationPeriod(int)}.
82
     */
83
    public void setExpirationTime(long expirationTime) {
84
        this.expirationTime = expirationTime;
×
85
    }
×
86

87
    /**
88
     * Start the expiration period for this instance.
89
     * @param timeToLive the number of seconds before expiration
90
     */
91
    public void startExpirationPeriod(int timeToLive) {
92
        this.expirationTime = System.currentTimeMillis() + timeToLive * 1000L;
×
93
    }
×
94

95
    /**
96
     * Return whether this instance has expired depending on the amount of
97
     * elapsed time since the call to {@link #startExpirationPeriod}.
98
     */
99
    public boolean isExpired() {
100
        return (expirationTime != -1 && System.currentTimeMillis() > expirationTime);
×
101
    }
102

103
    /**
104
     * Compare two FlashMaps and prefer the one that specifies a target URL
105
     * path or has more target URL parameters. Before comparing FlashMap
106
     * instances ensure that they match a given request.
107
     */
108
    @Override
109
    public int compareTo(@NonNull FlashMap other) {
110
        int thisUrlPath = (targetRequestName != null ? 1 : 0);
×
111
        int otherUrlPath = (other.targetRequestName != null ? 1 : 0);
×
112
        return otherUrlPath - thisUrlPath;
×
113
    }
114

115
    @Override
116
    public boolean equals(@Nullable Object other) {
117
        return (this == other || (other instanceof FlashMap that &&
×
118
                super.equals(other) &&
×
119
                ObjectUtils.nullSafeEquals(targetRequestName, that.targetRequestName)));
×
120
    }
121

122
    @Override
123
    public int hashCode() {
124
        int result = super.hashCode();
×
125
        result = 31 * result + ObjectUtils.nullSafeHashCode(targetRequestName);
×
126
        return result;
×
127
    }
128

129
    @Override
130
    public String toString() {
131
        ToStringBuilder tsb = new ToStringBuilder();
×
132
        tsb.append("targetRequestName", targetRequestName);
×
133
        tsb.append("attributes", this);
×
134
        return tsb.toString();
×
135
    }
136

137
}
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