TODO: 重构这个函数
 这里应该可以逻辑更加简单一些的
172141
def merge_similar_colors

        @colors.each do |info|
          per, c = *info
          info[1] = pure( dither( c ), s: nil, l:nil )
        end

        auto_link_colors!

        new_colors = {}
        @colors.each do |per, color|
          link_to = parent_color(color)
          if link_to
            new_colors[link_to] ||= 0
            new_colors[link_to] += per
          else
            new_colors[color.html] = per
          end
        end

        @colors = new_colors.map do |color_html, per|
          [per, Color::RGB.from_html(color_html)]
        end
      end
578484
private static int add(int set[], StringBuffer str)
    {
        int result = str.length();

        for (int i = result - 1; i >= 0; i --) {
            add(set, str.charAt(i));
        }
        return result;
    }
828634
public void add(int line, Vertex vertex)
    {
        for (Vertex oldVertex : vertexes[line])
        {
            // 保证唯一性
            if (oldVertex.realWord.length() == vertex.realWord.length()) return;
        }
        vertexes[line].add(vertex);
        ++size;
    }
290386
public void append(byte[] data) {
        if (data.length >= (this.datas.length - size)) {
            // 扩容
            byte[] newData = new byte[this.datas.length + data.length + this.datas.length / 2];
            System.arraycopy(this.datas, 0, newData, 0, size);
            this.datas = newData;
        }
        System.arraycopy(data, 0, this.datas, size, data.length);
        this.size += data.length;
        modCount++;
    }
1262765
@SuppressWarnings({ "unchecked", "rawtypes" })
	public static <T> Collection<T> addAll(Collection<T> collection, Object value, Type elementType) {
		if (null == collection || null == value) {
			return collection;
		}
		if (TypeUtil.isUnknow(elementType)) {
			// 元素类型为空时，使用Object类型来接纳所有类型
			elementType = Object.class;
		} else {
			final Class<?> elementRowType = TypeUtil.getClass(elementType);
			if (null != elementRowType && (elementRowType.isInstance(value) && false == Iterable.class.isAssignableFrom(elementRowType))) {
				// 其它类型按照单一元素处理
				collection.add((T) value);
				return collection;
			}
		}

		Iterator iter;
		if (value instanceof Iterator) {
			iter = (Iterator) value;
		} else if (value instanceof Iterable) {
			iter = ((Iterable) value).iterator();
		} else if (value instanceof Enumeration) {
			iter = new EnumerationIter<>((Enumeration) value);
		} else if (ArrayUtil.isArray(value)) {
			iter = new ArrayIter<>(value);
		} else if (value instanceof CharSequence) {
			// String按照逗号分隔的列表对待
			iter = StrUtil.splitTrim((CharSequence) value, CharUtil.COMMA).iterator();
		} else {
			// 其它类型按照单一元素处理
			iter = CollUtil.newArrayList(value).iterator();
		}

		final ConverterRegistry convert = ConverterRegistry.getInstance();
		while (iter.hasNext()) {
			collection.add((T) convert.convert(elementType, iter.next()));
		}

		return collection;
	}
589664
function Overloader() {
		var overloaded = new OverloadedFunction();
		var append = function(args) {
			overloaded.overload.apply(overloaded, args);
		};

		if (arguments.length) {
			// append(arguments);
		}

		var fn = function() {
			return overloaded.apply(this, arguments);
		};

		// 已创建的多态函数，仍可通过 overload() 方法扩展其多态实现。
		fn.overload = function(/* Type, Type, ..., Function */) {
			append(arguments);
			return fn;
		};

		// 扩展多态实现，同时将该实现设定为默认实现。
		fn.default = function(method) {
			overloaded.default(method);
			return fn;
		};

		// 返回一个函数实体。
		return fn;
	}
819614
function() {
                // 获取现有颜色映射
                //     resource => color_index
                var colorMapping = this._getResourceColorIndexMapping();

                var resource, used, i;

                used = [];

                // 抽取已经使用的值到 used 数组
                for (resource in colorMapping) {
                    if (Object.prototype.hasOwnProperty.call(colorMapping, resource)) {
                        used.push(colorMapping[resource]);
                    }
                }

                // 枚举所有的可用值，如果还没被使用，返回
                for (i = 0; i < RESOURCE_COLOR_SERIES.length; i++) {
                    if (!~used.indexOf(i)) return i;
                }

                // 没有可用的颜色了
                return -1;
            }
911454
private static int add(int set[], String str)
    {
        int result = str.length();

        for (int i = result - 1; i >= 0; i --) {
            add(set, str.charAt(i));
        }
        return result;
    }
662178
function mergeDetail(allEle, addEle, attrName, type) {

    if (allEle[attrName] && addEle[attrName]) {
        if (type == 1) {
            for (var k in allEle[attrName]) {
                //todo 现在没有考虑两个文件中同一项覆盖率的统计行数不一致的问题
                if ( parseInt(allEle[attrName][k])==0 &&  parseInt(addEle[attrName][k]) ==1) {
                    allEle[attrName][k] = 1;
                }
            }
        }
        else if (type == 2) {
            for (var k in allEle[attrName]) {
                //todo 现在没有考虑两个文件中同一项覆盖率的统计行数不一致的问题
                if (addEle[attrName][k]) {
                    if (parseInt(allEle[attrName][k][0])==0 &&parseInt(addEle[attrName][k][0])==1 ) {
                        allEle[attrName][k][0] = 1;
                    }
                    if (parseInt(allEle[attrName][k][1])==0 &&parseInt(addEle[attrName][k][1])==1 ) {
                        allEle[attrName][k][1] = 1;
                    }
                }
            }
        }
    }
    return allEle;
}
464876
private static void combineWords(String[] wordNet, int start, int end, CoreDictionary.Attribute[] attributeArray, CoreDictionary.Attribute value)
    {
        if (start + 1 != end)   // 小优化，如果只有一个词，那就不需要合并，直接应用新属性
        {
            StringBuilder sbTerm = new StringBuilder();
            for (int j = start; j < end; ++j)
            {
                if (wordNet[j] == null) continue;
                sbTerm.append(wordNet[j]);
                wordNet[j] = null;
            }
            wordNet[start] = sbTerm.toString();
        }
        attributeArray[start] = value;
    }
162421
private void recordDeserializeRequest(RequestCommand requestCommand) {
        if (!RpcInternalContext.isAttachmentEnable()) {
            return;
        }
        RpcInternalContext context = RpcInternalContext.getContext();
        int cost = context.getStopWatch().tick().read();
        int requestSize = RpcProtocol.getRequestHeaderLength()
            + requestCommand.getClazzLength()
            + requestCommand.getContentLength()
            + requestCommand.getHeaderLength();
        // 记录请求反序列化大小和请求反序列化耗时
        context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, requestSize);
        context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_DESERIALIZE_TIME, cost);
    }
625347
public function save(): void
    {
        $keys = [];

        $primaryKey = $this->primaryKey;

        //每个行对象进行保存
        foreach ($this as $record) {
            /*
             * @var SRecord
             */
            $record->save();

            //取行对象的主键值
            $keys[] = $record->{$primaryKey};
        }

        //要删除的记录的主键值
        $deletedKeys = array_diff($this->oldPrimaryKeys, $keys);

        //一对多时,在关联表中进行删除
        if ($this->type === 'hasMany') {
            /**
             * @var $tableClass Table
             */
            $tableClass = $this->tableClass;
            $tableClass::instance()->delete([$this->primaryKey => $deletedKeys]);
        } elseif ($this->type === 'belongsToMany') {
            //多对多关联时,删除 中间表
            $config = $this->relation;

            //配置信息
            $middleClass = $config['middle'];  //中间表
            $selfForeignKey = $config['selfForeignKey'];//中间表中与本表关联的键
            $targetForeignKey = $config['targetForeignKey'];//中间表中与对方 表关联的键
            $selfPrimaryValue = $config['selfPrimaryValue']; //主表主键值

            //在中间表中进行删除
            $middleClass::instance()->delete([$selfForeignKey => $selfPrimaryValue, $targetForeignKey => $deletedKeys]);
        }
    }
396082
public static String serialize(Object object, boolean addType) {
        if (object == null) {
            return "null";
        } else if (object instanceof CharSequence || object instanceof Character) { //TODO 去除特殊字符
            String tmp = object.toString();
            return '\"' + tmp.replace("\"", "\\\"").replace("\b", "\\b")
                .replace("\t", "\\t").replace("\r", "\\r")
                .replace("\f", "\\f").replace("\n", "\\n") + '\"';
        } else if (object instanceof Number || object instanceof Boolean) {
            return object.toString();
        } else if (object instanceof Map) {
            StringBuilder sb = new StringBuilder();
            sb.append('{');
            Map map = (Map) object;
            Iterator itr = map.entrySet().iterator();
            while (itr.hasNext()) {
                Map.Entry entry = (Map.Entry) itr.next();
                sb.append(serialize(entry.getKey(), addType)).append(':').append(serialize(entry.getValue(), addType))
                    .append(',');
            }
            int last = sb.length() - 1;
            if (sb.charAt(last) == ',') {
                sb.deleteCharAt(last);
            }
            sb.append('}');
            return sb.toString();
        } else if (object instanceof Collection) {
            return serialize(((Collection) object).toArray(), addType);
        } else if (object.getClass().isArray()) {
            StringBuilder sb = new StringBuilder();
            sb.append('[');
            int last = Array.getLength(object) - 1;
            for (int i = 0; i <= last; ++i) {
                Object value = Array.get(object, i);
                sb.append(serialize(value, addType)).append(',');
            }
            last = sb.length() - 1;
            if (sb.charAt(last) == ',') {
                sb.deleteCharAt(last);
            }
            sb.append(']');
            return sb.toString();
        } else {
            //throw new IllegalArgumentException("Unsupported type " + object.getClass().getName() + ":" + object.toString());
            // 自定义对象，先转成map等
            return serialize(BeanSerializer.serialize(object, addType), addType);
        }
    }
1067910
@SuppressWarnings("unchecked")
    private static Object putIfNotExist(Object data, Map<String, Object> resultMap) {
        LOG.info("[RuleController]补全信息时:data = " + data);
        if (data == null) {
            return resultMap;
        } else if (!(data instanceof Collection) && !(data instanceof Map)) {//既不是map也不是list,需要显示地配置出最后一个unit的返回结果列表
            return resultMap;
        } else if (data instanceof Map) {
            putToMap((Map) data, resultMap);
            return data;
        } else/* if (data instanceof Collection)*/ {
            Collection newCollection = new ArrayList<>();
            Collection listData = (Collection) data;
            for (Object o : listData) {
                newCollection.add(putIfNotExist(o, resultMap));
            }
            return newCollection;
        }
    }
772461
public synchronized void  loadAll(){
		group.clear();
		count=0;

		List<File> files = MyFiles.getAllFiles(fileName, ".txt");
		if(files==null||files.size()==0){
			System.err.println("模板为空");
		}
		try {
			for(int i=0;i<files.size();i++){
					read(files.get(i).toString());
					//记录文件修改时间
					lastModTime.put(files.get(i).toString(),files.get(i).lastModified());

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("总模板数: " +count);
	}
900875
public void combine(SimpleDictionary<V> other)
    {
        if (other.trie == null)
        {
            logger.warning("有个词典还没加载");
            return;
        }
        for (Map.Entry<String, V> entry : other.trie.entrySet())
        {
            if (trie.containsKey(entry.getKey())) continue;
            trie.put(entry.getKey(), entry.getValue());
        }
    }
243933
public void addResourceLoader(Matcher matcher, ResourceLoader resourceLoader)
	{
		//检查是否存在该匹配器
		if (this.matcherResourceLoaderMap.containsKey(matcher))
		{
			//已经添加了。
			return;
		}
		this.matcherResourceLoaderMap.put(matcher, resourceLoader);
		this.matchers.add(matcher);
	}