Results 1 to 4 of 4
  1. #1
    alpdog14 is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default Stream Tokenizer Iterater Adapter not working

    I have a Stream Tokenizer Iterater Adapter (STIA) class that has a test but it is not passing and was wondering if anyone can help me. I have posted this question on another forum but so far no one has helped. Here is the STIA class:

    Java Code:
    public class StreamTokenizerIteratorAdapter implements Iterator<Token> {
    	
    	StreamTokenizer st;
    	Iterator<Token> stia;
    	
    	public StreamTokenizerIteratorAdapter(final StreamTokenizer source) {
    		if (source == null)
    			throw new IllegalArgumentException("source == null");
    		
    		st = source;
    		Iterator<Token> stia = new StreamTokenizerIteratorAdapter(st);
    
    		
    	}
    
    	@Override
    	public boolean hasNext() {
    		
    		
    		DefaultToken tempToken = new DefaultToken(st.sval, st.lineno());
    		  int token = 0;
    		  while (token != StreamTokenizer.TT_EOF){
    		   tempToken = new DefaultToken(st.sval, st.lineno());
    		  }
    		  if (tempToken != null) return true;
    		  return false;
    	}
    
    	public Token next() {
    		
    		DefaultToken tempToken = new DefaultToken(st.sval, st.lineno());;
    		return tempToken;
    
    	}
    
    	@Override
    	public void remove() {
    		throw new UnsupportedOperationException();
    	}
    }
    This class has a test which is:
    Java Code:
    @Test
    	public void testBuild() throws IOException {
    				
    		TokenIteratorIndexBuilder builder = new TokenIteratorIndexBuilder(index);
    		st = new StreamTokenizer(new StringReader(s7));
    		int token;
    		while ((token = st.nextToken()) != StreamTokenizer.TT_EOF) {
    			if (token == StreamTokenizer.TT_WORD) {
    				Token t = new DefaultToken(st.sval, st.lineno());
    				al.add(t);
    			}
    		}
    	builder.buildFrom(al.iterator()); 
    	assertEquals(s7index, index);
    		
    	}
    The test is suppose to build a Tokenizer Iterater Index Builder with a STIA wrapped in a StreamTokenizer. So after running the test the two failures I get is this line on TokenIteratorIndexBuilder:
    Java Code:
    			throw new IllegalArgumentException("index == null");
    and the other line is on TestSTIA:

    Java Code:
    		TokenIteratorIndexBuilder builder = new TokenIteratorIndexBuilder(index);
    Sorry for all the code I just would like to explain the issue because there are a few different classes, if anyone can help I would be much appreciated.

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    It's not at all clear to me what you're trying to do (and I suspect it's not entirely clear to you either), but the immediate error seems pretty simple.
    Java Code:
    @Test
    	public void testBuild() throws IOException {
    				
    		TokenIteratorIndexBuilder builder = new TokenIteratorIndexBuilder(index);
                    ...
    Where did "index" come from? It wasn't passed in to your method as a parameter, and it wasn't declared within the method. It could be an ivar in your class, but this looks like JUnit code, and I think it's unusual to have ivars in JUnit classes.

    -Gary-

  3. #3
    alpdog14 is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    The STIA test is suppose to create a TIIB, then build the index from a STIA wrapped around a StreamTokenizer,

    I have another test for Stream Tokenizer Iterator Builder (STIB) and creating a index works fine for the test, here is the code for that test:

    Java Code:
    @Test
    	public void testBuild() {
    		Index index = new DefaultIndexImpl();
    		StreamTokenizerIndexBuilder builder = new StreamTokenizerIndexBuilder(index);
    		builder.buildFrom(new StreamTokenizer(new StringReader(s7)));
    		assertEquals(s7index, index);
    	}
    Any help to develop the test for STIA would be much appreciated.

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Well, I don't know your code, but it looks to me that the red line in this test:
    Java Code:
    @Test
    	public void testBuild() {
    		[COLOR="Red"]Index index = new DefaultIndexImpl();[/COLOR]
    		StreamTokenizerIndexBuilder builder = new StreamTokenizerIndexBuilder(index);
    		builder.buildFrom(new StreamTokenizer(new StringReader(s7)));
    		assertEquals(s7index, index);
    	}
    is missing from this test:
    Java Code:
    @Test
    	public void testBuild() throws IOException {
    				
    		TokenIteratorIndexBuilder builder = new TokenIteratorIndexBuilder(index);
    		st = new StreamTokenizer(new StringReader(s7));
    		int token;
    		while ((token = st.nextToken()) != StreamTokenizer.TT_EOF) {
    			if (token == StreamTokenizer.TT_WORD) {
    				Token t = new DefaultToken(st.sval, st.lineno());
    				al.add(t);
    			}
    		}
    	builder.buildFrom(al.iterator()); 
    	assertEquals(s7index, index);
    		
    	}
    -Gary-

Similar Threads

  1. Replies: 5
    Last Post: 08-07-2009, 01:54 PM
  2. JDBC using adapter (and connection handles)
    By Gideonzx in forum Advanced Java
    Replies: 1
    Last Post: 07-28-2009, 07:54 AM
  3. Replies: 2
    Last Post: 03-24-2009, 06:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •