net.automatalib.words.Word.iterator()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中net.automatalib.words.Word.iterator()方法的一些代码示例,展示了Word.iterator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Word.iterator()方法的具体详情如下:
包路径:net.automatalib.words.Word
类名称:Word
方法名:iterator

Word.iterator介绍

暂无

代码示例

代码示例来源:origin: net.automatalib/automata-core

@Override
public java.util.Iterator<I> iterator() {
  return new Iterator<>(word.iterator(), letter);
}

代码示例来源:origin: net.automatalib/automata-incremental

@Override
public boolean hasDefinitiveInformation(Word<? extends I> word) {
  Node<I, O> curr = root;
  Iterator<? extends I> symIt = word.iterator();
  while (symIt.hasNext() && curr != null) {
    int symIdx = inputAlphabet.getSymbolIndex(symIt.next());
    curr = curr.getSuccessor(symIdx);
  }
  return (curr != null);
}

代码示例来源:origin: LearnLib/automatalib

@Override
public boolean hasDefinitiveInformation(Word<? extends I> word) {
  Node<I, O> curr = root;
  Iterator<? extends I> symIt = word.iterator();
  while (symIt.hasNext() && curr != null) {
    int symIdx = inputAlphabet.getSymbolIndex(symIt.next());
    curr = curr.getSuccessor(symIdx);
  }
  return (curr != null);
}

代码示例来源:origin: net.automatalib/automata-api

@Override
public boolean equals(Object other) {
  if (this == other) {
    return true;
  }
  if (other == null) {
    return false;
  }
  if (!(other instanceof Word)) {
    return false;
  }
  Word<?> otherWord = (Word<?>) other;
  int len = otherWord.length();
  if (len != length()) {
    return false;
  }
  java.util.Iterator<I> thisIt = iterator();
  java.util.Iterator<?> otherIt = otherWord.iterator();
  while (thisIt.hasNext()) {
    I thisSym = thisIt.next();
    Object otherSym = otherIt.next();
    if (!Objects.equals(thisSym, otherSym)) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: net.automatalib/automata-api

@Override
public void print(Appendable a) throws IOException {
  if (isEmpty()) {
    a.append(EMPTY_WORD_REP);
  } else {
    a.append(WORD_DELIM_LEFT);
    java.util.Iterator<? extends I> symIt = iterator();
    assert symIt.hasNext();
    appendSymbol(a, symIt.next());
    while (symIt.hasNext()) {
      a.append(WORD_SYMBOL_SEPARATOR);
      appendSymbol(a, symIt.next());
    }
    a.append(WORD_DELIM_RIGHT);
  }
}

代码示例来源:origin: LearnLib/automatalib

@Override
public void print(Appendable a) throws IOException {
  if (isEmpty()) {
    a.append(EMPTY_WORD_REP);
  } else {
    a.append(WORD_DELIM_LEFT);
    java.util.Iterator<? extends I> symIt = iterator();
    assert symIt.hasNext();
    appendSymbol(a, symIt.next());
    while (symIt.hasNext()) {
      a.append(WORD_SYMBOL_SEPARATOR);
      appendSymbol(a, symIt.next());
    }
    a.append(WORD_DELIM_RIGHT);
  }
}

代码示例来源:origin: net.automatalib/automata-api

@Override
public Spliterator<I> spliterator() {
  return Spliterators.spliterator(iterator(),
                  length(),
                  Spliterator.IMMUTABLE | Spliterator.ORDERED | Spliterator.SUBSIZED);
}

代码示例来源:origin: LearnLib/automatalib

@Override
public boolean equals(Object other) {
  if (this == other) {
    return true;
  }
  if (other == null) {
    return false;
  }
  if (!(other instanceof Word)) {
    return false;
  }
  Word<?> otherWord = (Word<?>) other;
  int len = otherWord.length();
  if (len != length()) {
    return false;
  }
  java.util.Iterator<I> thisIt = iterator();
  java.util.Iterator<?> otherIt = otherWord.iterator();
  while (thisIt.hasNext()) {
    I thisSym = thisIt.next();
    Object otherSym = otherIt.next();
    if (!Objects.equals(thisSym, otherSym)) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: de.learnlib/learnlib-core

private static <S,I,T,O> int doFindMismatch(MealyMachine<S, I, T, O> hypothesis, Word<I> input, Word<O> output) {
  int i = 0;
  S state = hypothesis.getInitialState();
  
  Iterator<I> inIt = input.iterator();
  Iterator<O> outIt = output.iterator();
  
  while (inIt.hasNext() && outIt.hasNext()) {
    T trans = hypothesis.getTransition(state, inIt.next());
    O ceOut = outIt.next();
    O transOut = hypothesis.getTransitionOutput(trans);
    if (!Objects.equals(transOut, ceOut)) {
      return i;
    }
    state = hypothesis.getSuccessor(trans);
    i++;
  }
  
  return NO_MISMATCH;
}
public static <O> int findMismatch(Word<O> out1, Word<O> out2) {

代码示例来源:origin: de.learnlib/learnlib-util

private static <S, I, T, O> int doFindMismatch(MealyMachine<S, I, T, O> hypothesis, Word<I> input, Word<O> output) {
  int i = 0;
  S state = hypothesis.getInitialState();
  Iterator<I> inIt = input.iterator();
  Iterator<O> outIt = output.iterator();
  while (inIt.hasNext() && outIt.hasNext()) {
    T trans = hypothesis.getTransition(state, inIt.next());
    O ceOut = outIt.next();
    O transOut = hypothesis.getTransitionOutput(trans);
    if (!Objects.equals(transOut, ceOut)) {
      return i;
    }
    state = hypothesis.getSuccessor(trans);
    i++;
  }
  return NO_MISMATCH;
}

代码示例来源:origin: LearnLib/automatalib

@Override
public Spliterator<I> spliterator() {
  return Spliterators.spliterator(iterator(),
                  length(),
                  Spliterator.IMMUTABLE | Spliterator.ORDERED | Spliterator.SUBSIZED);
}

代码示例来源:origin: de.learnlib/learnlib-adt

private static <S, I, O> ADTNode<S, I, O> splitIntoNewADS(final ADTNode<S, I, O> nodeToSplit,
                             final Word<I> distinguishingSuffix,
                             final Word<O> oldOutput,
                             final Word<O> newOutput) {
  final Iterator<I> suffixIter = distinguishingSuffix.iterator();
  // Replace old final state
  final ADTNode<S, I, O> parent = nodeToSplit.getParent();
  final ADTNode<S, I, O> newADS = new ADTSymbolNode<>(null, suffixIter.next());
  if (parent != null) { // if parent == null, we split the initial node
    boolean foundSuccessor = false;
    for (Map.Entry<O, ADTNode<S, I, O>> entry : parent.getChildren().entrySet()) {
      if (entry.getValue().equals(nodeToSplit)) {
        final ADTNode<S, I, O> reset = new ADTResetNode<>(newADS);
        reset.setParent(parent);
        parent.getChildren().put(entry.getKey(), reset);
        newADS.setParent(reset);
        foundSuccessor = true;
        break;
      }
    }
    if (!foundSuccessor) {
      throw new IllegalStateException();
    }
  }
  return finalizeSplit(nodeToSplit, newADS, suffixIter, oldOutput.iterator(), newOutput.iterator());
}

代码示例来源:origin: de.learnlib/learnlib-adt

public static <S, I, O> ADTNode<S, I, O> splitParent(final ADTNode<S, I, O> nodeToSplit,
                             final Word<I> distinguishingSuffix,
                             final Word<O> oldOutput,
                             final Word<O> newOutput) {

    final ADTNode<S, I, O> previousADS = ADTUtil.getStartOfADS(nodeToSplit);

    final Iterator<I> suffixIter = distinguishingSuffix.iterator();
    final Iterator<O> oldIter = oldOutput.iterator();
    final Iterator<O> newIter = newOutput.iterator();
    ADTNode<S, I, O> adsIter = previousADS;
    O newSuffixOutput = null;

    while (!ADTUtil.isLeafNode(adsIter)) {

      // Forward other iterators
      suffixIter.next();
      newIter.next();
      newSuffixOutput = oldIter.next();

      adsIter = adsIter.getChildren().get(newSuffixOutput);
    }

    final ADTNode<S, I, O> continuedADS = new ADTSymbolNode<>(adsIter.getParent(), suffixIter.next());

    adsIter.getParent().getChildren().put(newSuffixOutput, continuedADS);

    return finalizeSplit(nodeToSplit, continuedADS, suffixIter, oldIter, newIter);
  }
}

代码示例来源:origin: de.learnlib/learnlib-adt

private FastMealyState<O> addTrace(final FastMealyState<O> state, final Word<I> input, final Word<O> output) {
  assert input.length() == output.length() : "Traces differ in length";
  final Iterator<I> inputIter = input.iterator();
  final Iterator<O> outputIter = output.iterator();
  FastMealyState<O> iter = state;
  while (inputIter.hasNext()) {
    final I nextInput = inputIter.next();
    final O nextOuput = outputIter.next();
    final FastMealyState<O> nextState;
    if (this.observationTree.getTransition(iter, nextInput) == null) {
      nextState = this.observationTree.addState();
      this.observationTree.addTransition(iter, nextInput, nextState, nextOuput);
    } else {
      assert this.observationTree.getOutput(iter, nextInput).equals(nextOuput) : "Inconsistent observations";
      nextState = this.observationTree.getSuccessor(iter, nextInput);
    }
    iter = nextState;
  }
  return iter;
}

代码示例来源:origin: de.learnlib/learnlib-adt

final Iterator<I> inputIterator = input.iterator();
final Iterator<O> outputIterator = output.iterator();

代码示例来源:origin: de.learnlib/learnlib-adt

public static <S, I, O> Pair<ADTNode<S, I, O>, ADTNode<S, I, O>> buildADSFromTrace(final MealyMachine<S, I, ?, O> automaton,
                                          final Word<I> trace,
                                          final S state) {
  final Iterator<I> sequenceIter = trace.iterator();
  final I input = sequenceIter.next();
  final ADTNode<S, I, O> head = new ADTSymbolNode<>(null, input);
  ADTNode<S, I, O> tempADS = head;
  I tempInput = input;
  S tempState = state;
  while (sequenceIter.hasNext()) {
    final I nextInput = sequenceIter.next();
    final ADTNode<S, I, O> nextNode = new ADTSymbolNode<>(tempADS, nextInput);
    final O oldOutput = automaton.getOutput(tempState, tempInput);
    tempADS.getChildren().put(oldOutput, nextNode);
    tempADS = nextNode;
    tempState = automaton.getSuccessor(tempState, tempInput);
    tempInput = nextInput;
  }
  return new Pair<>(head, tempADS);
}

代码示例来源:origin: net.automatalib/automata-util

public static <S, I, O> Pair<ADSNode<S, I, O>, ADSNode<S, I, O>> buildFromTrace(final MealyMachine<S, I, ?, O> automaton,
                                        final Word<I> trace,
                                        final S state) {
  final Iterator<I> sequenceIter = trace.iterator();
  final I input = sequenceIter.next();
  final ADSNode<S, I, O> head = new ADSSymbolNode<>(null, input);
  ADSNode<S, I, O> tempADS = head;
  I tempInput = input;
  S tempState = state;
  while (sequenceIter.hasNext()) {
    final I nextInput = sequenceIter.next();
    final ADSNode<S, I, O> nextNode = new ADSSymbolNode<>(tempADS, nextInput);
    final O oldOutput = automaton.getOutput(tempState, tempInput);
    tempADS.getChildren().put(oldOutput, nextNode);
    tempADS = nextNode;
    tempState = automaton.getSuccessor(tempState, tempInput);
    tempInput = nextInput;
  }
  return new Pair<>(head, tempADS);
}

代码示例来源:origin: LearnLib/automatalib

public static <S, I, O> Pair<ADSNode<S, I, O>, ADSNode<S, I, O>> buildFromTrace(final MealyMachine<S, I, ?, O> automaton,
                                        final Word<I> trace,
                                        final S state) {
  final Iterator<I> sequenceIter = trace.iterator();
  final I input = sequenceIter.next();
  final ADSNode<S, I, O> head = new ADSSymbolNode<>(null, input);
  ADSNode<S, I, O> tempADS = head;
  I tempInput = input;
  S tempState = state;
  while (sequenceIter.hasNext()) {
    final I nextInput = sequenceIter.next();
    final ADSNode<S, I, O> nextNode = new ADSSymbolNode<>(tempADS, nextInput);
    final O oldOutput = automaton.getOutput(tempState, tempInput);
    tempADS.getChildren().put(oldOutput, nextNode);
    tempADS = nextNode;
    tempState = automaton.getSuccessor(tempState, tempInput);
    tempInput = nextInput;
  }
  return Pair.of(head, tempADS);
}

代码示例来源:origin: net.automatalib/automata-incremental

@Override
public void insert(Word<? extends I> input, Word<? extends O> outputWord) throws ConflictException {
  Node<I, O> curr = root;
  Iterator<? extends O> outputIt = outputWord.iterator();
  for (I sym : input) {
    int symIdx = inputAlphabet.getSymbolIndex(sym);
    O out = outputIt.next();
    Edge<I, O> edge = curr.getEdge(symIdx);
    if (edge == null) {
      curr = insertNode(curr, symIdx, out);
    } else {
      if (!Objects.equal(out, edge.getOutput())) {
        throw new ConflictException();
      }
      curr = curr.getSuccessor(symIdx);
    }
  }
}

代码示例来源:origin: LearnLib/automatalib

@Override
public void insert(Word<? extends I> input, Word<? extends O> outputWord) throws ConflictException {
  Node<I, O> curr = root;
  Iterator<? extends O> outputIt = outputWord.iterator();
  for (I sym : input) {
    int symIdx = inputAlphabet.getSymbolIndex(sym);
    O out = outputIt.next();
    Edge<I, O> edge = curr.getEdge(symIdx);
    if (edge == null) {
      curr = insertNode(curr, symIdx, out);
    } else {
      if (!Objects.equal(out, edge.getOutput())) {
        throw new ConflictException();
      }
      curr = curr.getSuccessor(symIdx);
    }
  }
}

相关文章