Example usage for com.google.common.reflect TypeToken of

List of usage examples for com.google.common.reflect TypeToken of

Introduction

In this page you can find the example usage for com.google.common.reflect TypeToken of.

Prototype

public static TypeToken<?> of(Type type) 

Source Link

Document

Returns an instance of type token that wraps type .

Usage

From source file:com.twitter.common.args.parsers.ListParser.java

@Override
List<?> doParse(final ParserOracle parserOracle, String raw, final List<Type> typeParams) {
    final Type listType = typeParams.get(0);
    final Parser<?> parser = parserOracle.get(TypeToken.of(listType));
    return ImmutableList.copyOf(
            Iterables.transform(Parsers.MULTI_VALUE_SPLITTER.split(raw), new Function<String, Object>() {
                @Override//from   w w w .j  a v  a2  s. co m
                public Object apply(String raw) {
                    return parser.parse(parserOracle, listType, raw);
                }
            }));
}

From source file:io.github.katrix_.chitchat.chat.UserChitChatSerializer.java

@Override
public UserChitChat deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
    UUID uuid = value.getNode("uuid").getValue(TypeToken.of(UUID.class));
    String channelName = value.getNode("channel").getString();

    if (uuid == null || channelName == null)
        throw new ObjectMappingException("Required values for channel not found");

    ChannelChitChat channel;//w  w w . jav a  2s. co m

    if (ChitChatChannels.existName(channelName)) {
        channel = ChitChatChannels.get(channelName);
    } else {
        channel = ChitChatChannels.getGlobal();
    }

    return new UserChitChat(uuid, channel);
}

From source file:edu.washington.cs.cupid.wizards.popup.actions.NewMappingCapabilityAction.java

/**
 * @see IActionDelegate#run(IAction)//  w  w  w. ja v  a2 s. com
 */
public void run(IAction action) {
    Class<?> clazz = ((IStructuredSelection) selection).getFirstElement().getClass();

    MappingWizard wizard = new MappingWizard(TypeToken.of(clazz));
    WizardDialog dialog = new WizardDialog(shell, wizard);
    dialog.create();
    dialog.open();
}

From source file:ninja.leaping.permissionsex.backend.file.SchemaMigrations.java

static ConfigurationTransformation threeToFour() {
    return ConfigurationTransformation.chain(tBuilder()
            .addAction(new Object[] { "worlds", WILDCARD_OBJECT, "inheritance" }, (inputPath, valueAtPath) -> {
                try {
                    valueAtPath.setValue(Lists.transform(valueAtPath.getList(TypeToken.of(String.class)),
                            input -> "world:" + input));
                } catch (ObjectMappingException e) {
                    throw new RuntimeException(e);
                }/* w  ww  .j  av a 2 s  . c  o m*/

                return new Object[] { "context-inheritance", "world:" + inputPath.get(1) };
            }).build(), tBuilder().addAction(new Object[] { "worlds" }, (inputPath, valueAtPath) -> {
                valueAtPath.setValue(null);
                return null;
            }).build());
}

From source file:com.twitter.common.args.parsers.SetParser.java

@Override
Set<?> doParse(final ParserOracle parserOracle, String raw, List<Type> typeParams) {
    final Type setType = typeParams.get(0);
    final Parser<?> parser = parserOracle.get(TypeToken.of(setType));

    return ImmutableSet.copyOf(
            Iterables.transform(Parsers.MULTI_VALUE_SPLITTER.split(raw), new Function<String, Object>() {
                @Override/*w w  w.  j a  v a2  s  . c  om*/
                public Object apply(String raw) {
                    return parser.parse(parserOracle, setType, raw);
                }
            }));
}

From source file:edu.washington.cs.cupid.standard.NonEmpty.java

@Override
public TypeToken<Boolean> getOutputType() {
    return TypeToken.of(Boolean.class);
}

From source file:org.apache.brooklyn.util.core.flags.MethodCoercions.java

/**
 * Returns a predicate that matches a method with the given name, and a single parameter that
 * {@link org.apache.brooklyn.util.core.flags.TypeCoercions#tryCoerce(Object, com.google.common.reflect.TypeToken)} can process
 * from the given argument.// ww  w .ja v  a 2s  . c o m
 *
 * @param methodName name of the method
 * @param argument argument that is intended to be given
 * @return a predicate that will match a compatible method
 */
public static Predicate<Method> matchSingleParameterMethod(final String methodName, final Object argument) {
    checkNotNull(methodName, "methodName");
    checkNotNull(argument, "argument");

    return new Predicate<Method>() {
        @Override
        public boolean apply(@Nullable Method input) {
            if (input == null)
                return false;
            if (!input.getName().equals(methodName))
                return false;
            Type[] parameterTypes = input.getGenericParameterTypes();
            return parameterTypes.length == 1
                    && TypeCoercions.tryCoerce(argument, TypeToken.of(parameterTypes[0])).isPresentAndNonNull();

        }
    };
}

From source file:edu.washington.cs.cupid.egit.GitHistoryCapability.java

/**
 * Constructs capability that returns the Git history from a single line of descent (i.e., branch) for
 * a resource.//  w  w w .  java 2s . c  o  m
 */
public GitHistoryCapability() {
    super("Git History", "Git log entries for the resource. The most recent commit is FIRST.",
            TypeToken.of(IResource.class), new TypeToken<List<IFileRevision>>() {
            }, Flag.PURE, Flag.TRANSIENT);
}

From source file:org.jclouds.karaf.chef.commands.completer.ChefApiCompleter.java

@Override
public int complete(String buffer, int cursor, List<String> candidates) {
    try {// w w w  . j  av  a 2  s .c o m
        if (displayApisWithoutService) {
            for (ApiMetadata apiMetadata : Apis.contextAssignableFrom(TypeToken.of(ChefContext.class))) {
                delegate.getStrings().add(apiMetadata.getId());
            }
        } else if (chefServices != null) {
            for (ChefService chefService : chefServices) {
                String api = chefService.getContext().unwrap().getId();
                if (Apis.withId(api) != null) {
                    delegate.getStrings().add(api);
                }
            }
        }
    } catch (Exception ex) {
        // noop
    }
    return delegate.complete(buffer, cursor, candidates);
}

From source file:com.twitter.common.args.parsers.TimeDurationParser.java

@Override
public Duration parse(ParserOracle parserOracle, Type type, String raw) throws IllegalArgumentException {
    Parser<?> amountParser = parserOracle.get(TypeToken.of(Amount.class));

    @SuppressWarnings("unchecked")
    Amount<Long, Time> parsed = (Amount<Long, Time>) amountParser.parse(parserOracle, TIME_AMOUNT_TYPE, raw);
    return Duration.fromTimeUnit(parsed.getValue(), parsed.getUnit().getTimeUnit());
}