Using EnumSet by Example
In previous example I have explained using enum using color constants. Java util collection has provides EnumSet , it is a specialized Set implementation for use with enum types. In this post I have explained usage of EnumSet using an example. A text can have multiple attributes like bold, italic, underlined etc. Given a text can have these properties, defined a sample Text class with bit fields as text properties public class Text { //defining Text properties using int public static final int BOLD = 1<<0; public static final int ITALIC = 1<<1; public static final int UNDERLINED = 1<<2; private int style; public Text( int style){ this .style = style; } public boolean isBold(){ return (BOLD&style)==BOLD; } public boolean isItalic(){ return (ITALIC&style)==ITALIC; } public boolean isUnderlined(){ return (UNDE...