Creates a combined list of Entries using the provided mapping file, and sorts them by
first by priority, then the number of tokens in the regex.

@param mapping The path to a file of mappings
@return a sorted list of Entries
7236
private Map<String, Entry> readEntries(String mapping, boolean ignoreCase) {
		Map<String, Entry> entries = new HashMap<>();

		try {
			// ms, 2010-10-05: try to load the file from the CLASSPATH first
			InputStream is = getClass().getClassLoader().getResourceAsStream(mapping);
			// if not found in the CLASSPATH, load from the file system
			if (is == null) is = new FileInputStream(mapping);
			BufferedReader rd = new BufferedReader(new InputStreamReader(is));

			int lineCount = 0;
			for (String line; (line = rd.readLine()) != null; ) {
				lineCount ++;
				String[] split = line.split("\t");
				if (split.length < 2 || split.length > 4)
					throw new RuntimeException("Provided mapping file is in wrong format");
				if (split[1].trim().equalsIgnoreCase("AS")) System.err.println("ERRRR " + mapping + "|" + line + " at " + lineCount);
				String stringLine = split[1].trim();
				if (ignoreCase) stringLine = stringLine.toLowerCase();
				String[] words = stringLine.split("\\s+");
				String type = split[0].trim();
				Set<String> overwritableTypes = new HashSet<String>();
				overwritableTypes.add(flags.backgroundSymbol);
				overwritableTypes.add(null);
				double priority = 0;
				List<String> tokens = new ArrayList<String>();

				try {
					if (split.length >= 3)
						overwritableTypes.addAll(Arrays.asList(split[2].trim().split(",")));
					if (split.length == 4)
						priority = Double.parseDouble(split[3].trim());

					for (String str : words) {
						tokens.add(str);
					}
				} catch(NumberFormatException e) {
					System.err.println("ERROR: Invalid line " + lineCount + " in regexner file " + mapping + ": \"" + line + "\"!");
					throw e;
				}
				addEntry(words, type, priority, overwritableTypes);
			}
			rd.close();
			is.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return entries;
	}
1061472
public static Map<String, ?> redactValues(Map<String, ?> map) {
        Map<String, Object> result = new LinkedHashMap<String, Object>();
        result.putAll(map);
        for (String key : map.keySet()) {
            Object value = map.get(key);
            if (value == null) {
                result.put(key, value);
             } else if (value instanceof Map) {
                @SuppressWarnings("unchecked")
                Map<String, ?> bare = (Map<String, ?>) value;
                result.put(key, redactValues(bare));
            } else if (value instanceof String && StringUtils.isEmpty(value)){
                result.put(key, "");
            } else {
                result.put(key, "<redacted>");
            }
        }
        return result;
    }
268371
private static List<Parameter> convert(Map<String, Object> map) {
		Set<Entry<String, Object>> entries = map.entrySet();
		List<Parameter> parameters = new ArrayList<>(entries.size());
		for (Entry<String, Object> entry : entries) {
			if (entry.getValue() != null) {
				parameters.add(new Parameter(entry.getKey(), entry.getValue().toString()));
			}
		}
		return parameters;
	}
517819
public static <K, V> LinkedHashMap<K, V> sortByEntry(Map<K, V> map, Comparator<Map.Entry<K, V>> comparator) {
		return sortToMap(map.entrySet(), comparator);
	}
356371
public ListInventoryEntriesResult withEntries(java.util.Collection<java.util.Map<String, String>> entries) {
        setEntries(entries);
        return this;
    }
1315414
public synchronized ArrayList<LinkedHashMap.Entry<K, V>> getMatchingEntries(
      @Nullable Predicate<K> predicate) {
    ArrayList<LinkedHashMap.Entry<K, V>> matchingEntries = new ArrayList<>(mMap.entrySet().size());
    for (LinkedHashMap.Entry<K, V> entry : mMap.entrySet()) {
      if (predicate == null || predicate.apply(entry.getKey())) {
        matchingEntries.add(entry);
      }
    }
    return matchingEntries;
  }
631833
public static Map<String,String> order(Map<String, String> map){
		HashMap<String, String> tempMap = new LinkedHashMap<String, String>();
		List<Map.Entry<String, String>> infoIds = new ArrayList<Map.Entry<String, String>>(	map.entrySet());

		Collections.sort(infoIds, new Comparator<Map.Entry<String, String>>() {
			public int compare(Map.Entry<String, String> o1,Map.Entry<String, String> o2) {
				return (o1.getKey()).toString().compareTo(o2.getKey());
			}
		});

		for (int i = 0; i < infoIds.size(); i++) {
			Map.Entry<String, String> item = infoIds.get(i);
			tempMap.put(item.getKey(), item.getValue());
		}
		return tempMap;
	}
27392
public static <K extends Comparable<K>, V> Stream<Entry<K, V>>
    sortedStream(Map<K, V> map) {
        synchronized (map) {
            return buildEntryStream(map).sorted(comparing(Entry::getKey));
        }
    }
900439
public static Map<String, String> mapStringToMap(String map) {
    String[] m = map.split("[,;]");
    Map<String, String> res = new HashMap<String, String>();
    for (String str : m) {
      int index = str.lastIndexOf('=');
      String key = str.substring(0, index);
      String val = str.substring(index + 1);
      res.put(key.trim(), val.trim());
    }
    return res;
  }
579914
public static <K extends Comparable<K>, V> String toStringSorted(Map<K, V> map) {
    StringBuilder builder = new StringBuilder();
    toStringSorted(map, builder);
    return builder.toString();
  }
690961
public static <K, V> Map<K, V> sort(Map<K, V> map,
            Comparator<K> comparator) {
        TreeMap<K, V> sortedMap = new TreeMap<>(comparator);
        sortedMap.putAll(map);
        return sortedMap;
    }
1043460
@Override
    public Iterable<IMapping> mappings() {
        return new Iterable<IMapping>() {

            @Override
            public Iterator<IMapping> iterator() {
                return new MappingIterator();
            }
        };
    }
279415
public static <K extends Comparable<K>, V> void toStringSorted(Map<K, V> map, StringBuilder builder) {
    builder.append("{");
    List<Entry<K,V>> sortedProperties = Maps.sortedEntries(map);
    int index = 0;
    for (Entry<K, V> entry : sortedProperties) {
      if (index > 0) {
        builder.append(", ");
      }
      builder.append(entry.getKey()).append("=").append(entry.getValue());
      index++;
    }
    builder.append("}");
  }
872829
public List<Entry> getEntries() {
		if(_sortedEntries == null) {
			this._sortedEntries = Lists.newArrayListWithCapacity(entries.size());
			for(Map.Entry<Term, Entry> e:entries.entrySet())
				this._sortedEntries.add(e.getValue());
			Collections.sort(this._sortedEntries);
		}
		return _sortedEntries;
	}
586853
public static MapMapping createMapMapping( List<Element> inputElements ){
        if( inputElements == null || inputElements.isEmpty() ){
            return null;
        }
        MapMapping result = new MapMapping();
        for( Element element : inputElements ){
            String name = element.getString( 1 );
            result.addEntryMapping( name, createInputMapping( element.getObject( 0 ) ) );
        }
        return result;
    }
255835
public static <K, V> LinkedHashMap<K, V> sortToMap(Collection<Map.Entry<K, V>> entryCollection, Comparator<Map.Entry<K, V>> comparator) {
		List<Map.Entry<K, V>> list = new LinkedList<>(entryCollection);
		Collections.sort(list, comparator);

		LinkedHashMap<K, V> result = new LinkedHashMap<>();
		for (Map.Entry<K, V> entry : list) {
			result.put(entry.getKey(), entry.getValue());
		}
		return result;
	}
1178074
public ExpressionParser addMapper(Map<String,String> map)
    {
        mapperList.add((s)->map.get(s));
        return this;
    }