com.athaydes.rawhttp.reqinedit.StringOrFile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rawhttp-req-in-edit Show documentation
Show all versions of rawhttp-req-in-edit Show documentation
RawHTTP req-in-edit module (Jetbrains HTTP format)
package com.athaydes.rawhttp.reqinedit;
import java.util.Objects;
import java.util.function.Function;
/**
* Representation of either a {@link String} or a {@link java.io.File}.
*/
public final class StringOrFile {
private final String data;
private final boolean isFile;
private StringOrFile(String data, boolean isFile) {
this.data = data;
this.isFile = isFile;
}
static StringOrFile ofString(String bodyPart) {
return new StringOrFile(bodyPart, false);
}
static StringOrFile ofFile(String file) {
return new StringOrFile(file, true);
}
T match(Function onString, Function onFile) {
if (isFile) return onFile.apply(data);
else return onString.apply(data);
}
public boolean isBlank() {
return match(StringOrFile::blank, StringOrFile::blank);
}
private static boolean blank(String text) {
return text.trim().isEmpty();
}
@Override
public String toString() {
return "StringOrFile{" +
"data='" + data + '\'' +
", isFile=" + isFile +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StringOrFile that = (StringOrFile) o;
return isFile == that.isFile &&
data.equals(that.data);
}
@Override
public int hashCode() {
return Objects.hash(data, isFile);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy