public MutableConditionals() { this(new Conditionals()); }
public void addIfMatch(Tag tag) { conditionals = conditionals.addIfMatch(tag); }
public void addIfNoneMatch(Tag tag) { conditionals = conditionals.addIfNoneMatch(tag); }
/** * You should use the server's time here. Otherwise you might get unexpected results. * The typical use case is: * * * <pre> * HTTPResponse response = .... * HTTPRequest request = createRequest(); * request = request.conditionals(new Conditionals().ifUnModifiedSince(response.getLastModified()); * </pre> * * @param time the time to check. * @return the conditionals with the If-Unmodified-Since date set. */ public Conditionals ifUnModifiedSince(LocalDateTime time) { Preconditions.checkArgument(noneMatch.isEmpty(), String.format(ERROR_MESSAGE, HeaderConstants.IF_UNMODIFIED_SINCE, HeaderConstants.IF_NONE_MATCH)); Preconditions.checkArgument(!modifiedSince.isPresent(), String.format(ERROR_MESSAGE, HeaderConstants.IF_UNMODIFIED_SINCE, HeaderConstants.IF_MODIFIED_SINCE)); time = time.withNano(0); return new Conditionals(match, empty(), Optional.empty(), Optional.of(time)); }
/** * Converts the Conditionals into real headers. * @return real headers. */ public Headers toHeaders() { Headers headers = new Headers(); if (!getMatch().isEmpty()) { headers = headers.add(new Header(HeaderConstants.IF_MATCH, buildTagHeaderValue(getMatch()))); } if (!getNoneMatch().isEmpty()) { headers = headers.add(new Header(HeaderConstants.IF_NONE_MATCH, buildTagHeaderValue(getNoneMatch()))); } if (modifiedSince.isPresent()) { headers = headers.set(HeaderUtils.toHttpDate(HeaderConstants.IF_MODIFIED_SINCE, modifiedSince.get())); } if (unModifiedSince.isPresent()) { headers = headers.set(HeaderUtils.toHttpDate(HeaderConstants.IF_UNMODIFIED_SINCE, unModifiedSince.get())); } return headers; }
public static Conditionals valueOf(Headers headers) { List<Tag> ifMatch = makeTags(headers.getFirstHeaderValue(HeaderConstants.IF_MATCH).orElse(null)); List<Tag> ifNoneMatch = makeTags(headers.getFirstHeaderValue(HeaderConstants.IF_NONE_MATCH).orElse(null)); Optional<LocalDateTime> modifiedSince = headers.getFirstHeader(HeaderConstants.IF_MODIFIED_SINCE).flatMap(HeaderUtils::fromHttpDate); Optional<LocalDateTime> unModifiedSince = headers.getFirstHeader(HeaderConstants.IF_UNMODIFIED_SINCE).flatMap(HeaderUtils::fromHttpDate); return new Conditionals(ifMatch, ifNoneMatch, modifiedSince, unModifiedSince); }
public void ifModifiedSince(LocalDateTime time) { conditionals = conditionals.ifModifiedSince(time); }
public List<Tag> getMatch() { return conditionals.getMatch(); }
public List<Tag> getNoneMatch() { return conditionals.getNoneMatch(); }
public LocalDateTime getModifiedSince() { return conditionals.getModifiedSince().orElse(null); }
public LocalDateTime getUnModifiedSince() { return conditionals.getUnModifiedSince().orElse(null); }
/** * You should use the server's time here. Otherwise you might get unexpected results. * * The typical use case is: * * * <pre> * HTTPResponse response = .... * HTTPRequest request = createRequest(); * request = request.conditionals(new Conditionals().ifModifiedSince(response.getLastModified()); * </pre> * * @param time the time to check. * @return the conditionals with the If-Modified-Since date set. */ public Conditionals ifModifiedSince(LocalDateTime time) { Preconditions.checkArgument(match.isEmpty(), String.format(ERROR_MESSAGE, HeaderConstants.IF_MODIFIED_SINCE, HeaderConstants.IF_MATCH)); Preconditions.checkArgument(!unModifiedSince.isPresent(), String.format(ERROR_MESSAGE, HeaderConstants.IF_MODIFIED_SINCE, HeaderConstants.IF_UNMODIFIED_SINCE)); time = time.withNano(0); return new Conditionals(empty(), noneMatch, Optional.of(time), Optional.empty()); }
public HTTPRequest withIfModifiedSince(LocalDateTime dt) { return headers(headers.withConditionals(headers.getConditionals().ifModifiedSince(dt))); }
/** * Adds tags to the If-Match header. * * @param tag the tag to add, may be null. This means the same as adding {@link Tag#ALL} * @throws IllegalArgumentException if ALL is supplied more than once, or you add a null tag more than once. * @return a new Conditionals object with the If-Match tag added. */ public Conditionals addIfMatch(Tag tag) { Preconditions.checkArgument(!modifiedSince.isPresent(), String.format(ERROR_MESSAGE, HeaderConstants.IF_MATCH, HeaderConstants.IF_MODIFIED_SINCE)); Preconditions.checkArgument(noneMatch.isEmpty(), String.format(ERROR_MESSAGE, HeaderConstants.IF_MATCH, HeaderConstants.IF_NONE_MATCH)); List<Tag> match = new ArrayList<>(this.match); if (tag == null) { tag = Tag.ALL; } if (Tag.ALL.equals(tag)) { match.clear(); } if (!match.contains(Tag.ALL)) { if (!match.contains(tag)) { match.add(tag); } } else { throw new IllegalArgumentException("Tag ALL already in the list"); } return new Conditionals(Collections.unmodifiableList(match), empty(), Optional.empty(), unModifiedSince); }
public HTTPRequest addIfMatch(Tag tag) { return headers(headers.withConditionals(headers.getConditionals().addIfMatch(tag))); }
public HTTPRequest addIfNoneMatch(Tag tag) { return headers(headers.withConditionals(headers.getConditionals().addIfNoneMatch(tag))); }
throw new IllegalArgumentException("Tag ALL already in the list"); return new Conditionals(empty(), Collections.unmodifiableList(noneMatch), modifiedSince, Optional.empty());