use of java.math.BigInteger in project j2objc by google.
the class DatatypeFactory method newXMLGregorianCalendar.
/**
* <p>Constructor of value spaces that a
* <code>java.util.GregorianCalendar</code> instance would need to convert to an
* <code>XMLGregorianCalendar</code> instance.</p>
*
* <p><code>XMLGregorianCalendar eon</code> and
* <code>fractionalSecond</code> are set to <code>null</code></p>
*
* <p>A {@link DatatypeConstants#FIELD_UNDEFINED} value indicates that field is not set.</p>
*
* @param year of <code>XMLGregorianCalendar</code> to be created.
* @param month of <code>XMLGregorianCalendar</code> to be created.
* @param day of <code>XMLGregorianCalendar</code> to be created.
* @param hour of <code>XMLGregorianCalendar</code> to be created.
* @param minute of <code>XMLGregorianCalendar</code> to be created.
* @param second of <code>XMLGregorianCalendar</code> to be created.
* @param millisecond of <code>XMLGregorianCalendar</code> to be created.
* @param timezone of <code>XMLGregorianCalendar</code> to be created.
*
* @return <code>XMLGregorianCalendar</code> created from specified values.
*
* @throws IllegalArgumentException If any individual parameter's value is outside the maximum value constraint for the field
* as determined by the Date/Time Data Mapping table in {@link XMLGregorianCalendar}
* or if the composite values constitute an invalid <code>XMLGregorianCalendar</code> instance
* as determined by {@link XMLGregorianCalendar#isValid()}.
*/
public XMLGregorianCalendar newXMLGregorianCalendar(final int year, final int month, final int day, final int hour, final int minute, final int second, final int millisecond, final int timezone) {
// year may be undefined
BigInteger realYear = (year != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) year) : null;
// millisecond may be undefined
// millisecond must be >= 0 millisecond <= 1000
// undefined value
BigDecimal realMillisecond = null;
if (millisecond != DatatypeConstants.FIELD_UNDEFINED) {
if (millisecond < 0 || millisecond > 1000) {
throw new IllegalArgumentException("javax.xml.datatype.DatatypeFactory#newXMLGregorianCalendar(" + "int year, int month, int day, int hour, int minute, int second, int millisecond, int timezone)" + "with invalid millisecond: " + millisecond);
}
realMillisecond = BigDecimal.valueOf((long) millisecond, 3);
}
return newXMLGregorianCalendar(realYear, month, day, hour, minute, second, realMillisecond, timezone);
}
use of java.math.BigInteger in project j2objc by google.
the class Duration method toString.
/**
* <p>Returns a <code>String</code> representation of this <code>Duration</code> <code>Object</code>.</p>
*
* <p>The result is formatted according to the XML Schema 1.0 specification and can be always parsed back later into the
* equivalent <code>Duration</code> <code>Object</code> by {@link DatatypeFactory#newDuration(String lexicalRepresentation)}.</p>
*
* <p>Formally, the following holds for any <code>Duration</code>
* <code>Object</code> x:</p>
* <pre>
* new Duration(x.toString()).equals(x)
* </pre>
*
* @return A non-<code>null</code> valid <code>String</code> representation of this <code>Duration</code>.
*/
public String toString() {
StringBuilder buf = new StringBuilder();
if (getSign() < 0) {
buf.append('-');
}
buf.append('P');
BigInteger years = (BigInteger) getField(DatatypeConstants.YEARS);
if (years != null) {
buf.append(years).append('Y');
}
BigInteger months = (BigInteger) getField(DatatypeConstants.MONTHS);
if (months != null) {
buf.append(months).append('M');
}
BigInteger days = (BigInteger) getField(DatatypeConstants.DAYS);
if (days != null) {
buf.append(days).append('D');
}
BigInteger hours = (BigInteger) getField(DatatypeConstants.HOURS);
BigInteger minutes = (BigInteger) getField(DatatypeConstants.MINUTES);
BigDecimal seconds = (BigDecimal) getField(DatatypeConstants.SECONDS);
if (hours != null || minutes != null || seconds != null) {
buf.append('T');
if (hours != null) {
buf.append(hours).append('H');
}
if (minutes != null) {
buf.append(minutes).append('M');
}
if (seconds != null) {
buf.append(toString(seconds)).append('S');
}
}
return buf.toString();
}
use of java.math.BigInteger in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalConversionException.
/**
* java.util.Formatter#format(String, Object...) for exceptions in
* Float/Double/BigDecimal conversion type 'e', 'E', 'g', 'G', 'f', 'a', 'A'
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalConversionException() {
Formatter f = null;
final char[] conversions = { 'e', 'E', 'g', 'G', 'f', 'a', 'A' };
final Object[] illArgs = { false, (byte) 1, (short) 2, 3, (long) 4, new BigInteger("5"), new Character('c'), new Object(), new Date() };
for (int i = 0; i < illArgs.length; i++) {
for (int j = 0; j < conversions.length; j++) {
try {
f = new Formatter(Locale.UK);
f.format("%" + conversions[j], illArgs[i]);
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
}
}
try {
f = new Formatter(Locale.UK);
f.format("%a", new BigDecimal(1));
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
try {
f = new Formatter(Locale.UK);
f.format("%A", new BigDecimal(1));
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
final String[] flagsConversionMismatches = { "%,e", "%,E", "%#g", "%#G", "%,a", "%,A", "%(a", "%(A" };
for (int i = 0; i < flagsConversionMismatches.length; i++) {
try {
f = new Formatter(Locale.CHINA);
f.format(flagsConversionMismatches[i], new BigDecimal(1));
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
try {
f = new Formatter(Locale.JAPAN);
f.format(flagsConversionMismatches[i], (BigDecimal) null);
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
}
final String[] missingFormatWidths = { "%-0e", "%0e", "%-e", "%-0E", "%0E", "%-E", "%-0g", "%0g", "%-g", "%-0G", "%0G", "%-G", "%-0f", "%0f", "%-f", "%-0a", "%0a", "%-a", "%-0A", "%0A", "%-A" };
for (int i = 0; i < missingFormatWidths.length; i++) {
try {
f = new Formatter(Locale.KOREA);
f.format(missingFormatWidths[i], 1f);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
try {
f = new Formatter(Locale.KOREA);
f.format(missingFormatWidths[i], (Float) null);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
}
final String[] illFlags = { "%+ e", "%+ E", "%+ g", "%+ G", "%+ f", "%+ a", "%+ A", "%-03e", "%-03E", "%-03g", "%-03G", "%-03f", "%-03a", "%-03A" };
for (int i = 0; i < illFlags.length; i++) {
try {
f = new Formatter(Locale.CANADA);
f.format(illFlags[i], 1.23d);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f = new Formatter(Locale.CANADA);
f.format(illFlags[i], (Double) null);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
}
f = new Formatter(Locale.US);
try {
f.format("%F", 1);
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
}
use of java.math.BigInteger in project binnavi by google.
the class InterpreterTest method testAdd2.
@Test
public void testAdd2() throws InterpreterException {
final ReilInterpreter interpreter = new ReilInterpreter(Endianness.LITTLE_ENDIAN, new CpuPolicyX86(), new EmptyInterpreterPolicy());
final HashMap<BigInteger, List<ReilInstruction>> instructions = new HashMap<BigInteger, List<ReilInstruction>>();
instructions.put(BigInteger.ZERO, Lists.newArrayList(ReilHelpers.createAdd(0, OperandSize.DWORD, "2147483648", OperandSize.DWORD, "4294967295", OperandSize.QWORD, "t0")));
interpreter.interpret(instructions, BigInteger.ZERO);
assertEquals(BigInteger.valueOf(0x17FFFFFFFL), interpreter.getVariableValue("t0"));
}
use of java.math.BigInteger in project binnavi by google.
the class LoopeTranslatorTest method testSimple.
@Test
public void testSimple() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(3), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ecx", BigInteger.valueOf(5), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "eax"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1);
final IInstruction instruction = new MockInstruction("dec", operands);
final ArrayList<ReilInstruction> instructionsDec = new ArrayList<ReilInstruction>();
decTranslator.translate(environment, instruction, instructionsDec);
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "256"));
final MockInstruction instruction2 = new MockInstruction("loope", Lists.newArrayList(operandTree2));
instruction2.address = new CAddress(0x101);
translator.translate(environment, instruction2, instructions);
final HashMap<BigInteger, List<ReilInstruction>> mapping = new HashMap<BigInteger, List<ReilInstruction>>();
mapping.put(BigInteger.valueOf(instructions.get(0).getAddress().toLong()), instructions);
mapping.put(BigInteger.valueOf(instructionsDec.get(0).getAddress().toLong()), instructionsDec);
interpreter.interpret(mapping, BigInteger.valueOf(0x100));
assertEquals(6, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.valueOf(2), interpreter.getVariableValue("eax"));
assertEquals(BigInteger.valueOf(4), interpreter.getVariableValue("ecx"));
assertEquals(BigInteger.ZERO, interpreter.getVariableValue("ZF"));
assertEquals(BigInteger.ZERO, interpreter.getVariableValue("SF"));
assertEquals(BigInteger.ZERO, interpreter.getVariableValue("OF"));
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Aggregations