public static boolean withOff(PsiBuilder builder_, int level_, Parser parser, String... modes) { TObjectIntHashMap<String> map = getParsingModes(builder_); TObjectIntHashMap<String> prev = new TObjectIntHashMap<>(); for (String mode : modes) { int p = map.get(mode); if (p > 0) { map.put(mode, 0); prev.put(mode, p); } } boolean result = parser.parse(builder_, level_); prev.forEachEntry((mode, p) -> { map.put(mode, p); return true; }); return result; }
private static boolean withImpl(PsiBuilder builder_, int level_, String mode, boolean onOff, Parser whenOn, Parser whenOff) { TObjectIntHashMap<String> map = getParsingModes(builder_); int prev = map.get(mode); boolean change = ((prev & 1) == 0) == onOff; if (change) map.put(mode, prev << 1 | (onOff ? 1 : 0)); boolean result = (change ? whenOn : whenOff).parse(builder_, level_); if (change) map.put(mode, prev); return result; }
/** * Gets the metadata information for all documents. If the requested * metadata information is not specified, then we return null. * @param name the name of the metadata type. * @return an array of strings with the metadata information, or null of the metadata is not available. */ public String[] getMetaItems(final String name) { if (!metaMap.containsKey(name)) return null; return metadata[metaMap.get(name)]; }
final int termCount = occurrences.size(); final TObjectIntHashMap<String> cache_termids = new TObjectIntHashMap<String>(termCount); occurrences.forEachEntry( new TObjectIntProcedure<String>() { public boolean execute(final String a, final int b) final String[] terms = cache_termids.keys(new String[termCount]); Arrays.sort(terms, new Comparator<String>(){ public int compare(String o1, String o2) { for(String t : terms) termIds[i++] = cache_termids.get(t);
@NotNull private static TObjectIntHashMap<String> getParsingModes(@NotNull PsiBuilder builder_) { TObjectIntHashMap<String> flags = builder_.getUserDataUnprotected(MODES_KEY); if (flags == null) builder_.putUserDataUnprotected(MODES_KEY, flags = new TObjectIntHashMap<>()); return flags; }
private static boolean exitMode(@NotNull PsiBuilder builder_, @SuppressWarnings("UnusedParameters") int level, String mode, boolean safe) { TObjectIntHashMap<String> flags = getParsingModes(builder_); int count = flags.get(mode); if (count == 1) flags.remove(mode); else if (count > 1) flags.put(mode, count - 1); else if (!safe) builder_.error("Could not exit inactive '" + mode + "' mode at offset " + builder_.getCurrentOffset()); return true; }
public static boolean isModeOn(@NotNull PsiBuilder builder_, @SuppressWarnings("UnusedParameters") int level, String mode) { return getParsingModes(builder_).get(mode) > 0; }
/** For when you manually want to set the term for a given term, and you * know that this term and termcodes do NOT exist, then you can use * this method. <b>NB:</b> counter variable above probably needs to be * considered in this method. */ public void setTermCode(final String term, final int termCode) { map.put(term, termCode+1); } }
/** Stores the lexicon tree to a lexicon stream as a sequence of entries. * The binary tree is traversed in order, by called the method * traverseAndStoreToStream. * @param lexiconStream The lexicon output stream to store to. */ public void storeToStream(LexiconOutputStream<String> lexiconStream, TermCodes termCodes) throws IOException { final String[] terms = tfs.keys(new String[0]); Arrays.sort(terms); BasicLexiconEntry le = new BasicLexiconEntry(); for (String t : terms) { le.setTermId(termCodes.getCode(t)); le.setStatistics(nts.get(t), tfs.get(t)); le.setMaxFrequencyInDocuments(maxtfs.get(t)); lexiconStream.writeNextEntry(t, le); } }
public int addFeature(String featureName) { if (_featuresDB._featuresMap.containsKey(featureName)) throw new RuntimeException("Duplicate feature: " + featureName); int feature = _featuresDB._featuresMap.size(); _featuresDB._featuresMap.put(featureName, feature); _featuresDB._featuresRMap.add(featureName); return feature; }
/** * Adds given String to this Alphabet if it has not already been added. It is assigned * a new unique ID equal to the new size of the Alphabet after performing the addition. * @param s String to add */ public void addString(String s) { String ss = s.intern(); if (!reverseIndex.containsKey(ss)) { reverseIndex.put(ss, strings.size()); strings.add(ss); } }
/** * Returns the number of entries in the map. * @return the map's size. */ public int size() { return this._map.size(); }
/** * checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsKey(Object key) { return contains(key); }