当前位置: 首页>>代码示例>>Java>>正文


Java Numbers类代码示例

本文整理汇总了Java中com.trollworks.toolkit.utility.text.Numbers的典型用法代码示例。如果您正苦于以下问题:Java Numbers类的具体用法?Java Numbers怎么用?Java Numbers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Numbers类属于com.trollworks.toolkit.utility.text包,在下文中一共展示了Numbers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: valueToString

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
@Override
public String valueToString(Object value) throws ParseException {
    if (value instanceof Integer) {
        int percentage = ((Integer) value).intValue();
        if (percentage != 0) {
            return Numbers.format(percentage) + "%"; //$NON-NLS-1$
        }
        return ""; //$NON-NLS-1$
    } else if (value instanceof WeightValue) {
        WeightValue weight = (WeightValue) value;
        if (weight.getValue() == 0) {
            return ""; //$NON-NLS-1$
        }
        return weight.toString();
    }
    return ""; //$NON-NLS-1$
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:18,代码来源:WeightReductionFormatter.java

示例2: getCostDescription

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
/** @return The formatted cost. */
public String getCostDescription() {
    StringBuilder builder = new StringBuilder();
    CostType costType = getCostType();

    switch (costType) {
        case PERCENTAGE:
        case POINTS:
        default:
            builder.append(Numbers.formatWithForcedSign(getCostModifier()));
            if (costType == CostType.PERCENTAGE) {
                builder.append('%');
            }
            String desc = mAffects.getShortTitle();
            if (desc.length() > 0) {
                builder.append(' ');
                builder.append(desc);
            }
            break;
        case MULTIPLIER:
            builder.append('x');
            builder.append(Numbers.format(getCostMultiplier()));
            break;
    }
    return builder.toString();
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:27,代码来源:Modifier.java

示例3: updateCostModifier

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
private void updateCostModifier() {
    boolean enabled = true;

    if (hasLevels()) {
        mCostModifierField.setText(Numbers.formatWithForcedSign(getCost() * getLevels()) + "%"); //$NON-NLS-1$
    } else {
        CostType costType = getCostType();
        switch (costType) {
            case PERCENTAGE:
            default:
                mCostModifierField.setText(Numbers.formatWithForcedSign(getCost()) + costType);
                break;
            case POINTS:
                mCostModifierField.setText(Numbers.formatWithForcedSign(getCost()));
                break;
            case MULTIPLIER:
                mCostModifierField.setText(costType + Numbers.format(getCostMultiplier()));
                mAffects.setSelectedItem(Affects.TOTAL);
                enabled = false;
                break;
        }
    }
    mAffects.setEnabled(mIsEditable && enabled);
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:25,代码来源:ModifierEditor.java

示例4: getMargins

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
private static double[] getMargins(CmdLine cmdLine) {
    if (cmdLine.isOptionUsed(GCS.MARGIN_OPTION)) {
        StringTokenizer tokenizer = new StringTokenizer(cmdLine.getOptionArgument(GCS.MARGIN_OPTION), ":"); //$NON-NLS-1$
        double[] values = new double[4];
        int index = 0;

        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();

            if (index < 4) {
                values[index] = Numbers.extractDouble(token, -1.0, true);
                if (values[index] < 0.0) {
                    System.out.println(INVALID_PAPER_MARGINS);
                    return null;
                }
            }
            index++;
        }
        if (index == 4) {
            return values;
        }
        System.out.println(INVALID_PAPER_MARGINS);
    }
    return null;
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:26,代码来源:GCS.java

示例5: writeBestWeaponDefense

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
private void writeBestWeaponDefense(BufferedWriter out, Function<MeleeWeaponStats, String> resolver) throws IOException {
    String best = "-";
    int bestValue = Integer.MIN_VALUE;
    for (WeaponDisplayRow row : new FilteredIterator<>(mSheet.getMeleeWeaponOutline().getModel().getRows(), WeaponDisplayRow.class)) {
        MeleeWeaponStats weapon = (MeleeWeaponStats) row.getWeapon();
        String result = resolver.apply(weapon).trim();
        if (result.length() > 0 && !"No".equals(result)) {
            int value = Numbers.extractInteger(result, 0, false);
            if (value > bestValue) {
                bestValue = value;
                best = result;
            }
        }
    }
    writeEncodedText(out, best);
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:17,代码来源:TextTemplate.java

示例6: DescriptionRandomizer

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
/**
 * Creates a new {@link DescriptionRandomizer}.
 *
 * @param character The {@link GURPSCharacter} to randomize the description of.
 */
public DescriptionRandomizer(GURPSCharacter character) {
    super(new BorderLayout());
    mCharacter = character;
    mCheckBoxes = new JCheckBox[COUNT];
    mFields = new JTextField[COUNT];
    JPanel wrapper = new JPanel(new ColumnLayout(2));
    wrapper.setBorder(new EmptyBorder(10));
    Profile description = mCharacter.getDescription();
    addField(wrapper, DescriptionPanel.GENDER, null, GENDER_INDEX, description.getGender());
    addField(wrapper, DescriptionPanel.AGE, null, AGE_INDEX, Numbers.format(description.getAge()));
    addField(wrapper, DescriptionPanel.BIRTHDAY, null, BIRTHDAY_INDEX, description.getBirthday());
    addField(wrapper, DescriptionPanel.HEIGHT_FIELD, null, HEIGHT_INDEX, description.getHeight().toString());
    addField(wrapper, DescriptionPanel.WEIGHT, null, WEIGHT_INDEX, description.getWeight().toString());
    addField(wrapper, DescriptionPanel.HAIR, DescriptionPanel.HAIR_TOOLTIP, HAIR_INDEX, description.getHair());
    addField(wrapper, DescriptionPanel.EYE_COLOR, DescriptionPanel.EYE_COLOR_TOOLTIP, EYES_INDEX, description.getEyeColor());
    addField(wrapper, DescriptionPanel.SKIN_COLOR, DescriptionPanel.SKIN_COLOR_TOOLTIP, SKIN_INDEX, description.getSkinColor());
    addField(wrapper, DescriptionPanel.HANDEDNESS, DescriptionPanel.HANDEDNESS_TOOLTIP, HAND_INDEX, description.getHandedness());
    add(wrapper, BorderLayout.CENTER);
    mRandomize = new JButton(RANDOMIZE);
    mRandomize.addActionListener(this);
    add(mRandomize, BorderLayout.SOUTH);
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:28,代码来源:DescriptionRandomizer.java

示例7: applyChanges

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
/** Apply the changes. */
public void applyChanges() {
    MultipleUndo edit = new MultipleUndo(UNDO_RANDOMIZE);
    Profile description = mCharacter.getDescription();
    mCharacter.addEdit(edit);
    mCharacter.startNotify();
    description.setGender(mFields[GENDER_INDEX].getText());
    description.setAge(Numbers.extractInteger(mFields[AGE_INDEX].getText(), 18, true));
    description.setBirthday(mFields[BIRTHDAY_INDEX].getText());
    description.setHeight(LengthValue.extract(mFields[HEIGHT_INDEX].getText(), true));
    description.setWeight(WeightValue.extract(mFields[WEIGHT_INDEX].getText(), true));
    description.setHair(mFields[HAIR_INDEX].getText());
    description.setEyeColor(mFields[EYES_INDEX].getText());
    description.setSkinColor(mFields[SKIN_INDEX].getText());
    description.setHandedness(mFields[HAND_INDEX].getText());
    mCharacter.endNotify();
    edit.end();
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:19,代码来源:DescriptionRandomizer.java

示例8: getMinStrengthValue

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
/** @return The minimum ST to use this weapon, or -1 if there is none. */
public int getMinStrengthValue() {
    StringBuilder builder = new StringBuilder();
    int count = mStrength.length();
    boolean started = false;
    for (int i = 0; i < count; i++) {
        char ch = mStrength.charAt(i);
        if (Character.isDigit(ch)) {
            builder.append(ch);
            started = true;
        } else if (started) {
            break;
        }
    }
    return started ? Numbers.extractInteger(builder.toString(), -1, false) : -1;
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:17,代码来源:WeaponStats.java

示例9: extract

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
/**
 * @param buffer The buffer to extract a {@link WeightValue} from.
 * @param localized <code>true</code> if the string might have localized notation within it.
 * @return The result.
 */
public static WeightValue extract(String buffer, boolean localized) {
	WeightUnits units = WeightUnits.LB;
	if (buffer != null) {
		buffer = buffer.trim();
		for (WeightUnits lu : WeightUnits.values()) {
			String text = Enums.toId(lu);
			if (buffer.endsWith(text)) {
				units = lu;
				buffer = buffer.substring(0, buffer.length() - text.length());
				break;
			}
		}
	}
	return new WeightValue(localized ? Numbers.getLocalizedDouble(buffer, 0) : Numbers.getDouble(buffer, 0), units);
}
 
开发者ID:Ayutac,项目名称:toolkit,代码行数:21,代码来源:WeightValue.java

示例10: extractFromResolutionString

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
private static PrinterResolution extractFromResolutionString(String buffer) {
	if (buffer != null && buffer.length() > 0) {
		int sep = buffer.indexOf('x');
		int x;
		int y;

		if (sep != -1 && sep < buffer.length() - 1) {
			x = Numbers.getInteger(buffer.substring(0, sep), 0);
			y = Numbers.getInteger(buffer.substring(sep + 1), 0);
		} else {
			x = Numbers.getInteger(buffer, 0);
			y = x;
		}
		if (x < 1 || y < 1) {
			return null;
		}
		return new PrinterResolution(x, y, 1);
	}
	return null;
}
 
开发者ID:Ayutac,项目名称:toolkit,代码行数:21,代码来源:PrintManager.java

示例11: getAmountAsString

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
/** @return The amount, as a {@link String}. */
public String getAmountAsString() {
    if (mInteger) {
        return Numbers.formatWithForcedSign(getIntegerAmount());
    }
    return Numbers.formatWithForcedSign(mAmount);
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:8,代码来源:LeveledAmount.java

示例12: stringToValue

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
@Override
public Object stringToValue(String text) throws ParseException {
    text = text != null ? text.trim() : ""; //$NON-NLS-1$
    if (text.endsWith("%")) { //$NON-NLS-1$
        return Integer.valueOf(Numbers.extractInteger(text.substring(0, text.length() - 1), 0, true));
    }
    return WeightValue.extract(text, true);
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:9,代码来源:WeightReductionFormatter.java

示例13: load

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
/**
 * Loads a contained weight reduction.
 *
 * @param reader The XML reader to use.
 */
protected void load(XMLReader reader) throws IOException {
    String value = reader.readText().trim();
    if (value.endsWith("%")) { //$NON-NLS-1$
        mValue = Integer.valueOf(Numbers.extractInteger(value.substring(0, value.length() - 1), 0, false));
    } else {
        mValue = WeightValue.extract(value, false);
    }
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:14,代码来源:ContainedWeightReduction.java

示例14: createNumberField

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
@SuppressWarnings("unused")
private JTextField createNumberField(Container labelParent, Container fieldParent, String title, boolean allowSign, int value, String tooltip, int maxDigits) {
    JTextField field = new JTextField(Text.makeFiller(maxDigits, '9') + Text.makeFiller(maxDigits / 3, ',') + (allowSign ? "-" : EMPTY)); //$NON-NLS-1$
    UIUtilities.setOnlySize(field, field.getPreferredSize());
    field.setText(Numbers.format(value));
    field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    field.setEnabled(mIsEditable);
    new NumberFilter(field, false, allowSign, true, maxDigits);
    field.addActionListener(this);
    labelParent.add(new LinkedLabel(title, field));
    fieldParent.add(field);
    return field;
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:14,代码来源:ModifierEditor.java

示例15: costTypeChanged

import com.trollworks.toolkit.utility.text.Numbers; //导入依赖的package包/类
private void costTypeChanged() {
    boolean hasLevels = hasLevels();

    if (hasLevels) {
        mLevelField.setText(Numbers.format(mLastLevel));
    } else {
        mLastLevel = Numbers.extractInteger(mLevelField.getText(), 0, true);
        mLevelField.setText(EMPTY);
    }
    mLevelField.setEnabled(hasLevels);
    updateCostField();
    updateCostModifier();
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:14,代码来源:ModifierEditor.java


注:本文中的com.trollworks.toolkit.utility.text.Numbers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。