Disable TestHasApps.
[SquirrelJME.git] / modules / midp-lcdui / src / test / java / lcdui / list / ListItem.java
blob01e2075faea2f14f70f2cf947ad259bf4e51bf68
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package lcdui.list;
12 import java.util.Objects;
13 import java.util.Random;
14 import javax.microedition.lcdui.Font;
15 import javax.microedition.lcdui.Image;
16 import javax.microedition.lcdui.List;
18 /**
19 * This stores information about a single list item.
21 * @since 2020/11/08
23 public final class ListItem
25 /** Label. */
26 public String label;
28 /** Image. */
29 public Image image;
31 /** Font. */
32 public Font font;
34 /** Is this enabled? */
35 public boolean enabled;
37 /** Is this selected? */
38 public boolean selected;
40 /**
41 * Initializes the given list item.
43 * @param __label The label.
44 * @param __image The image.
45 * @param __font The font.
46 * @param __enabled Is this enabled?
47 * @param __selected Is this selected?
48 * @throws NullPointerException If there is no label.
49 * @since 2020/11/08
51 public ListItem(String __label, Image __image, Font __font,
52 boolean __enabled, boolean __selected)
53 throws NullPointerException
55 if (__label == null)
56 throw new NullPointerException("NARG");
58 this.label = __label;
59 this.image = __image;
60 this.font = __font;
61 this.enabled = __enabled;
62 this.selected = __selected;
65 /**
66 * {@inheritDoc}
67 * @since 2020/11/08
69 @Override
70 public boolean equals(Object __o)
72 if (__o == this)
73 return true;
75 if (!(__o instanceof ListItem))
76 return false;
78 ListItem o = (ListItem)__o;
79 return this.hashCode() == o.hashCode() &&
80 this.enabled == o.enabled &&
81 this.selected == o.selected &&
82 Objects.equals(this.label, o.label) &&
83 Objects.equals(this.image, o.image) &&
84 Objects.equals(this.font, o.font);
87 /**
88 * {@inheritDoc}
89 * @since 2020/11/08
91 @Override
92 public int hashCode()
94 int rv = 0;
96 rv ^= (this.selected ? 0x8000_0000 : 0x4000_0000);
97 rv ^= (this.enabled ? 0x0800_0000 : 0x0400_0000);
98 rv ^= (this.label != null ?
99 (this.label.hashCode() | 0x0080_0000) : 0x0040_0000);
100 rv ^= (this.image != null ?
101 (this.image.hashCode() | 0x0008_0000) : 0x0004_0000);
102 rv ^= (this.font != null ?
103 (this.font.hashCode() | 0x0000_8000) : 0x0000_4000);
105 return rv;
109 * Sets the given list item.
111 * @param __list The list to set.
112 * @param __dx The index to set.
113 * @throws NullPointerException On null arguments.
114 * @since 2020/11/08
116 public final void into(List __list, int __dx)
117 throws NullPointerException
119 if (__list == null)
120 throw new NullPointerException("NARG");
122 __list.set(__dx, this.label, this.image);
123 __list.setFont(__dx, this.font);
124 __list.setSelectedIndex(__dx, this.selected);
125 __list.setEnabled(__dx, this.enabled);
129 * Returns information on the given list item.
131 * @param __list The list to get from.
132 * @param __dx The index to read.
133 * @return The resulting list item.
134 * @throws NullPointerException On null arguments.
135 * @since 2020/11/08
137 public static ListItem of(List __list, int __dx)
138 throws NullPointerException
140 if (__list == null)
141 throw new NullPointerException("NARG");
143 return new ListItem(__list.getString(__dx),
144 __list.getImage(__dx),
145 __list.getFont(__dx),
146 __list.isEnabled(__dx),
147 __list.isSelected(__dx));
151 * Returns a randomized item.
153 * @param __rand The randomized source.
154 * @return A newly randomized list item.
155 * @throws NullPointerException On null arguments.
156 * @since 2020/11/13
158 public static ListItem random(Random __rand)
159 throws NullPointerException
161 if (__rand == null)
162 throw new NullPointerException("NARG");
164 // Face
165 int face;
166 switch (__rand.nextInt(3))
168 case 0: face = Font.FACE_MONOSPACE; break;
169 case 1: face = Font.FACE_PROPORTIONAL; break;
170 default: face = Font.FACE_SYSTEM; break;
173 // Style
174 int style;
175 switch (__rand.nextInt(4))
177 case 0: style = Font.STYLE_BOLD; break;
178 case 1: style = Font.STYLE_ITALIC; break;
179 case 2: style = Font.STYLE_PLAIN; break;
180 default: style = Font.STYLE_UNDERLINED; break;
183 // Size
184 int size;
185 switch (__rand.nextInt(3))
187 case 0: size = Font.SIZE_LARGE; break;
188 case 1: size = Font.SIZE_MEDIUM; break;
189 default: size = Font.SIZE_SMALL; break;
192 return new ListItem(
193 Character.toString((char)('a' + __rand.nextInt(25))),
194 Image.createImage(1 + __rand.nextInt(16),
195 1 + __rand.nextInt(16)),
196 Font.getFont(face, style, size),
197 __rand.nextBoolean(), __rand.nextBoolean());