Code example for LinkedList

Methods: peek, removeFirst

0
 
        public MimeMessageBuilder() { 
        } 
 
        private void expect(Class<?> c) {
            if (!c.isInstance(stack.peek())) {
                throw new IllegalStateException("Internal stack error: " + "Expected '"
                                                + c.getName() + "' found '" + stack.peek().getClass().getName() + "'");
            } 
        } 
 
        public void startMessage() { 
            if (stack.isEmpty()) {
                stack.addFirst(MimeMessage.this);
            } else { 
                expect(Part.class); 
                try { 
                    MimeMessage m = new MimeMessage();
                    ((Part)stack.peek()).setBody(m);
                    stack.addFirst(m);
                } catch (MessagingException me) {
                    throw new Error(me);
                } 
            } 
        } 
 
        public void endMessage() { 
            expect(MimeMessage.class); 
            stack.removeFirst();
        } 
 
        public void startHeader() { 
            expect(Part.class); 
        }