单例实现
    @singleton
    class test():
        pass
161316
def singleton(cls):
    '''
    
    '''

    cls.__new_original__ = cls.__new__

    @wraps(cls.__new__)
    def singleton_new(cls, *args, **kw):
        it = cls.__dict__.get('__it__')
        if it is not None:
            return it

        cls.__it__ = it = cls.__new_original__(cls, *args, **kw)
        it.__init_original__(*args, **kw)
        return it

    cls.__new__ = singleton_new
    cls.__init_original__ = cls.__init__
    cls.__init__ = object.__init__

    return cls
515967
static public function singleton()
    {
        if (! self::$_singleton) {
            global $CA_CONFIG;
            self::$_singleton = self::probe($CA_CONFIG ? $CA_CONFIG : array());
        }
        return self::$_singleton;
    }
311137
public function init($moduleName, $moduleTestName, $unitTestPath = 'test')
    {
        $moduleSvc = $this->getServiceLocator()->get('ModulesService');
        $modulePath = $moduleSvc->getModulePath($moduleName);
        $bootstrapSavePath = $modulePath.'/'.$unitTestPath.'/Bootstrap.php';
        $xmlSavePath = $modulePath.'/'.$unitTestPath.'/phpunit.xml';
        $moduleTestSavePath = $modulePath.'/'.$unitTestPath.'/'.$moduleTestName.'/Controller';
        $testSavePath = $modulePath.'/'.$unitTestPath;

        $this->setAppConfig();
        if(file_exists($modulePath) && file_exists($testSavePath)) {

            $bootstrapTemplate = $_SERVER['DOCUMENT_ROOT'] . '/../test/tpl/BootstrapTemplate';
            $puControllerTemplate = $_SERVER['DOCUMENT_ROOT'] . '/../test/tpl/PHPUnitControllTest';
            $bootstrapContent = '';
            $xmlContent = '';
            if(file_exists($bootstrapTemplate)) {

                $bootstrapContent = file_get_contents($bootstrapTemplate);
                $bootstrapContent = sprintf($bootstrapContent, $moduleTestName);
                file_put_contents($bootstrapSavePath, $bootstrapContent);
                $xml = $_SERVER['DOCUMENT_ROOT'].'/../test/tpl/phpunitxmlTemplate';
                if(file_exists($xml)) {
                    $xmlContent = file_get_contents($xml);
                    $xmlContent = str_replace('{{moduleName}}', $moduleTestName, $xmlContent);
                    file_put_contents($xmlSavePath, $xmlContent);
                }

                if(!file_exists($moduleTestSavePath)) {
                    mkdir($moduleTestSavePath, 0777, true);

                    $tmpcontrollerName = explode("Test", $moduleTestName);
                    if(is_array($tmpcontrollerName) && !empty($tmpcontrollerName)) {
                        $controllerName = $tmpcontrollerName[0] . 'ControllerTest';
                        if(!file_exists($moduleTestSavePath.'/'.$controllerName.'.php')) {
                            $ctrlTpl = file_get_contents($puControllerTemplate);
                            $ctrlTpl = str_replace(array(
                                '{{moduleTestName}}',
                                '{{moduleTestControllerName}}',
                                '{{tableFunctions}}',
                                '{{moduleName}}'
                            ), array($moduleTestName, $controllerName, $this->getDbMethods($moduleName), $moduleName), $ctrlTpl);
                            file_put_contents($moduleTestSavePath.'/'.$controllerName.'.php', $ctrlTpl);
                        }
                    }
                }
            }
        }
        else {
            mkdir($testSavePath, 0777, true);
            $this->init($moduleName, $moduleTestName, $unitTestPath);
        }

        // Make sure the files are existing
        if(file_exists($bootstrapSavePath) && file_exists($xmlSavePath) && file_exists($moduleTestSavePath)) {
            return true;
        }

        return false;

    }
1014923
static function result($s, $quanpin = true, $daxie = false, $trim = false)
      {
            $pyCount = 0;
            if(is_array($quanpin) && $quanpin[1]) {
                  $pyCount = $quanpin[1];
                  unset($quanpin[1]);
                  $quanpin = $quanpin[0];
            }
            $s = preg_replace("/\s/is", "_", $s);
            $s = preg_replace("/(|\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\+|\=|\{|\}|\[|\]|\||\\|\:|\;|\"|\'|\<|\,|\>|\.|\?|\/)/is", "", $s);
            $i = 0;
            $py = '';
            $_trim = $trim ? ' ' : '';
            // 加入这一句，自动识别UTF-8
            if (strlen("拼音") > 4)
            $s = iconv('UTF-8', 'GBK', $s);
            if ($quanpin) {
                  // 全拼
                  for ($i = 0; $i < strlen($s); $i++) {
                      if (ord($s[$i]) > 128) {
                          $char = self::asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256);
                          $py.=$char.$_trim;
                          $i++;
                      } else {
                          $py.=$s[$i].$_trim;
                      }
                  }
            } else {
                  // 首字母
                  for ($i = 0; $i < strlen($s); $i++) {
                        if (ord($s[$i]) > 128) {
                              $char = self::asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256);
                              $py	.=$char[0].$_trim;
                              $i++;
                        } else {
                              $py	.=$s[$i].$_trim;
                        }
                  }
            }
            $py = $trim ? trim($py, ' ') : $py;
            if($pyCount){
                  $py = substr($py, 0, $pyCount);
            }
            return ($daxie == true ? $py : strtolower($py));// 判断是否输出小写字符
      }
116546
public static function singleton()
    {
        $returnValue = null;

        
        $cacheName = get_called_class();
        if (!isset(self::$instances[$cacheName])) {
        	self::$instances[$cacheName] = new $cacheName();
        }
        
        $returnValue = self::$instances[$cacheName];
        

        return $returnValue;
    }
1212673
def getInstance(cls, *args):
        '''
        
        '''
        if not cls.__singleton:
            cls.__singleton = Config(*args)
        return cls.__singleton
305053
private static function init()
    {
        $config = Config::getEnv("database.redis");
        if (empty($config)) {
            throw new \InvalidArgumentException("配置项'database.redis'不能为空");
        }
        $config = (array) $config;
        $db_conn_name_list = \Qp\Kernel\Database\QpDB::getConnectionNameList();

        foreach ($config as $name => $data) {
            $name = strval($name);
            if (in_array($name, $db_conn_name_list)) {
                throw new \InvalidArgumentException("配置项'database.redis'的连接名'{$name}'和其他类型的数据库连接名冲突");
            }

            $data = (array) $data;
            if (empty($data)) {
                throw new \InvalidArgumentException("配置项'database.redis.{$name}'必须为非空数组");
            }
            $conn_name = $name;
            self::handleConfigArr($data, 'host', $host);
            self::handleConfigArr($data, 'auth', $auth);
            self::handleConfigArr($data, 'database', $database);
            self::handleConfigArr($data, 'port', $port);
            self::handleConfigArr($data, 'prefix', $prefix);

            $prefix = strval($prefix);
            if ($prefix == "") {
                $data['prefix'] = ":";
            } else {
                $data['prefix'] = "_" . $prefix . ":";
            }

            self::$config_list[$conn_name] = new ConfigObj($conn_name, $host, $auth, $database, $port, $data['prefix'], $data);
        }

        if (self::$frontCache === null) {
            self::$frontCache = new \Phalcon\Cache\Frontend\Data(self::$frontCacheData);
        }
    }
487373
@Override
	public T get() {
		T result = reference.get();

		if (result == null) {
			result = init();
			if (false == reference.compareAndSet(null, result)) {
				// 其它线程已经创建好此对象
				result = reference.get();
			}
		}

		return result;
	}
836745
@SuppressWarnings("unchecked")
    public static <R> R invoke(Object obj, String methodName, Class<?>[] parameterTypes,
                               Object... args) {
        Assert.isFalse(
            CollectionUtil.safeIsEmpty(parameterTypes) ^ CollectionUtil.safeIsEmpty(args),
            "方法参数类型列表必须和方法参数列表一致");
        Assert.isTrue(parameterTypes == null || parameterTypes.length == args.length,
            "方法参数类型列表长度必须和方法参数列表长度一致");
        Method method;
        if (obj instanceof Class) {
            method = getMethod((Class) obj, methodName, parameterTypes);
        } else {
            method = getMethod(obj.getClass(), methodName, parameterTypes);
        }
        return invoke(obj, method, args);
    }
993622
protected static function get(string $component, bool $forInstance = false)
    {
        //读取具体组件
        $component = strtoupper($component);
        if (array_key_exists($component, self::$lists)) {
            $Class = self::$lists[$component][0];
            if ($forInstance) {
                if (!is_object($Class)) {
                    $Class = new $Class;
                }
            } else {
                if (is_object($Class)) {
                    $Class = get_class($Class);
                }
            }
            return $Class;
        }
        throw new Exception("$component does not exist!"); //没有注册则抛出异常
    }
422489
public function make(string $name, bool $isSingleton = true, int $instanceId = 0)
    {
        // 获取标识
        if (isset($this->shortNameMap[$name])) {
            $funcKey = $this->shortNameMap[$name];
        } else {
            $funcKey = $this->getFuncKey($name, $instanceId);
        }
        // 非单例模式
        if (! $isSingleton) {
            return $this->getNewInstance($funcKey);
        }
        // 单例模式
        if (! isset($this->objectMap[$funcKey])) {
            $objectInstance = $this->getNewInstance($funcKey);
            $this->objectMap[$funcKey] = $objectInstance;
        }
        return $this->objectMap[$funcKey];
    }
1043849
private Collection tryBuildCollection(Class<? extends Collection> clazz) {
        if (List.class.equals(clazz) || Collection.class.equals(clazz)) {
            return new ArrayList();
        } else if (Set.class.equals(clazz)) {
            return new HashSet();
        } else if (List.class.isAssignableFrom(clazz)) {
            try {
                return clazz.newInstance();
            } catch (Exception e) {
                log.warn("指定class[{}]无法创建对象，请为其添加公共无参数构造器，将使用默认实现ArrayList", clazz, e);
                return new ArrayList();
            }
        } else if (Set.class.isAssignableFrom(clazz)) {
            try {
                return clazz.newInstance();
            } catch (Exception e) {
                log.warn("指定class[{}]无法创建对象，请为其添加公共无参数构造器，将使用默认实现HashSet", clazz, e);
                return new HashSet();
            }
        } else {
            log.warn("未知集合类型：[{}]", clazz);
            return null;
        }
    }
1280762
public static <T> T newInstance(Class<T> clazz) throws SofaRpcRuntimeException {
        if (clazz.isPrimitive()) {
            return (T) getDefaultPrimitiveValue(clazz);
        }

        T t = getDefaultWrapperValue(clazz);
        if (t != null) {
            return t;
        }

        try {
            // 普通类，如果是成员类（需要多传一个父类参数）
            if (!(clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers()))) {
                try {
                    // 先找一个空的构造函数
                    Constructor<T> constructor = clazz.getDeclaredConstructor();
                    constructor.setAccessible(true);
                    return constructor.newInstance();
                } catch (Exception ignore) { // NOPMD
                }
            }
            // 不行的话，找一个最少参数的构造函数
            Constructor<T>[] constructors = (Constructor<T>[]) clazz.getDeclaredConstructors();
            if (constructors == null || constructors.length == 0) {
                throw new SofaRpcRuntimeException("The " + clazz.getCanonicalName()
                    + " has no default constructor!");
            }
            Constructor<T> constructor = constructors[0];
            if (constructor.getParameterTypes().length > 0) {
                for (Constructor<T> c : constructors) {
                    if (c.getParameterTypes().length < constructor.getParameterTypes().length) {
                        constructor = c;
                        if (constructor.getParameterTypes().length == 0) {
                            break;
                        }
                    }
                }
            }
            constructor.setAccessible(true);
            // 虚拟构造函数的参数值，基本类型使用默认值，其它类型使用null
            Class<?>[] argTypes = constructor.getParameterTypes();
            Object[] args = new Object[argTypes.length];
            for (int i = 0; i < args.length; i++) {
                args[i] = getDefaultPrimitiveValue(argTypes[i]);
            }
            return constructor.newInstance(args);
        } catch (SofaRpcRuntimeException e) {
            throw e;
        } catch (Throwable e) {
            throw new SofaRpcRuntimeException(e.getMessage(), e);
        }
    }
34129
private static <T> Iterator<T> start(T singleton) {
    return Collections.singleton(singleton).iterator();
  }
1237755
public function bind( $id, $value = null, $singleton = false ) {
		if ( is_string( $id ) && $this->is_singleton( $id ) ) {
			throw new Exception( sprintf( 'Identifier `%s` is a singleton and cannot be rebind', $id ) );
		}

		if ( is_string( $value ) && class_exists( $value ) ) {
			$closure = new ReflectionClass( $value );
			$value   = $this->call_closure( $closure );
			$closure = function () use ( $value ) {
				return $value;
			};

			$this->bindings[$id] = compact( 'closure', 'singleton' );
			$this->keys[$id]     = true;

			return $value;
		}

		if ( is_object( $id ) && get_class( $id ) !== false ) {
			$value              = $id;
			$id                 = $this->get_class_prefix( get_class( $id ), false );
			$this->classes[$id] = true;
		}

		if ( $value instanceof Closure ) {
			$closure = $value;
		} else {
			$closure = $this->get_closure( $value, $singleton );
		}

		$this->bindings[$id] = compact( 'closure', 'singleton' );
		$this->keys[$id]     = true;

		return $value;
	}
292525
public void loadData() throws Exception{

		System.out.print("Loading training data ...");
		long beginTime = System.currentTimeMillis();

		Pipe pipe = createProcessor();


		trainSet = new InstanceSet(pipe, factory);
		labels = factory.DefaultLabelAlphabet();
		features = factory.DefaultFeatureAlphabet();
		features.setStopIncrement(false);
		labels.setStopIncrement(false);

		// 训练集
		trainSet.loadThruStagePipes(new SequenceReader(train, true));

		long endTime = System.currentTimeMillis();
		System.out.println(" done!");
		System.out.println("Time escape: " + (endTime - beginTime) / 1000 + "s");
		System.out.println();

		// 输出
		System.out.println("Training Number: " + trainSet.size());
		System.out.println("Label Number: " + labels.size()); // 标签个数
		System.out.println("Feature Number: " + features.size()); // 特征个数
		System.out.println();

		// 冻结特征集
		features.setStopIncrement(true);
		labels.setStopIncrement(true);


		// 读入测试数据
		if (testfile != null) {
			System.out.print("Loading test data ...");
			boolean hasTarget = true;;
			if (!hasTarget) {// 如果test data没有标注
				pipe = featurePipe;
			} 

			// 测试集
			testSet = new InstanceSet(pipe);
			testSet.loadThruStagePipes(new SequenceReader(testfile, hasTarget, "utf8"));
			System.out.println("Test Number: " + testSet.size()); // 样本个数
		}
	}
973931
function () {
                this.$Test._endTest.call(this);
                this.checkExpectedEventListEnd();
                this.resetClassOverrides();
                this.assertLogsEmpty(false, false);
                this._assertCount = 0;
                this._currentTestName = '';

                this._isFinished = true;

                this.$raiseEvent({
                    name : "end",
                    testObject : this,
                    testClass : this.$classpath,
                    nbrOfAsserts : this._totalAssertCount
                });
            }