当前位置: 首页>>代码示例>>Java>>正文


Java SerializedLambda类代码示例

本文整理汇总了Java中java.lang.invoke.SerializedLambda的典型用法代码示例。如果您正苦于以下问题:Java SerializedLambda类的具体用法?Java SerializedLambda怎么用?Java SerializedLambda使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SerializedLambda类属于java.lang.invoke包,在下文中一共展示了SerializedLambda类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkInput

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    count++;
    if (filter.serialClass() != null) {
        if (filter.serialClass().getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(filter.serialClass())) {
            classes.add(Proxy.class);
        } else {
            classes.add(filter.serialClass());
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:SerialFilterTest.java

示例2: checkInput

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:SerialFilterTest.java

示例3: createLambdaObject

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private SerializedValue createLambdaObject(Type type, Object object) {
	SerializedValue serializedObject = serialized.get(object);
	if (serializedObject == null) {
		SerializedLambda serializedLambda = Lambdas.serializeLambda(object);
		try {
			Class<?> functionalInterfaceType = classFrom(serializedLambda.getFunctionalInterfaceClass());
			Serializer serializer = fetchSerializer(serializedLambda.getClass());
			serializedObject = serializer.generate(type, functionalInterfaceType);
			serialized.put(object, serializedObject);
			if (serializedObject instanceof SerializedReferenceType) {
				((SerializedReferenceType) serializedObject).setId(identityHashCode(object));
			}
			serializer.populate(serializedObject, serializedLambda);
		} catch (RuntimeException e) {
			throw new SerializationException(e);
		}
	}
	return serializedObject;
}
 
开发者ID:almondtools,项目名称:testrecorder,代码行数:21,代码来源:ConfigurableSerializerFacade.java

示例4: fetchSerializer

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private Serializer<?> fetchSerializer(Class<?> clazz) {
	Serializer<?> serializer = serializers.get(clazz);
	if (serializer != null) {
		return serializer;
	}
	if (clazz.isArray()) {
		serializer = new ArraySerializer(this);
	} else if (clazz.isEnum() || (clazz.getSuperclass() != null && clazz.getSuperclass().isEnum())) {
		serializer = new EnumSerializer(this);
	} else if (SerializedLambda.class == clazz) {
		serializer = new LambdaSerializer(this);
	} else {
		serializer = new GenericSerializer(this);
	}
	return serializer;
}
 
开发者ID:almondtools,项目名称:testrecorder,代码行数:17,代码来源:ConfigurableSerializerFacade.java

示例5: populate

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
@Override
public void populate(SerializedLambdaObject serializedLambda, Object object) {
	if (!(object instanceof SerializedLambda)) {
		return;
	}
	SerializedLambda lambda = (SerializedLambda) object;

	serializedLambda.setSignature(new LambdaSignature()
		.withCapturingClass(lambda.getCapturingClass())
		.withInstantiatedMethodType(lambda.getInstantiatedMethodType())
		.withFunctionalInterface(
			lambda.getFunctionalInterfaceClass(), 
			lambda.getFunctionalInterfaceMethodName(),
			lambda.getFunctionalInterfaceMethodSignature())
		.withImplMethod(lambda.getImplClass(), lambda.getImplMethodKind(), lambda.getImplMethodName(), lambda.getImplMethodSignature()));
	

	List<SerializedValue> arguments = IntStream.range(0, lambda.getCapturedArgCount())
		.mapToObj(lambda::getCapturedArg)
		.map(o -> facade.serialize(o.getClass(), o))
		.collect(toList());
	serializedLambda.setCapturedArguments(arguments);
}
 
开发者ID:almondtools,项目名称:testrecorder,代码行数:24,代码来源:LambdaSerializer.java

示例6: testReferencedLambdaExpression

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
public void testReferencedLambdaExpression() {
    final LambdaKeeper keeper = new LambdaKeeper();
    keeper.keep((Callable<String> & Serializable)() -> "result");
    keeper.reference();

    final String expected = ""
        + "<keeper>\n"
        + "  <callable resolves-to=\"serialized-lambda\">\n"
        + "    <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
        + "    <functionalInterfaceClass>java/util/concurrent/Callable</functionalInterfaceClass>\n"
        + "    <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
        + "    <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
        + "    <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
        + "    <implMethodName>lambda$0</implMethodName>\n"
        + "    <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
        + "    <implMethodKind>6</implMethodKind>\n"
        + "    <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
        + "    <capturedArgs/>\n"
        + "  </callable>\n"
        + "  <referenced class=\"java.util.concurrent.Callable\" reference=\"../callable\"/>\n"
        + "</keeper>";
    xstream.alias("keeper", LambdaKeeper.class);
    xstream.allowTypes(SerializedLambda.class);

    assertBothWaysNormalized(keeper, expected);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:27,代码来源:LambdaTest.java

示例7: serialized

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
default SerializedLambda serialized() {
    try {
        Method replaceMethod = getClass().getDeclaredMethod("writeReplace");
        replaceMethod.setAccessible(true);
        return (SerializedLambda) replaceMethod.invoke(this);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:10,代码来源:MethodFinder.java

示例8: method

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
default Method method() {
    SerializedLambda lambda = serialized();
    Class<?> containingClass = getContainingClass();
    return Arrays.asList(containingClass.getDeclaredMethods())
            .stream()
            .filter(method -> Objects.equals(method.getName(), lambda.getImplMethodName()))
            .findFirst()
            .orElseThrow(UnableToGuessMethodException::new);
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:10,代码来源:MethodFinder.java

示例9: nameOf

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private static String nameOf(PropertyToMatch<?, ?> property) {
    Optional<String> propertyName = Stream.<Class<?>>iterate(property.getClass(), Class::getSuperclass)
            .flatMap(c -> Arrays.stream(c.getDeclaredMethods()))
            .filter(m -> m.getName().equals("writeReplace"))
            .map(m -> (SerializedLambda) invoke(m, property))
            .map(SerializedLambda::getImplMethodName)
            .findFirst();

    return propertyName.orElseThrow(() -> new RuntimeException("Unable to determine property name."));
}
 
开发者ID:tim-group,项目名称:tg-eventstore,代码行数:11,代码来源:HasPropertyValueMatcher.java

示例10: LambdaInfo

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
public LambdaInfo(Object lambda, Kind kind, SerializedLambda serializedLambda, Method functionalMethod, Method implementationMethod) {
    this.lambda = lambda;
    this.kind = kind;
    this.serializedLambda = serializedLambda;
    this.functionalMethod = functionalMethod;
    this.implementationMethod = implementationMethod;
}
 
开发者ID:onepiecex,项目名称:mq-aliyun,代码行数:8,代码来源:Lambdas.java

示例11: fnToFieldName

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
public static String fnToFieldName(Fn fn) {
    try {
        Method method = fn.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda) method.invoke(fn);
        String getter = serializedLambda.getImplMethodName();
        String fieldName = Introspector.decapitalize(getter.replace("get", ""));
        return fieldName;
    } catch (ReflectiveOperationException e) {
        throw new ReflectionOperationException(e);
    }
}
 
开发者ID:liuyuyu,项目名称:weekend,代码行数:13,代码来源:Reflections.java

示例12: assertDeserializeMethod

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:DeserializeMethodTest.java

示例13: saveGame

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private void saveGame() {
	xstream.autodetectAnnotations(true);
	xstream.allowTypes(new Class[] {SerializedLambda.class});
	spritesCopy = new ArrayList<>();
	for (Sprite sprite : spriteModel.getSprites()) {
		spritesCopy.add(sprite.clone());
	}
	savedSpritesXML = xstream.toXML(spritesCopy);
}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:10,代码来源:Models.java

示例14: where

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
public <T> IsPojo<A> where(
    final MethodReference<A, T> methodReference,
    final Matcher<T> returnValueMatcher) {
  final SerializedLambda serializedLambda = serializeLambda(methodReference);

  ensureDirectMethodReference(serializedLambda);

  return where(
      serializedLambda.getImplMethodName(),
      methodReference,
      returnValueMatcher);
}
 
开发者ID:spotify,项目名称:java-hamcrest,代码行数:13,代码来源:IsPojo.java

示例15: ensureDirectMethodReference

import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private static void ensureDirectMethodReference(final SerializedLambda serializedLambda) {
  final Method targetMethod;
  try {
    final Class<?> implClass = Class.forName(serializedLambda.getImplClass().replace('/', '.'));
    targetMethod = findMethodByName(implClass, serializedLambda.getImplMethodName());
  } catch (NoSuchMethodException | ClassNotFoundException e) {
    throw new IllegalStateException(
        "serializeLambda returned a SerializedLambda pointing to an invalid class/method", e);
  }

  if (targetMethod.isSynthetic()) {
    throw new IllegalArgumentException("The supplied lambda is not a direct method reference");
  }
}
 
开发者ID:spotify,项目名称:java-hamcrest,代码行数:15,代码来源:IsPojo.java


注:本文中的java.lang.invoke.SerializedLambda类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。