-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathRenderFlatTempVariable.java
More file actions
40 lines (32 loc) · 1.02 KB
/
RenderFlatTempVariable.java
File metadata and controls
40 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.hubspot.jinjava.el.ext.eager;
import com.hubspot.jinjava.objects.serialization.PyishBlockSetSerializable;
import java.util.Objects;
public class RenderFlatTempVariable implements PyishBlockSetSerializable {
private static final String CONTEXT_KEY_PREFIX = "__render_%d_temp_variable__";
private final String deferredResult;
public RenderFlatTempVariable(String deferredResult) {
this.deferredResult = deferredResult;
}
public static String getVarName(String result) {
return String.format(CONTEXT_KEY_PREFIX, Math.abs(result.hashCode() >> 1));
}
@Override
public String getBlockSetBody() {
return deferredResult;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RenderFlatTempVariable that = (RenderFlatTempVariable) o;
return deferredResult.equals(that.deferredResult);
}
@Override
public int hashCode() {
return Objects.hash(deferredResult);
}
}