110 * @return int tag value (or deflt.) 111 */ 112 public static int switchTagAsInt(final Object tag, final int deflt) { 113 if (tag instanceof Number) { 114 final double d = ((Number)tag).doubleValue(); 115 if (isRepresentableAsInt(d)) { 116 return (int)d; 117 } 118 } 119 120 return deflt; 121 } 122 123 /** 124 * Converts a switch tag value to a simple integer. deflt value if it can't. 125 * 126 * @param tag Switch statement tag value. 127 * @param deflt default to use if not convertible. 128 * @return int tag value (or deflt.) 129 */ 130 public static int switchTagAsInt(final long tag, final int deflt) { 131 return isRepresentableAsInt(tag) ? (int)tag : deflt; 132 } 133 134 /** 135 * Converts a switch tag value to a simple integer. deflt value if it can't. 136 * 137 * @param tag Switch statement tag value. 138 * @param deflt default to use if not convertible. 139 * @return int tag value (or deflt.) 140 */ 141 public static int switchTagAsInt(final double tag, final int deflt) { 142 return isRepresentableAsInt(tag) ? (int)tag : deflt; 143 } 144 145 /** 146 * This is the builtin implementation of {@code Object.prototype.toString} 147 * @param self reference 148 * @return string representation as object 149 */ | 110 * @return int tag value (or deflt.) 111 */ 112 public static int switchTagAsInt(final Object tag, final int deflt) { 113 if (tag instanceof Number) { 114 final double d = ((Number)tag).doubleValue(); 115 if (isRepresentableAsInt(d)) { 116 return (int)d; 117 } 118 } 119 120 return deflt; 121 } 122 123 /** 124 * Converts a switch tag value to a simple integer. deflt value if it can't. 125 * 126 * @param tag Switch statement tag value. 127 * @param deflt default to use if not convertible. 128 * @return int tag value (or deflt.) 129 */ 130 public static int switchTagAsInt(final boolean tag, final int deflt) { 131 return deflt; 132 } 133 134 /** 135 * Converts a switch tag value to a simple integer. deflt value if it can't. 136 * 137 * @param tag Switch statement tag value. 138 * @param deflt default to use if not convertible. 139 * @return int tag value (or deflt.) 140 */ 141 public static int switchTagAsInt(final long tag, final int deflt) { 142 return isRepresentableAsInt(tag) ? (int)tag : deflt; 143 } 144 145 /** 146 * Converts a switch tag value to a simple integer. deflt value if it can't. 147 * 148 * @param tag Switch statement tag value. 149 * @param deflt default to use if not convertible. 150 * @return int tag value (or deflt.) 151 */ 152 public static int switchTagAsInt(final double tag, final int deflt) { 153 return isRepresentableAsInt(tag) ? (int)tag : deflt; 154 } 155 156 /** 157 * This is the builtin implementation of {@code Object.prototype.toString} 158 * @param self reference 159 * @return string representation as object 160 */ |