List of usage examples for java.lang Float intValue
public int intValue()
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.java
/** * Returns the value of the specified attribute (width or height). * @return the value of the specified attribute (width or height) * @param attributeName the name of the attribute to return (<tt>"width"</tt> or <tt>"height"</tt>) * @param returnNegativeValues if {@code true}, negative values are returned; * if {@code false}, this method returns an empty string in lieu of negative values; * if {@code null}, this method returns <tt>0</tt> in lieu of negative values *//*w w w . ja va2 s .co m*/ protected String getWidthOrHeight(final String attributeName, final Boolean returnNegativeValues) { String value = getDomNodeOrDie().getAttribute(attributeName); if (getBrowserVersion().hasFeature(JS_WIDTH_HEIGHT_ACCEPTS_ARBITRARY_VALUES)) { return value; } if (!PERCENT_VALUE.matcher(value).matches()) { try { final Float f = Float.valueOf(value); final int i = f.intValue(); if (i < 0) { if (returnNegativeValues == null) { value = "0"; } else if (!returnNegativeValues.booleanValue()) { value = ""; } else { value = Integer.toString(i); } } else { value = Integer.toString(i); } } catch (final NumberFormatException e) { if (!getBrowserVersion().hasFeature(JS_WIDTH_HEIGHT_ACCEPTS_ARBITRARY_VALUES)) { value = ""; } } } return value; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.java
/** * Sets the value of the specified attribute (width or height). * @param attributeName the name of the attribute to set (<tt>"width"</tt> or <tt>"height"</tt>) * @param value the value of the specified attribute (width or height) * @param allowNegativeValues if {@code true}, negative values will be stored; * if {@code false}, negative values cause an exception to be thrown;<br> * this check/conversion is only done if the feature JS_WIDTH_HEIGHT_ACCEPTS_ARBITRARY_VALUES * is set for the simulated browser *///ww w.j a v a 2 s . co m protected void setWidthOrHeight(final String attributeName, String value, final boolean allowNegativeValues) { if (!getBrowserVersion().hasFeature(JS_WIDTH_HEIGHT_ACCEPTS_ARBITRARY_VALUES) && !value.isEmpty()) { if (value.endsWith("px")) { value = value.substring(0, value.length() - 2); } boolean error = false; if (!PERCENT_VALUE.matcher(value).matches()) { try { final Float f = Float.valueOf(value); final int i = f.intValue(); if (i < 0) { if (!allowNegativeValues) { error = true; } } } catch (final NumberFormatException e) { error = true; } } if (error) { final Exception e = new Exception( "Cannot set the '" + attributeName + "' property to invalid value: '" + value + "'"); Context.throwAsScriptRuntimeEx(e); } } getDomNodeOrDie().setAttribute(attributeName, value); }
From source file:pcgen.gui2.facade.CharacterFacadeImpl.java
/** * @see pcgen.facade.core.CharacterFacade#addPurchasedEquipment(EquipmentFacade, int, boolean, boolean) */// www .j a v a 2s . c o m @Override public void addPurchasedEquipment(EquipmentFacade equipment, int quantity, boolean customize, boolean free) { if (equipment == null || quantity <= 0) { return; } // int nextOutputIndex = 1; Equipment equipItemToAdjust = (Equipment) equipment; if (customize) { equipItemToAdjust = openCustomizer(equipItemToAdjust); if (equipItemToAdjust == null) { return; } } else { if (equipItemToAdjust.getSafe(ObjectKey.MOD_CONTROL).getModifiersRequired()) { if (!hasBeenAdjusted(equipItemToAdjust)) { delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString("in_igBuyMustCustomizeItemFirst")); //$NON-NLS-1$ return; } } } Equipment updatedItem = theCharacter.getEquipmentNamed(equipItemToAdjust.getName()); if (!free && !canAfford(equipItemToAdjust, quantity, (GearBuySellScheme) gearBuySellSchemeRef.get())) { delegate.showInfoMessage(Constants.APPLICATION_NAME, LanguageBundle .getFormattedString("in_igBuyInsufficientFunds", quantity, equipItemToAdjust.getName())); return; } if (updatedItem != null) { // item is already in inventory; update it final double prevQty = (updatedItem.qty() < 0) ? 0 : updatedItem.qty(); final double newQty = prevQty + quantity; theCharacter.updateEquipmentQty(updatedItem, prevQty, newQty); Float qty = new Float(newQty); updatedItem.setQty(qty); purchasedEquip.setQuantity(equipment, qty.intValue()); } else { // item is not in inventory; add it updatedItem = equipItemToAdjust.clone(); if (updatedItem != null) { // Set the number carried and add it to the character Float qty = new Float(quantity); updatedItem.setQty(qty); theCharacter.addEquipment(updatedItem); } purchasedEquip.addElement(updatedItem, quantity); } // Update the PC and equipment if (!free) { double itemCost = calcItemCost(updatedItem, quantity, (GearBuySellScheme) gearBuySellSchemeRef.get()); theCharacter.adjustGold(itemCost * -1); } theCharacter.setCalcEquipmentList(); theCharacter.setDirty(true); updateWealthFields(); }
From source file:pcgen.gui2.facade.CharacterFacadeImpl.java
/** * @see pcgen.facade.core.CharacterFacade#removePurchasedEquipment(EquipmentFacade, int, boolean) *//* www. ja v a 2 s .c o m*/ @Override public void removePurchasedEquipment(EquipmentFacade equipment, int quantity, boolean free) { if (equipment == null || quantity <= 0) { return; } Equipment equipItemToAdjust = (Equipment) equipment; Equipment updatedItem = theCharacter.getEquipmentNamed(equipItemToAdjust.getName()); double numRemoved = 0; // see if item is already in inventory; update it if (updatedItem != null) { final double prevQty = (updatedItem.qty() < 0) ? 0 : updatedItem.qty(); numRemoved = Math.min(quantity, prevQty); final double newQty = Math.max(prevQty - numRemoved, 0); if (newQty <= 0) { // completely remove item updatedItem.setNumberCarried(new Float(0)); updatedItem.setLocation(EquipmentLocation.NOT_CARRIED); final Equipment eqParent = updatedItem.getParent(); if (eqParent != null) { eqParent.removeChild(theCharacter, updatedItem); } theCharacter.removeEquipment(updatedItem); purchasedEquip.removeElement(updatedItem); } else { // update item count theCharacter.updateEquipmentQty(updatedItem, prevQty, newQty); Float qty = new Float(newQty); updatedItem.setQty(qty); updatedItem.setNumberCarried(qty); purchasedEquip.setQuantity(equipment, qty.intValue()); } theCharacter.updateEquipmentQty(updatedItem, prevQty, newQty); Float qty = new Float(newQty); updatedItem.setQty(qty); updatedItem.setNumberCarried(qty); } // Update the PC and equipment if (!free) { double itemCost = calcItemCost(updatedItem, numRemoved * -1, (GearBuySellScheme) gearBuySellSchemeRef.get()); theCharacter.adjustGold(itemCost * -1); } theCharacter.setCalcEquipmentList(); theCharacter.setDirty(true); updateWealthFields(); }
From source file:pcgen.core.Equipment.java
/** * Add a Weapon to an Equipment Location. * @param num how many pieces to add/*from w w w . ja v a 2 s .c o m*/ * @param eLoc the Location to add the weapon to * @param aPC the PC to quip the weapon on */ public void addWeaponToLocation(Float num, EquipmentLocation eLoc, PlayerCharacter aPC) { Float numEquipped = (eLoc == EquipmentLocation.EQUIPPED_TWO_HANDS) ? 2.0f : num; setNumberEquipped(numEquipped.intValue()); setLocation(eLoc); if (eLoc != EquipmentLocation.EQUIPPED_NEITHER) { setQty(num); setNumberCarried(num); setIsEquipped(true, aPC); } }