All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brainslug.flow.execution.TokenList Maven / Gradle / Ivy

package brainslug.flow.execution;

import brainslug.flow.model.Identifier;

import java.util.*;

public class TokenList {

  List tokenList;

  public TokenList(List tokenList) {
    this.tokenList = tokenList;
  }

  public List getTokens() {
    return tokenList;
  }

  public Map> groupedBySourceNode() {
    return sourceNodeMap(tokenList);
  }

  protected Map> sourceNodeMap(List instanceTokens) {
    Map> sourceNodeMap = new HashMap>();
    for (Token token : instanceTokens) {
      if (token.getSourceNode().isPresent()) {
        getOrCreateTokenList(sourceNodeMap, token.getSourceNode().get())
          .add(token);
      }
    }
    return Collections.unmodifiableMap(sourceNodeMap);
  }

  protected List getOrCreateTokenList(Map> sourceNodeMap, Identifier sourceNodeId) {
    if (sourceNodeMap.get(sourceNodeId) == null) {
      sourceNodeMap.put(sourceNodeId, new ArrayList());
    }
    return sourceNodeMap.get(sourceNodeId);
  }

  public Iterator getIterator() {
    return tokenList.iterator();
  }

  public void add(Token token) {
    tokenList.add(token);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy