/** * Copies the contents of this {@code AttributeSource} to the given target {@code AttributeSource}. * The given instance has to provide all {@link Attribute}s this instance contains. * The actual attribute implementations must be identical in both {@code AttributeSource} instances; * ideally both AttributeSource instances should use the same {@link AttributeFactory}. * You can use this method as a replacement for {@link #restoreState}, if you use * {@link #cloneAttributes} instead of {@link #captureState}. */ public final void copyTo(AttributeSource target) { for (State state = getCurrentState(); state != null; state = state.next) { final AttributeImpl targetImpl = target.attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("This AttributeSource contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in the target"); } state.attribute.copyTo(targetImpl); } }
/** * Restores this state by copying the values of all attribute implementations * that this state contains into the attributes implementations of the targetStream. * The targetStream must contain a corresponding instance for each argument * contained in this state (e.g. it is not possible to restore the state of * an AttributeSource containing a TermAttribute into a AttributeSource using * a Token instance as implementation). * <p> * Note that this method does not affect attributes of the targetStream * that are not contained in this state. In other words, if for example * the targetStream contains an OffsetAttribute, but this state doesn't, then * the value of the OffsetAttribute remains unchanged. It might be desirable to * reset its value to the default, in which case the caller should first * call {@link TokenStream#clearAttributes()} on the targetStream. */ public final void restoreState(State state) { if (state == null) return; do { AttributeImpl targetImpl = attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("State contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in in this AttributeSource"); } state.attribute.copyTo(targetImpl); state = state.next; } while (state != null); }
/** * Restores this state by copying the values of all attribute implementations * that this state contains into the attributes implementations of the targetStream. * The targetStream must contain a corresponding instance for each argument * contained in this state (e.g. it is not possible to restore the state of * an AttributeSource containing a TermAttribute into a AttributeSource using * a Token instance as implementation). * <p> * Note that this method does not affect attributes of the targetStream * that are not contained in this state. In other words, if for example * the targetStream contains an OffsetAttribute, but this state doesn't, then * the value of the OffsetAttribute remains unchanged. It might be desirable to * reset its value to the default, in which case the caller should first * call {@link TokenStream#clearAttributes()} on the targetStream. */ public final void restoreState(State state) { if (state == null) return; do { AttributeImpl targetImpl = attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("State contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in in this AttributeSource"); } state.attribute.copyTo(targetImpl); state = state.next; } while (state != null); }
/** * Restores this state by copying the values of all attribute implementations * that this state contains into the attributes implementations of the targetStream. * The targetStream must contain a corresponding instance for each argument * contained in this state (e.g. it is not possible to restore the state of * an AttributeSource containing a TermAttribute into a AttributeSource using * a Token instance as implementation). * <p> * Note that this method does not affect attributes of the targetStream * that are not contained in this state. In other words, if for example * the targetStream contains an OffsetAttribute, but this state doesn't, then * the value of the OffsetAttribute remains unchanged. It might be desirable to * reset its value to the default, in which case the caller should first * call {@link TokenStream#clearAttributes()} on the targetStream. */ public final void restoreState(State state) { if (state == null) return; do { AttributeImpl targetImpl = attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("State contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in in this AttributeSource"); } state.attribute.copyTo(targetImpl); state = state.next; } while (state != null); }
/** * Copies the contents of this {@code AttributeSource} to the given target {@code AttributeSource}. * The given instance has to provide all {@link Attribute}s this instance contains. * The actual attribute implementations must be identical in both {@code AttributeSource} instances; * ideally both AttributeSource instances should use the same {@link AttributeFactory}. * You can use this method as a replacement for {@link #restoreState}, if you use * {@link #cloneAttributes} instead of {@link #captureState}. */ public final void copyTo(AttributeSource target) { for (State state = getCurrentState(); state != null; state = state.next) { final AttributeImpl targetImpl = target.attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("This AttributeSource contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in the target"); } state.attribute.copyTo(targetImpl); } }
/** * Restores this state by copying the values of all attribute implementations * that this state contains into the attributes implementations of the targetStream. * The targetStream must contain a corresponding instance for each argument * contained in this state (e.g. it is not possible to restore the state of * an AttributeSource containing a TermAttribute into a AttributeSource using * a Token instance as implementation). * <p> * Note that this method does not affect attributes of the targetStream * that are not contained in this state. In other words, if for example * the targetStream contains an OffsetAttribute, but this state doesn't, then * the value of the OffsetAttribute remains unchanged. It might be desirable to * reset its value to the default, in which case the caller should first * call {@link TokenStream#clearAttributes()} on the targetStream. */ public final void restoreState(State state) { if (state == null) return; do { AttributeImpl targetImpl = attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("State contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in in this AttributeSource"); } state.attribute.copyTo(targetImpl); state = state.next; } while (state != null); }
/** * Copies the contents of this {@code AttributeSource} to the given target {@code AttributeSource}. * The given instance has to provide all {@link Attribute}s this instance contains. * The actual attribute implementations must be identical in both {@code AttributeSource} instances; * ideally both AttributeSource instances should use the same {@link AttributeFactory}. * You can use this method as a replacement for {@link #restoreState}, if you use * {@link #cloneAttributes} instead of {@link #captureState}. */ public final void copyTo(AttributeSource target) { for (State state = getCurrentState(); state != null; state = state.next) { final AttributeImpl targetImpl = target.attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("This AttributeSource contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in the target"); } state.attribute.copyTo(targetImpl); } }
/** * Copies the contents of this {@code AttributeSource} to the given target {@code AttributeSource}. * The given instance has to provide all {@link Attribute}s this instance contains. * The actual attribute implementations must be identical in both {@code AttributeSource} instances; * ideally both AttributeSource instances should use the same {@link AttributeFactory}. * You can use this method as a replacement for {@link #restoreState}, if you use * {@link #cloneAttributes} instead of {@link #captureState}. */ public final void copyTo(AttributeSource target) { for (State state = getCurrentState(); state != null; state = state.next) { final AttributeImpl targetImpl = target.attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("This AttributeSource contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in the target"); } state.attribute.copyTo(targetImpl); } }
/** * Restores this state by copying the values of all attribute implementations * that this state contains into the attributes implementations of the targetStream. * The targetStream must contain a corresponding instance for each argument * contained in this state (e.g. it is not possible to restore the state of * an AttributeSource containing a TermAttribute into a AttributeSource using * a Token instance as implementation). * <p> * Note that this method does not affect attributes of the targetStream * that are not contained in this state. In other words, if for example * the targetStream contains an OffsetAttribute, but this state doesn't, then * the value of the OffsetAttribute remains unchanged. It might be desirable to * reset its value to the default, in which case the caller should first * call {@link TokenStream#clearAttributes()} on the targetStream. */ public final void restoreState(State state) { if (state == null) return; do { AttributeImpl targetImpl = attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("State contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in in this AttributeSource"); } state.attribute.copyTo(targetImpl); state = state.next; } while (state != null); }
/** * Copies the contents of this {@code AttributeSource} to the given target {@code AttributeSource}. * The given instance has to provide all {@link Attribute}s this instance contains. * The actual attribute implementations must be identical in both {@code AttributeSource} instances; * ideally both AttributeSource instances should use the same {@link AttributeFactory}. * You can use this method as a replacement for {@link #restoreState}, if you use * {@link #cloneAttributes} instead of {@link #captureState}. */ public final void copyTo(AttributeSource target) { for (State state = getCurrentState(); state != null; state = state.next) { final AttributeImpl targetImpl = target.attributeImpls.get(state.attribute.getClass()); if (targetImpl == null) { throw new IllegalArgumentException("This AttributeSource contains AttributeImpl of type " + state.attribute.getClass().getName() + " that is not in the target"); } state.attribute.copyTo(targetImpl); } }