拷贝单个对象

@param clazz      目标类型
@param src        原对象
@param biConsumer 回调函数
@param <T>        原数据类型
@param <R>        目标数据类型
@return 目标对象
177464
public static <T, R> R process(Class<R> clazz, T src, BiConsumer<R, T> biConsumer) {
        if (Objects.isNull(clazz)) {
            throw new IllegalArgumentException("the clazz argument must be not null");
        }
        if (Objects.isNull(src)) {
            log.warn("the src argument must be not null, return null. ");
            return null;
        }
        try {
            R r = clazz.newInstance();
            processObject(r, src, biConsumer);
            return r;
        } catch (Exception e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    }
964873
public static boolean hasAccessibleDefaultConstructor(Class<?> clazz) {
    Constructor<?> constructor;
    try {
      constructor = clazz.getDeclaredConstructor();
    } catch (NoSuchMethodException e) {
      return clazz.getDeclaredConstructors().length == 0;
    }

    return !isPrivate(constructor);
  }
1245001
public static Map<RouteDefinition, Method> get(Class clazz) {

		Map<RouteDefinition, Method> out = new HashMap<>();

		Map<RouteDefinition, Method> candidates = collect(clazz);
		// Final check if definitions are OK
		for (RouteDefinition definition : candidates.keySet()) {

			if (definition.getMethod() == null) { // skip non REST methods
				continue;
			}

			Method method = candidates.get(definition);
			Assert.notNull(definition.getRoutePath(), getClassMethod(clazz, method) + " - Missing route @Path!");

			int bodyParamCount = 0;
			for (MethodParameter param : definition.getParameters()) {
				if (bodyParamCount > 0 && (ParameterType.body.equals(param.getType()) || ParameterType.unknown.equals(param.getType()))) {
					// OK we have to body params ...
					throw new IllegalArgumentException(getClassMethod(clazz, method) + " - to many body arguments given. " +
					                                   "Missing argument annotation (@PathParam, @QueryParam, @FormParam, @HeaderParam, @CookieParam or @Context) for: " +
					                                   param.getType() + " " + param.getName() + "!");
				}

				if (ParameterType.unknown.equals(param.getType())) { // proclaim as body param
					// check if method allows for a body param
					Assert.isTrue(definition.requestHasBody(), getClassMethod(clazz, method) + " - " +
					                                           "Missing argument annotation (@PathParam, @QueryParam, @FormParam, @HeaderParam, @CookieParam or @Context) for: " +
					                                           param.getName() + "!");

					param.setType(ParameterType.body);
				}

				if (ParameterType.body.equals(param.getType())) {
					bodyParamCount++;
				}
			}

			out.put(definition, method);
		}

		return out;
	}
1079682
public static <T> boolean hasConverter(Class<T> clazz) {
      if (clazz == null) {
         return false;
      } else if (converters.containsKey(clazz)) {
         return true;
      }
      return clazz.isArray() && converters.containsKey(clazz.getComponentType());
   }
503551
public <T> void registerConverter(final Class<T> clazz, final CellConverterFactory<T> converterFactory) {
        ArgUtils.notNull(clazz, "clazz");
        ArgUtils.notNull(converterFactory, "converterFactory");
        
        converterFactoryMap.put(clazz, converterFactory);
    }
831007
public static <T> Stream<T> findAll(Class<T> clazz) {
    ServiceLoader<T> load = ServiceLoader.load(clazz);
    return StreamSupport.stream(load.spliterator(), false);
  }
639082
protected void attachBifurcatedConsumer(BifurcatedConsumerSessionImpl consumer)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "attachBifurcatedConsumer", consumer);

        // Create a bifurcated list if required
        if (_bifurcatedConsumers == null)
        {
            synchronized (this)
            {
                if (_bifurcatedConsumers == null)
                    _bifurcatedConsumers = new LinkedList<BifurcatedConsumerSessionImpl>();
            }
        }

        synchronized (_bifurcatedConsumers)
        {
            _bifurcatedConsumers.add(consumer);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "attachBifurcatedConsumer");
    }
59803
public static <D, J> J toJava(Class<? extends PreferenceTypeAdapter<J, D>> clazz, D value) {
		@SuppressWarnings("unchecked")
		PreferenceTypeAdapter<J, D> adapter = cache.get(clazz);

		if (adapter == null) {
			adapter = generateAdapter(clazz);
		}

		return adapter.toJava(value);
	}
940189
public static Converter<?, ?> constructConverter(Class<? extends Converter<?, ?>> clazz) {
		Constructor<? extends Converter<?, ?>> constructor;
		try {
			constructor = clazz.getConstructor();
		} catch (Exception e) {
			throw new IllegalArgumentException("Could not find public no-arg constructor for CSV converter class: "
					+ clazz, e);
		}
		try {
			return constructor.newInstance();
		} catch (Exception e) {
			throw new IllegalArgumentException("Could not construct new CSV converter: " + clazz, e);
		}
	}
1305360
public static <TYPE> Provider<TYPE> of(final Class<TYPE> clazz,
            @Nullable final Map<String, String> overrides)
    {
        return of(null, clazz, overrides);
    }
175886
@Nonnull
	public static <T1, T2> LBiConsumerBuilder<T1, T2> biConsumer(Consumer<LBiConsumer<T1, T2>> consumer) {
		return new LBiConsumerBuilder(consumer);
	}
222169
@Nonnull
	public static LBiByteConsumer biByteConsumerFrom(Consumer<LBiByteConsumerBuilder> buildingFunction) {
		LBiByteConsumerBuilder builder = new LBiByteConsumerBuilder();
		buildingFunction.accept(builder);
		return builder.build();
	}
1181537
public static <T> T getInstance(Class<T> clazz) {
        try {
            Constructor<T> constructor = clazz.getConstructor();
            ReflectUtil.allowAccess(constructor);
            return constructor.newInstance();
        } catch (Exception e) {
            throw new ReflectException("获取类实例异常，可能是没有默认无参构造器", e);
        }
    }
679369
public List<ConversionMethod> getConversionMethods (Class<?> clazz){
		List<ConversionMethod> conversions = new ArrayList<ConversionMethod>();
		Map<String, List<ConversionMethod>> conversionsMap = this.conversionsLoad();
		for (Class<?> classToCheck : getAllsuperClasses(clazz)){
			List<ConversionMethod> methods = conversionsMap.get(classToCheck.getName());
			if(methods != null)conversions.addAll(methods);
		}
		return conversions;
	}
344432
@SuppressWarnings("unchecked")
    public <T> CellConverterFactory<T> getConverterFactory(final Class<T> clazz) {
        ArgUtils.notNull(clazz, "clazz");
        
        CellConverterFactory<T> converterFactory = (CellConverterFactory<T>) converterFactoryMap.get(clazz);
        if(converterFactory == null) {
            // 特別に判定が必要なクラス
            if(Enum.class.isAssignableFrom(clazz)) {
                converterFactory = (CellConverterFactory<T>) converterFactoryMap.get(Enum.class);
                
            } else if(List.class.isAssignableFrom(clazz)) {
                converterFactory = (CellConverterFactory<T>) converterFactoryMap.get(List.class);
                
            } else if(clazz.isArray()) {
                converterFactory = (CellConverterFactory<T>) converterFactoryMap.get(Object[].class);
                
            }
        }
        
        return converterFactory;
    }
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);
        }
    }
918734
public static <T, U> Consumer<Pair<T, U>> tupled(BiConsumer<T, U> consumer) {
        dbc.precondition(consumer != null, "cannot apply a pair to a null consumer");
        return pair -> consumer.accept(pair.first(), pair.second());
    }