Skip to content

Instantly share code, notes, and snippets.

@Nicklas2751
Created January 21, 2020 20:49
Show Gist options
  • Save Nicklas2751/342c9e4df025ee9495610c12bc740f03 to your computer and use it in GitHub Desktop.
Save Nicklas2751/342c9e4df025ee9495610c12bc740f03 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
/**
* A video resolution.
*/
public class Aufloesung {
private final int width;
private final int height;
public Aufloesung(int width, int height) {
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Aufloesung)) return false;
Aufloesung that = (Aufloesung) o;
return getWidth() == that.getWidth() &&
getHeight() == that.getHeight();
}
@Override
public int hashCode() {
return Objects.hash(getWidth(), getHeight());
}
@Override
public String toString() {
return StringRepresentation.findByAufloesung(this).map(Objects::toString).orElse(width + "x" + height);
}
/**
* A string representation of a video resolution.
*/
public enum StringRepresentation {
PAL_VCD(352, 288, "PAL (VCD)"),
PAL_CVD(352, 576, "PAL (CVD)"),
PAL_SVCD(480, 576, "PAL (SVCD)"),
PAL(544, 576, "PAL"),
PAL_DVD(704, 576, "PAL (DVD)"),
PAL_DV(720, 576, "PAL (DV)"),
PAL_DVB(768, 576, "PAL (DVB)"),
PAL_WIDE(1024, 576, "PAL-wide"),
PAL_OPT(960, 540, "PAL-opt"),
NTSC_VCD(352, 240, "NTSC (VCD)"),
NTSC_CVD(352, 480, "NTSC (CVD)"),
NTSC_SVCD(480, 480, "NTSC SVCD"),
NTSC(544, 480, "NTSC"),
NTSC_VGA(640, 480, "NTSC (VGA)"),
NTSC_DVD(704, 480, "NTSC (DVD)"),
NTSC_DV(720, 480, "NTSC (DV)"),
HD720_DV(960, 720, "HDTV 720 (DV)"),
HD720(1280, 720, "HDTV 720"),
HD1080_DV(1440, 1080, "HDTV 1080 (DV)"),
FULL_HD(1920, 1080, "Full HDTV"),
UHD_4K(3840, 2160, "Ultra HDTV 4K"),
UHD_8K(7680, 4320, "Ultra HDTV 8K"),
QUHD_16K(15360, 8640, "Quad Ultra HDTV 16K");
private final String representation;
private final int width;
private final int height;
StringRepresentation(int width, int height, String representation) {
this.width = width;
this.height = height;
this.representation = representation;
}
public static Optional<StringRepresentation> findByAufloesung(Aufloesung aufloesung) {
return Arrays.stream(StringRepresentation.values())
.filter(stringRepresentation -> stringRepresentation.height == aufloesung.height &&
stringRepresentation.width == aufloesung.width)
.findFirst();
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
@Override
public String toString() {
return representation;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment