Example usage for com.google.common.collect Iterables toArray

List of usage examples for com.google.common.collect Iterables toArray

Introduction

In this page you can find the example usage for com.google.common.collect Iterables toArray.

Prototype

static <T> T[] toArray(Iterable<? extends T> iterable, T[] array) 

Source Link

Usage

From source file:org.eclipse.wb.internal.swing.model.bean.AbstractActionInfo.java

/**
 * @return the new {@link Action} property.
 *//*from  w  w w  . j  a  va 2 s .  com*/
private Property createProperty(String title, String keyName, ExpressionConverter converter,
        PropertyEditor editor) throws Exception {
    List<ExpressionAccessor> accessors = getAccessors(keyName);
    // may be no accessors
    if (accessors.isEmpty()) {
        return null;
    }
    // create property
    return new GenericPropertyImpl(this, title, Iterables.toArray(accessors, ExpressionAccessor.class),
            Property.UNKNOWN_VALUE, converter, editor);
}

From source file:bio.gcat.Parameter.java

public Parameter(String key, String label, Object value, Object[] options) {
    this(key, label, value, options, (String[]) Iterables
            .toArray(Iterables.transform(Arrays.asList(options), new Function<Object, String>() {
                @Override//w  ww .  j a v  a2s  .c o  m
                public String apply(Object option) {
                    return option != null ? option.toString() : null;
                }
            }), String.class));
}

From source file:org.splevo.jamopp.refactoring.java.caslicensehandler.cheatsheet.actions.CASLicenseHandlerConfiguration.java

private String[] getAllLicensesBy(ConcreteClassifier classifier) {
    return Iterables.toArray(Iterables.transform(classifier.getFields(), new Function<Field, String>() {
        @Override/*from  ww w  . j  a  v  a 2  s. co  m*/
        public String apply(Field input) {
            return input.getName();
        }
    }), String.class);
}

From source file:com.atlassian.plugins.studio.storage.examples.it.IntegrationTestServlet.java

private Method[] getTests(Object instance) {
    return Iterables.toArray(Iterables.<Method>filter(
            Arrays.<Method>asList(instance.getClass().getDeclaredMethods()), new Predicate<Method>() {
                @Override// w  w w . j  av  a 2 s. c o  m
                public boolean apply(@Nullable Method input) {
                    ToolkitTest marker = input.getAnnotation(ToolkitTest.class);
                    return marker != null && !marker.ignore();
                }
            }), Method.class);
}

From source file:org.asoem.greyfish.core.actions.ContractNetInitiatorAction.java

private static MessageTemplate createAcceptReplyTemplate(
        final Iterable<? extends ACLMessage<?>> acceptMessages) {
    if (Iterables.isEmpty(acceptMessages)) {
        return MessageTemplates.alwaysFalse();
    } else {//  ww w  . ja  v  a2  s  .  co  m
        return MessageTemplates.or( // is a reply
                Iterables.toArray(
                        Iterables.transform(acceptMessages, new Function<ACLMessage, MessageTemplate>() {
                            @Override
                            public MessageTemplate apply(final ACLMessage aclMessage) {
                                return MessageTemplates.isReplyTo(aclMessage);
                            }
                        }), MessageTemplate.class));
    }
}

From source file:org.eclipse.emf.compare.ide.ui.internal.handler.EMFComparisonSourceActionHandler.java

private IEMFComparisonSource[] adaptSelection(Collection<?> selection) {
    final IAdapterManager adapterManager = Platform.getAdapterManager();
    final Iterable<IEMFComparisonSource> sources = Iterables.transform(selection,
            new Function<Object, IEMFComparisonSource>() {
                public IEMFComparisonSource apply(Object input) {
                    return (IEMFComparisonSource) adapterManager.loadAdapter(input,
                            IEMFComparisonSource.class.getName());
                }/*from w w w  . j  av  a  2  s  .  com*/
            });
    return Iterables.toArray(sources, IEMFComparisonSource.class);
}

From source file:it.smartcommunitylab.aac.controller.ResourceAccessController.java

@ApiOperation(value = "Get token info")
@RequestMapping(method = RequestMethod.GET, value = "/resources/token")
@Deprecated//from  w w  w . j a  va  2s  .  com
public @ResponseBody AACTokenValidation getTokenInfo(HttpServletRequest request, HttpServletResponse response) {
    AACTokenValidation result = new AACTokenValidation();

    try {
        String parsedToken = it.smartcommunitylab.aac.common.Utils.parseHeaderToken(request);

        OAuth2Authentication auth = resourceServerTokenServices.loadAuthentication(parsedToken);

        OAuth2AccessToken storedToken = tokenStore.getAccessToken(auth);
        long expiresIn = storedToken.getExpiresIn();

        String clientId = auth.getOAuth2Request().getClientId();

        ObjectMapper mapper = new ObjectMapper();
        mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
                .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
                .withGetterVisibility(JsonAutoDetect.Visibility.ANY)
                .withSetterVisibility(JsonAutoDetect.Visibility.ANY)
                .withCreatorVisibility(JsonAutoDetect.Visibility.ANY));

        String userName = null;
        String userId = null;
        boolean applicationToken = false;

        //         System.err.println(auth.getPrincipal());

        if (auth.getPrincipal() instanceof User) {
            User principal = (User) auth.getPrincipal();
            userId = principal.getUsername();
            //         } if (auth.getPrincipal() instanceof it.smartcommunitylab.aac.model.User) { 
            //            it.smartcommunitylab.aac.model.User principal = (it.smartcommunitylab.aac.model.User)auth.getPrincipal();
            //            userId = principal.getId().toString();
            //            userName = getWSO2Name(user);
        } else {
            ClientDetailsEntity client = clientDetailsRepository.findByClientId(clientId);
            applicationToken = true;
            userId = "" + client.getDeveloperId();
            //            if (client.getParameters() != null) {
            //               Map<String,?> parameters = mapper.readValue(client.getParameters(), Map.class);
            //               userName = (String)parameters.get("username");
            //            } else {
            ////               it.smartcommunitylab.aac.model.User user = userRepository.findOne(Long.parseLong(userId));
            //               userName = "admin";
            //               userName = (String)auth.getPrincipal();
            //            }
        }
        userName = userManager.getUserInternalName(Long.parseLong(userId));

        result.setUsername(userName);
        result.setUserId(userId);
        result.setClientId(clientId);
        result.setScope(Iterables.toArray(auth.getOAuth2Request().getScope(), String.class));
        result.setGrantType(auth.getOAuth2Request().getGrantType());

        long now = System.currentTimeMillis();
        result.setIssuedTime(now);
        result.setValidityPeriod(expiresIn);

        logger.info("Requested token " + parsedToken + " expires in " + result.getValidityPeriod());

        result.setValid(true);

        result.setApplicationToken(applicationToken);

        //         System.err.println(mapper.writeValueAsString(response));         
    } catch (InvalidTokenException e) {
        logger.error("Invalid token: " + e.getMessage());
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return null;
    } catch (Exception e) {
        logger.error("Error getting info for token: " + e.getMessage());
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }

    return result;
}

From source file:com.mattc.argus2.concurrent.Decompressors.java

/**
 * Reload Reflections Object. Scans all classes in our classpath. <br />
 * <br />/*from w ww. j  av  a 2s  .  c  o  m*/
 * This process is SLOW, it should be done rarely. It is guaranteed to occur< br/>
 * once on initialization.
 */
private static long reloadReflector() {
    final long start = System.currentTimeMillis();
    final Collection<URL> urls = ClasspathHelper.forJavaClassPath();
    urls.addAll(ClasspathHelper.forClassLoader(Iterables.toArray(loaders, ClassLoader.class)));

    reflector = new Reflections(new ConfigurationBuilder().useParallelExecutor()
            // Scan All Classes on java.class.path
            .setUrls(urls)
            // Scan All ClassLoaders Registered
            .addClassLoaders(loaders)
            // Only Include Subtypes of DecompressProcess who are Annotated
            // with @Decompressor
            .setScanners(new SubTypesScanner().filterResultsBy(sPredicate)));

    return System.currentTimeMillis() - start;
}

From source file:dagger.internal.codegen.SourceFiles.java

static TypeName parameterizedGeneratedTypeNameForBinding(Binding binding) {
    ClassName className = generatedClassNameForBinding(binding);
    ImmutableList<TypeVariableName> typeParameters = bindingTypeElementTypeVariableNames(binding);
    return typeParameters.isEmpty() ? className
            : ParameterizedTypeName.get(className, Iterables.toArray(typeParameters, TypeName.class));
}

From source file:buildcraft.core.InterModComms.java

public static void processAddFacadeIMC(IMCEvent event, IMCMessage m) {
    try {//from ww w.  j a v  a2  s. c  o  m
        if (m.isStringMessage()) {
            Splitter splitter = Splitter.on("@").trimResults();

            String[] array = Iterables.toArray(splitter.split(m.getStringValue()), String.class);
            if (array.length != 2) {
                BCLog.logger.info(String.format("Received an invalid add-facade request %s from mod %s",
                        m.getStringValue(), m.getSender()));
            } else {
                String blockName = array[0];
                Integer metaId = Ints.tryParse(array[1]);

                if (Strings.isNullOrEmpty(blockName) || metaId == null) {
                    BCLog.logger.info(String.format("Received an invalid add-facade request %s from mod %s",
                            m.getStringValue(), m.getSender()));
                } else {
                    Block block = (Block) Block.blockRegistry.getObject(blockName);
                    if (block.getRenderType() != 0 && block.getRenderType() != 31) {
                        BuildCraftTransport.facadeItem.addFacade(new ItemStack(block, 1, metaId));
                    } else {
                        logRedundantAddFacadeMessage(m, block.toString());
                    }
                }
            }
        } else if (m.isItemStackMessage()) {
            ItemStack modItemStack = m.getItemStackValue();

            Block block = Block.getBlockFromItem(modItemStack.getItem());
            if (block != null && block.getRenderType() != 0 && block.getRenderType() != 31) {
                BuildCraftTransport.facadeItem.addFacade(modItemStack);
            } else if (block != null) {
                logRedundantAddFacadeMessage(m, block.toString());
            }
        }
    } catch (Exception ex) {
    }
}