Example usage for java.lang.reflect ParameterizedType ParameterizedType

List of usage examples for java.lang.reflect ParameterizedType ParameterizedType

Introduction

In this page you can find the example usage for java.lang.reflect ParameterizedType ParameterizedType.

Prototype

ParameterizedType

Source Link

Usage

From source file:Main.java

static ParameterizedType type(final Class raw, final Type... args) {
    return new ParameterizedType() {
        public Type getRawType() {
            return raw;
        }//from   w w w  . j  a  va 2  s. c  o m

        public Type[] getActualTypeArguments() {
            return args;
        }

        public Type getOwnerType() {
            return null;
        }
    };

}

From source file:Main.java

private static ParameterizedType type(final Class raw, final Type... args) {
    return new ParameterizedType() {
        public Type getRawType() {
            return raw;
        }// w  w  w . j a  v  a 2s .c o m

        public Type[] getActualTypeArguments() {
            return args;
        }

        public Type getOwnerType() {
            return null;
        }
    };
}

From source file:org.brutusin.rpc.RpcComponent.java

/**
 *
 * @param rt/* ww w.  ja  v  a  2  s.  co m*/
 * @return
 */
protected static Type getType(final ResolvableType rt) {
    if (!rt.hasGenerics()) {
        return rt.resolve();
    } else {
        return new ParameterizedType() {
            public Type[] getActualTypeArguments() {
                Type[] ret = new Type[rt.getGenerics().length];
                for (int i = 0; i < ret.length; i++) {
                    ret[i] = getType(rt.getGenerics()[i]);
                }
                return ret;
            }

            public Type getRawType() {
                return rt.resolve();
            }

            public Type getOwnerType() {
                return null;
            }
        };
    }
}

From source file:org.openlmis.fulfillment.util.BaseParameterizedTypeReference.java

@Override
public Type getType() {
    Type[] responseWrapperActualTypes = { valueType };

    return new ParameterizedType() {
        @Override//  w w w . ja  v a2 s  .  c o m
        public Type[] getActualTypeArguments() {
            return responseWrapperActualTypes;
        }

        @Override
        public Type getRawType() {
            return getBaseType();
        }

        @Override
        public Type getOwnerType() {
            return null;
        }
    };
}

From source file:org.localmatters.serializer.tool.ConfigWriterFromClassTest.java

/**
 * Tests handling a parameterized type when the raw type is not a class 
 *///from w  w w . j a  va 2 s.  co m
public void testHandleParametrizedTypeWhenRawNotClass() {
    ConfigWriterFromClass writer = new ConfigWriterFromClass(Object.class);
    AttributeSerialization attribute = new AttributeSerialization();
    Serialization ser = writer.handleType("invalid", new ParameterizedType() {
        public Type getRawType() {
            return new Type() {
            };
        }

        public Type getOwnerType() {
            return null;
        }

        public Type[] getActualTypeArguments() {
            return null;
        }
    }, attribute);
    assertTrue(ser instanceof NameSerialization);
    NameSerialization name = (NameSerialization) ser;
    assertEquals("value", name.getName());
    assertTrue(name.getDelegate() instanceof ComplexSerialization);
    ComplexSerialization complex = (ComplexSerialization) name.getDelegate();
    assertEquals(1, CollectionUtils.size(complex.getAttributes()));
    assertSame(attribute, complex.getAttributes().get(0));
    assertTrue(CollectionUtils.isEmpty(complex.getElements()));
    assertEquals(2, CollectionUtils.size(complex.getComments()));
    assertEquals("Unable to resolve the class for the element [invalid]!", complex.getComments().get(0));
    assertEquals("Its configuration must be written manually.", complex.getComments().get(1));
}

From source file:com.axibase.tsd.client.HttpClient.java

private <T> GenericType<List<T>> listType(final Class<T> clazz) {
    ParameterizedType genericType = new ParameterizedType() {
        public Type[] getActualTypeArguments() {
            return new Type[] { clazz };
        }/*from  w  ww .  j a v a 2  s  .  c o  m*/

        public Type getRawType() {
            return List.class;
        }

        public Type getOwnerType() {
            return List.class;
        }
    };
    return new GenericType<List<T>>(genericType) {
    };
}

From source file:org.apache.ranger.admin.client.RangerAdminRESTClient.java

public static <T> GenericType<List<T>> getGenericType(final T clazz) {

    ParameterizedType parameterizedGenericType = new ParameterizedType() {
        public Type[] getActualTypeArguments() {
            return new Type[] { clazz.getClass() };
        }//from  w w w.j a  va2 s. c  o  m

        public Type getRawType() {
            return List.class;
        }

        public Type getOwnerType() {
            return List.class;
        }
    };

    return new GenericType<List<T>>(parameterizedGenericType) {
    };
}

From source file:org.blockartistry.DynSurround.registry.SoundRegistry.java

@SideOnly(Side.CLIENT)
public static void initializeRegistry() {
    final ParameterizedType TYPE = new ParameterizedType() {
        public Type[] getActualTypeArguments() {
            return new Type[] { String.class, SoundMetadataConfig.class };
        }/*from w w w.j  av a  2 s  . c om*/

        public Type getRawType() {
            return Map.class;
        }

        public Type getOwnerType() {
            return null;
        }
    };

    try (final InputStream stream = SoundRegistry.class.getResourceAsStream("/assets/dsurround/sounds.json")) {
        if (stream != null) {
            @SuppressWarnings("unchecked")
            final Map<String, SoundMetadataConfig> sounds = (Map<String, SoundMetadataConfig>) new Gson()
                    .fromJson(new InputStreamReader(stream), TYPE);
            for (final Entry<String, SoundMetadataConfig> e : sounds.entrySet()) {
                final String soundName = e.getKey();
                final SoundMetadata data = new SoundMetadata(e.getValue());
                final ResourceLocation resource = new ResourceLocation(DSurround.RESOURCE_ID, soundName);
                SoundUtils.getOrRegisterSound(resource);
                soundMetadata.put(resource, data);
            }
        }
    } catch (final Throwable t) {
        DSurround.log().error("Unable to read the mod sound file!", t);
    }

}