| 11 | import java.awt.Color; |
| 12 | |
| 13 | public class ColorParser |
| 14 | { |
| 15 | private ColorParser() {} |
| 16 | |
| 17 | static Color parseColor(String str) |
| 18 | { |
| 19 | if (str.startsWith("#") && str.length() == 7) { |
| 20 | return new Color(Integer.parseInt(str.substring(1), 16)); |
| 21 | } |
| 22 | else if (str.startsWith("rgba(") && str.endsWith(")")) { |
| 23 | String [] parts = str.substring(5,str.length()-1).split(","); |
| 24 | int r = Integer.parseInt(parts[0]); |
| 25 | int g = Integer.parseInt(parts[1]); |
| 26 | int b = Integer.parseInt(parts[2]); |
| 27 | double aa = Double.parseDouble(parts[3]); |
| 28 | int a = Math.min(255, (int)Math.floor(aa*256.0)); |
| 29 | return new Color(r,g,b,a); |
| 30 | } |
| 31 | else { |
| 32 | throw new Error("invalid color format: "+str); |
| 33 | } |
| 34 | } |
| 35 | } |
nothing calls this directly
no outgoing calls
no test coverage detected