/** * Constructs an iterator that selects only elements of the parsed iterator * that are assignable to the parse type * @param it the base iterator * @param type the type all elements of this Iterator need to be assignable to. */ @SuppressWarnings("unchecked") public TypeSafeIterator(Iterator<?> it,Class<T> type){ super((Iterator<Object>)it,new AssignableFormAdapter<T>(),type); }
@Override public A adapt(A value, Class<A> type) { if(filter.isValid(value)){ return value; } else { return null; } }
@Override public final boolean hasNext() { if(hasNext == null){ // only once even with multiple calls next = prepareNext(); hasNext = next != null; } return hasNext; }
public static String value2Regex(String value){ return '^'+escapeRegex(value)+'$'; } /**
/** * Getter for the ID's of the symbols defined as successors of this one. * @return The id's of the symbols defined as successors of this one or an * empty list if there are no successors are defined. */ public final Iterator<String> getSuccessors() { return new ToStringIterator(metadata.get(SUCCESSOR)); }
/** * Creates an instance that iterates over values and returns {@link Text} * instances that confirm to the active languages. If no languages are parsed * or <code>null</code> is parsed as a language, this Iterator also creates * and returns {@link Text} instances for {@link String} values. * @param valueFactory the factory used to create text instances for String values * @param it the iterator * @param languages The active languages or no values to accept all languages */ public TextIterator(ValueFactory valueFactory,Iterator<Object> it,String...languages){ super(it,new TextAdapter(valueFactory, languages),Text.class); } private static class TextAdapter implements Adapter<Object,Text>{
public FilteringIterator(Iterator<T> iterator,Filter<T> filter,Class<T> type) { super(iterator,new FilterAdapter<T>(filter),type); }
protected A prepareNext(){ T check; A converted; while(it.hasNext()){ check = it.next(); converted = adapter.adapt(check,type); if(converted != null){ return converted; } } return null; }
public static String value2Regex(String value){ return '^'+escapeRegex(value)+'$'; } /**
/** * Getter for the ID's of the symbols defined as successors of this one. * @return The id's of the symbols defined as successors of this one or an * empty list if there are no successors are defined. */ public final Iterator<String> getSuccessors() { return new ToStringIterator(metadata.get(SUCCESSOR)); }
/** * Constructs an iterator that selects only elements of the parsed iterator * that are assignable to the parse type * @param it the base iterator * @param type the type all elements of this Iterator need to be assignable to. */ @SuppressWarnings("unchecked") public TypeSafeIterator(Iterator<?> it,Class<T> type){ super((Iterator<Object>)it,new AssignableFormAdapter<T>(),type); }
@Override public A adapt(A value, Class<A> type) { if(filter.isValid(value)){ return value; } else { return null; } }
@Override public final boolean hasNext() { if(hasNext == null){ // only once even with multiple calls next = prepareNext(); hasNext = next != null; } return hasNext; }
/** * Creates an instance that iterates over values and returns {@link Text} * instances that confirm to the active languages. If no languages are parsed * or <code>null</code> is parsed as a language, this Iterator also creates * and returns {@link Text} instances for {@link String} values. * @param valueFactory the factory used to create text instances for String values * @param it the iterator * @param languages The active languages or no values to accept all languages */ public TextIterator(ValueFactory valueFactory,Iterator<Object> it,String...languages){ super(it,new TextAdapter(valueFactory, languages),Text.class); } private static class TextAdapter implements Adapter<Object,Text>{
public FilteringIterator(Iterator<T> iterator,Filter<T> filter,Class<T> type) { super(iterator,new FilterAdapter<T>(filter),type); }
protected A prepareNext(){ T check; A converted; while(it.hasNext()){ check = it.next(); converted = adapter.adapt(check,type); if(converted != null){ return converted; } } return null; }
/** * Creates a regex that matches vales against whole words * ('<code>\b{value}\b</code>) * @param word the word to match * @return the regex to match words * @since 0.12.1 */ public static String word2Regex(String word){ return escapeRegex(word, new StringBuilder("\\b")).append("\\b").toString(); }
/** * Getter for the ID's of the symbols defined as predecessors of this one. * @return The id's of the symbols defined as predecessors of this one or an * empty list if there are no predecessors are defined. */ public final Iterator<String> getPredecessors() { return new ToStringIterator(metadata.get(PREDECESSOR)); }
/** * Creates a regex that matches vales against whole words * ('<code>\b{value}\b</code>) * @param word the word to match * @return the regex to match words * @since 0.12.1 */ public static String word2Regex(String word){ return escapeRegex(word, new StringBuilder("\\b")).append("\\b").toString(); }
/** * Getter for the ID's of the symbols defined as predecessors of this one. * @return The id's of the symbols defined as predecessors of this one or an * empty list if there are no predecessors are defined. */ public final Iterator<String> getPredecessors() { return new ToStringIterator(metadata.get(PREDECESSOR)); }