src/main/java/de/uapcore/lightpit/types/WebColor.java

Thu, 15 Oct 2020 12:27:05 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 Oct 2020 12:27:05 +0200
changeset 127
6105ee2cceaf
permissions
-rw-r--r--

adds component entity

     1 package de.uapcore.lightpit.types;
     3 public final class WebColor {
     5     private final String hex;
     7     /**
     8      * Constructs a color object from a hex string.
     9      * @param hex the 6 digits hex string optionally preceded by a hash symbol
    10      * @throws IllegalArgumentException if the given string does not specify a color
    11      */
    12     public WebColor(String hex) throws IllegalArgumentException {
    13         this.hex = (hex.startsWith("#") ? hex : ("#"+hex)).toUpperCase();
    14         if (!this.hex.matches("#[0-9A-F]{6}"))
    15             throw new IllegalArgumentException(hex+" is not a color");
    16     }
    18     /**
    19      * Returns the hex representation without th leading hash symbol.
    20      * @return the hex representation of this color (e.g. FF0000 for red)
    21      */
    22     public String getHex() {
    23         return hex.substring(1);
    24     }
    26     @Override
    27     public String toString() {
    28         return hex;
    29     }
    30 }

mercurial