Search in sources :

Example 1 with Date

use of org.openmuc.jasn1.compiler.modules.module1.Date in project algorithms-sedgewick-wayne by reneargento.

the class Exercise13 method main.

public static void main(String[] args) {
    Date date = new Date(8, 3, 2016);
    Exercise13 transaction = new Exercise13("Rene", date, 500);
    StdOut.println(transaction);
    StdOut.println("Expected: Rene spent 500.0 on 8/3/2016");
}
Also used : Date(edu.princeton.cs.algs4.Date)

Example 2 with Date

use of org.openmuc.jasn1.compiler.modules.module1.Date in project algorithms-sedgewick-wayne by reneargento.

the class Exercise14 method main.

public static void main(String[] args) {
    Date date = new Date(8, 3, 2016);
    Exercise14 transaction1 = new Exercise14("Rene", date, 500);
    Exercise14 transaction2 = new Exercise14("Rene", date, 500);
    Exercise14 transaction3 = new Exercise14("Argento", date, 600);
    Exercise14 transaction4 = transaction3;
    StdOut.println("Equals 1: " + transaction1.equals(transaction2) + " Expected: true");
    StdOut.println("Equals 2: " + transaction2.equals(transaction1) + " Expected: true");
    StdOut.println("Equals 3: " + transaction1.equals(transaction3) + " Expected: false");
    StdOut.println("Equals 4: " + transaction3.equals(transaction4) + " Expected: true");
}
Also used : Date(edu.princeton.cs.algs4.Date)

Example 3 with Date

use of org.openmuc.jasn1.compiler.modules.module1.Date in project algorithms-sedgewick-wayne by reneargento.

the class Exercise33_RandomTransactions method generateRandomTransactions.

private Exercise21_ComparableTransactions[] generateRandomTransactions(int numberOfObjects) {
    Exercise21_ComparableTransactions[] transactions = new Exercise21_ComparableTransactions[numberOfObjects];
    for (int i = 0; i < numberOfObjects; i++) {
        String who = "Client " + (i + 1);
        int month = StdRandom.uniform(12) + 1;
        int maxDay = month == 2 ? 28 : 30;
        int day = StdRandom.uniform(maxDay) + 1;
        int year = StdRandom.uniform(1900, 2018);
        Date date = new Date(month, day, year);
        double amount = (double) Math.round(StdRandom.uniform(0.0, 1000000.0) * 100) / 100;
        Exercise21_ComparableTransactions transaction = new Exercise21_ComparableTransactions(who, date, amount);
        transactions[i] = transaction;
    }
    return transactions;
}
Also used : Date(edu.princeton.cs.algs4.Date) Exercise21_ComparableTransactions(chapter2.section1.Exercise21_ComparableTransactions)

Example 4 with Date

use of org.openmuc.jasn1.compiler.modules.module1.Date in project jasn1 by openmuc.

the class PersonnelRecord method decode.

public int decode(InputStream is, boolean withTag) throws IOException {
    int codeLength = 0;
    int subCodeLength = 0;
    BerTag berTag = new BerTag();
    if (withTag) {
        codeLength += tag.decodeAndCheck(is);
    }
    BerLength length = new BerLength();
    codeLength += length.decode(is);
    int totalLength = length.val;
    if (totalLength == -1) {
        subCodeLength += berTag.decode(is);
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(Name.tag)) {
            name = new Name();
            subCodeLength += name.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
            title = new BerVisibleString();
            subCodeLength += title.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ.tag)) {
            number = new org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ();
            subCodeLength += number.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
            dateOfHire = new Date();
            subCodeLength += dateOfHire.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
            nameOfSpouse = new Name();
            subCodeLength += nameOfSpouse.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
            children = new Children();
            subCodeLength += children.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
            testBitString = new MyBitString();
            subCodeLength += testBitString.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
            test = new MyInt();
            subCodeLength += test.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        test2 = new TestChoice();
        int choiceDecodeLength = test2.decode(is, berTag);
        if (choiceDecodeLength != 0) {
            subCodeLength += choiceDecodeLength;
            subCodeLength += berTag.decode(is);
        } else {
            test2 = null;
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        test3 = new TestChoice();
        choiceDecodeLength = test3.decode(is, berTag);
        if (choiceDecodeLength != 0) {
            subCodeLength += choiceDecodeLength;
            subCodeLength += berTag.decode(is);
        } else {
            test3 = null;
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) {
            subCodeLength += length.decode(is);
            test4 = new TestChoice();
            choiceDecodeLength = test4.decode(is, null);
            if (choiceDecodeLength != 0) {
                subCodeLength += choiceDecodeLength;
                subCodeLength += berTag.decode(is);
            } else {
                test4 = null;
            }
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) {
            subCodeLength += length.decode(is);
            test5 = new TestChoice();
            choiceDecodeLength = test5.decode(is, null);
            if (choiceDecodeLength != 0) {
                subCodeLength += choiceDecodeLength;
                subCodeLength += berTag.decode(is);
            } else {
                test5 = null;
            }
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 10)) {
            subCodeLength += length.decode(is);
            test6 = new TestChoice();
            choiceDecodeLength = test6.decode(is, null);
            if (choiceDecodeLength != 0) {
                subCodeLength += choiceDecodeLength;
                subCodeLength += berTag.decode(is);
            } else {
                test6 = null;
            }
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        employeeNumberZ = new EmployeeNumberZ();
        choiceDecodeLength = employeeNumberZ.decode(is, berTag);
        if (choiceDecodeLength != 0) {
            subCodeLength += choiceDecodeLength;
            subCodeLength += berTag.decode(is);
        } else {
            employeeNumberZ = null;
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerVisibleString.tag)) {
            code_ = new BerVisibleString();
            subCodeLength += code_.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(TestSequenceOf.tag)) {
            testSequenceOf = new TestSequenceOf();
            subCodeLength += testSequenceOf.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(TestSequenceOf2.tag)) {
            testSequenceOf2 = new TestSequenceOf2();
            subCodeLength += testSequenceOf2.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
            int nextByte = is.read();
            if (nextByte != 0) {
                if (nextByte == -1) {
                    throw new EOFException("Unexpected end of input stream.");
                }
                throw new IOException("Decoded sequence has wrong end of contents octets");
            }
            codeLength += subCodeLength + 1;
            return codeLength;
        }
        if (berTag.equals(BerEmbeddedPdv.tag)) {
            embeddedPdv = new BerEmbeddedPdv();
            subCodeLength += embeddedPdv.decode(is, false);
            subCodeLength += berTag.decode(is);
        }
        int nextByte = is.read();
        if (berTag.tagNumber != 0 || berTag.tagClass != 0 || berTag.primitive != 0 || nextByte != 0) {
            if (nextByte == -1) {
                throw new EOFException("Unexpected end of input stream.");
            }
            throw new IOException("Decoded sequence has wrong end of contents octets");
        }
        codeLength += subCodeLength + 1;
        return codeLength;
    }
    codeLength += totalLength;
    subCodeLength += berTag.decode(is);
    if (berTag.equals(Name.tag)) {
        name = new Name();
        subCodeLength += name.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
        title = new BerVisibleString();
        subCodeLength += title.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ.tag)) {
        number = new org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ();
        subCodeLength += number.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
        dateOfHire = new Date();
        subCodeLength += dateOfHire.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
        nameOfSpouse = new Name();
        subCodeLength += nameOfSpouse.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
        children = new Children();
        subCodeLength += children.decode(is, false);
        subCodeLength += berTag.decode(is);
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
        testBitString = new MyBitString();
        subCodeLength += testBitString.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
        test = new MyInt();
        subCodeLength += test.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    test2 = new TestChoice();
    int choiceDecodeLength = test2.decode(is, berTag);
    if (choiceDecodeLength != 0) {
        subCodeLength += choiceDecodeLength;
        subCodeLength += berTag.decode(is);
    } else {
        test2 = null;
    }
    test3 = new TestChoice();
    subCodeLength += test3.decode(is, berTag);
    subCodeLength += berTag.decode(is);
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) {
        subCodeLength += length.decode(is);
        test4 = new TestChoice();
        subCodeLength += test4.decode(is, null);
        subCodeLength += berTag.decode(is);
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) {
        subCodeLength += length.decode(is);
        test5 = new TestChoice();
        subCodeLength += test5.decode(is, null);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 10)) {
        subCodeLength += length.decode(is);
        test6 = new TestChoice();
        subCodeLength += test6.decode(is, null);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    employeeNumberZ = new EmployeeNumberZ();
    choiceDecodeLength = employeeNumberZ.decode(is, berTag);
    if (choiceDecodeLength != 0) {
        subCodeLength += choiceDecodeLength;
        subCodeLength += berTag.decode(is);
    } else {
        employeeNumberZ = null;
    }
    if (berTag.equals(BerVisibleString.tag)) {
        code_ = new BerVisibleString();
        subCodeLength += code_.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(TestSequenceOf.tag)) {
        testSequenceOf = new TestSequenceOf();
        subCodeLength += testSequenceOf.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(TestSequenceOf2.tag)) {
        testSequenceOf2 = new TestSequenceOf2();
        subCodeLength += testSequenceOf2.decode(is, false);
        subCodeLength += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match the mandatory sequence element tag.");
    }
    if (berTag.equals(BerEmbeddedPdv.tag)) {
        embeddedPdv = new BerEmbeddedPdv();
        subCodeLength += embeddedPdv.decode(is, false);
        if (subCodeLength == totalLength) {
            return codeLength;
        }
    }
    throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
}
Also used : IOException(java.io.IOException) EmployeeNumberZ(org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ) EmployeeNumberZ(org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ) EOFException(java.io.EOFException)

Example 5 with Date

use of org.openmuc.jasn1.compiler.modules.module1.Date in project algorithms-sedgewick-wayne by reneargento.

the class Exercise25_HashCache method main.

public static void main(String[] args) {
    Exercise25_HashCache hashCache = new Exercise25_HashCache();
    Transaction transaction = hashCache.new Transaction("Person 1", new Date(1, 10, 5), 1000);
    StdOut.println(transaction.hashCode() + " Expected: Cache miss");
    StdOut.println(transaction.hashCode() + " Expected: Cache hit");
    StdOut.println(transaction.hashCode() + " Expected: Cache hit");
}
Also used : Date(edu.princeton.cs.algs4.Date)

Aggregations

Date (edu.princeton.cs.algs4.Date)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)3 BerVisibleString (org.openmuc.jasn1.ber.types.string.BerVisibleString)3 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 EmployeeNumberZ (org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ)2 ChildInformation (org.openmuc.jasn1.compiler.x690_ber_example.ChildInformation)2 Date (org.openmuc.jasn1.compiler.x690_ber_example.Date)2 EmployeeNumber (org.openmuc.jasn1.compiler.x690_ber_example.EmployeeNumber)2 Name (org.openmuc.jasn1.compiler.x690_ber_example.Name)2 PersonnelRecord (org.openmuc.jasn1.compiler.x690_ber_example.PersonnelRecord)2 Exercise21_ComparableTransactions (chapter2.section1.Exercise21_ComparableTransactions)1 In (edu.princeton.cs.algs4.In)1 Queue (edu.princeton.cs.algs4.Queue)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 BerEmbeddedPdv (org.openmuc.jasn1.ber.types.BerEmbeddedPdv)1 BerInteger (org.openmuc.jasn1.ber.types.BerInteger)1