/** * Get the range object <code>elem</code> maps to. * * @param elem * object from the domain. * * @return the object from the range corresponding to <code>elem</code>. */ @Override default R apply(D elem) { return get(elem); }
/** * Safely retrieves a value from a mapping. If the mapping is <code>null</code> or returns a <code>null</code> * value, the given fallback value is returned. * * @param mapping * the mapping. * @param key * the key. * @param fallback * the fallback value to return if either the mapping or the originally returned value are * <code>null</code>. * * @return the value returned by the specified mapping, or the fallback value. */ public static <D, R> R safeGet(Mapping<? super D, R> mapping, D key, R fallback) { if (mapping == null) { return fallback; } R val = mapping.get(key); if (val == null) { return fallback; } return val; }
@Override public R get(int index) { return mapping.get(list.get(index)); }
/** * Retrieves the block to which a given original state belongs. * * @param origState * the original state. * * @return the corresponding block. */ public Block<S, L> getBlockForState(S origState) { State<S, L> state = stateStorage.get(origState); return state.getBlock(); }
/** * Retrieves the block to which a given original state belongs. * * @param origState * the original state. * * @return the corresponding block. */ public Block<S, L> getBlockForState(S origState) { State<S, L> state = stateStorage.get(origState); return state.getBlock(); }
protected N2 copyNode(N1 node) { NP2 prop = npMapping.get(node); N2 n2 = outGraph.addNode(prop); nodeMapping.put(node, n2); return n2; }
protected E2 copyEdge(N2 src2, E1 edge, N1 tgt1) { EP2 prop = epMapping.get(edge); N2 tgt2 = nodeMapping.get(tgt1); return outGraph.connect(src2, tgt2, prop); }
protected E2 copyEdge(N2 src2, E1 edge, N1 tgt1) { EP2 prop = epMapping.get(edge); N2 tgt2 = nodeMapping.get(tgt1); return outGraph.connect(src2, tgt2, prop); }
protected N2 copyNode(N1 node) { NP2 prop = npMapping.get(node); N2 n2 = outGraph.addNode(prop); nodeMapping.put(node, n2); return n2; }
protected N2 copyEdgeChecked(N2 source, E1 edge, N1 tgt1) { EP2 prop = epMapping.get(edge); N2 tgt2 = nodeMapping.get(tgt1); N2 freshTgt = null; if (tgt2 == null) { tgt2 = copyNode(tgt1); freshTgt = tgt2; } outGraph.connect(source, tgt2, prop); return freshTgt; }
protected N2 copyEdgeChecked(N2 source, E1 edge, N1 tgt1) { EP2 prop = epMapping.get(edge); N2 tgt2 = nodeMapping.get(tgt1); N2 freshTgt = null; if (tgt2 == null) { tgt2 = copyNode(tgt1); freshTgt = tgt2; } outGraph.connect(source, tgt2, prop); return freshTgt; }
private Word<O> truncateOutput(Word<O> output) { if (errorSyms == null) { return output; } int maxLen = output.length() - 1; int i = 0; O repSym = null; while (i < maxLen && repSym == null) { O sym = output.getSymbol(i++); repSym = errorSyms.get(sym); } if (repSym == null) { return output; } WordBuilder<O> wb = new WordBuilder<>(maxLen + 1); wb.append(output.prefix(i)); wb.repeatAppend(1 + maxLen - i, repSym); return wb.toWord(); }
private void postProcess(MasterQuery<I, O> master) { Word<I> word = master.getSuffix(); Word<O> answer = master.getAnswer(); if (errorSyms == null) { incMealy.insert(word, answer); return; } int answLen = answer.length(); int i = 0; while (i < answLen) { O sym = answer.getSymbol(i++); if (errorSyms.get(sym) != null) { break; } } if (i == answLen) { incMealy.insert(word, answer); } else { incMealy.insert(word.prefix(i), answer.prefix(i)); } }
private MasterQuery<I, O> createMasterQuery(Word<I> word) { WordBuilder<O> wb = new WordBuilder<>(); if (incMealy.lookup(word, wb)) { return new MasterQuery<>(word, wb.toWord()); } if (errorSyms == null) { return new MasterQuery<>(word); } int wbSize = wb.size(); if (wbSize == 0) { return new MasterQuery<>(word, errorSyms); } O repSym = errorSyms.get(wb.getSymbol(wbSize - 1)); if (repSym == null) { return new MasterQuery<>(word, errorSyms); } wb.repeatAppend(word.length() - wbSize, repSym); return new MasterQuery<>(word, wb.toWord()); }