List of usage examples for com.google.common.collect Collections2 transform
public static <F, T> Collection<T> transform(Collection<F> fromCollection, Function<? super F, T> function)
From source file:mocks.HelloCDIServiceMock.java
@Override public Hellos getHellos() { return Hellos.builder().helloCollection(Lists .newArrayList(Collections2.transform(mockedMessageStrings, new Function<HelloEntity, String>() { @Override//from w ww . j av a 2 s . c o m public String apply(HelloEntity arg0) { return arg0.getHelloMessage(); } }))).build(); }
From source file:com.lyndir.lhunath.opal.wayward.behavior.CSSClassAttributeAppender.java
/** * @param cssClassModels Models that provides CSS classes to append to the element's <code>class</code> attribute. * * @return An appender which appends all the CSS classes in the collection from the given model to a component's HTML element. *//*ww w. ja v a 2 s . c o m*/ public static CSSClassAttributeAppender of(final IModel<?>... cssClassModels) { return ofList(new AbstractReadOnlyModel<Collection<String>>() { @Override public Collection<String> getObject() { return Collections2.transform(Arrays.asList(cssClassModels), new Function<IModel<?>, String>() { @Nullable @Override public String apply(final IModel<?> from) { return from.getObject() == null ? null : String.valueOf(from.getObject()); } }); } }); }
From source file:org.zanata.util.WebElementUtil.java
/** * This method potentially will suffer from StaleElementException if the * WebElements given are dynamic elements on the page. If so consider using * #elementsToText(org.openqa.selenium.WebDriver, org.openqa.selenium.By) * instead./*from w w w.j ava 2s . c om*/ * * @param webElements * collection of WebElement * @return text representation of the elements */ public static List<String> elementsToText(Collection<WebElement> webElements) { return ImmutableList.copyOf(Collections2.transform(webElements, WebElementToTextFunction.FUNCTION)); }
From source file:gt.org.ms.api.utils.EntitiesHelper.java
public static List<Persona> getPersonas(List<PersonaChildEntity> pc) { return new ArrayList<Persona>(Collections2.transform(pc, new Function<PersonaChildEntity, Persona>() { @Override//w w w . j av a2 s . com public Persona apply(PersonaChildEntity f) { return f.getFkPersona(); } })); }
From source file:pl.softech.eav.example.Util.java
private static String toString(MyObject object, final int ntabs) { if (object == null) { return null; }// w w w. j a v a 2 s. c om SimpleToStringBuilder sb = new SimpleToStringBuilder("MyObject", ntabs); sb.add("name", object.getName()); sb.add("category", object.getCategory().getIdentifier().getIdentifier()); sb.add("values", collectionToString(Collections2.transform(object.getValues(), new Function<ObjectValue, String>() { @Override public String apply(ObjectValue input) { return Util.toString(input, ntabs + 2); } }), ntabs + 1)); return sb.toString(); }
From source file:io.joynr.capabilities.ProviderQosPersisted.java
public ProviderQosPersisted(final String participantId, ProviderQos providerQos) { super(Collections2.transform(Arrays.asList(providerQos.getCustomParameters()), new Function<CustomParameter, CustomParameterPersisted>() { @Override/*from ww w .j av a 2s .c o m*/ public CustomParameterPersisted apply(CustomParameter input) { return new CustomParameterPersisted(participantId, input); } }).toArray(new CustomParameter[providerQos.getCustomParameters().length]), providerQos.getProviderVersion(), providerQos.getPriority(), providerQos.getScope(), providerQos.getSupportsOnChangeSubscriptions()); this.participantId = participantId; }
From source file:org.terasology.logic.console.ui.ConsoleTabCompletionEngine.java
@Override public String complete(String text) { String cmdQuery = text.trim(); List<CommandInfo> commands = console.getCommandList(); // Explicitly create a map String->CommandInfo if the CommandInfo is required later Collection<String> commandNames = Collections2.transform(commands, new Function<CommandInfo, String>() { @Override/*from ww w. j a v a 2 s .c om*/ public String apply(CommandInfo input) { return input.getName(); } }); Collection<String> matches = CamelCaseMatcher.getMatches(cmdQuery, commandNames); //one match found if (matches.size() == 1) { return matches.iterator().next(); } else if (matches.size() > 1) { //multiple matches found //add list of available commands StringBuilder commandMatches = new StringBuilder(); for (String cmd : matches) { if (commandMatches.length() != 0) { commandMatches.append(" "); } commandMatches.append(cmd); } console.addMessage(commandMatches.toString()); } return text; }
From source file:gt.org.ms.controller.roles.handlers.ModificarHandler.java
@Override public RoleDto execute(final RoleDto request) { final Role r = roles.findOne(request.getId()); accesosRole.deleteInBatch(r.getAccesoRoleCollection()); r.setNombre(request.getNombre());//from w w w.j a v a 2 s .c o m r.setAccesoRoleCollection(null); r.setEstado(Estado.ACTIVO); final Role r2 = roles.save(r); r2.setAccesoRoleCollection( Collections2.transform(request.getAccesos(), new Function<AccesoDto, AccesoRole>() { @Override public AccesoRole apply(AccesoDto f) { AccesoRole acceso = new AccesoRole(); acceso.setFkAcceso(accesos.findOne(f.getId())); acceso.setFkRole(r2); setCreateInfo(acceso); return acceso; } })); accesosRole.save(r2.getAccesoRoleCollection()); return request; }
From source file:pl.kodujdlapolski.na4lapy.utils.formvalidator.FormValidator.java
public List<ValidationError> validateForm() { return Lists.newArrayList(Collections2.transform(getErrorFields(), new Function<Rule, ValidationError>() { @Nullable// w w w .ja v a 2 s . c o m @Override public ValidationError apply(Rule validationRule) { validationRule.setErrorMessage(context.getString(validationRule.getErrorMessageResourceId())); return new ValidationError((View) validationRule.getView(), validationRule.getErrorMessageResourceId(), validationRule.getValidationCode()); } @Override public boolean equals(Object object) { return false; } })); }
From source file:org.mandarax.dsl.verification.CheckFreeVariablesInFacts.java
@Override public void verify(Collection<CompilationUnit> cus, VerificationErrorReporter errorHandler) throws VerificationException { for (CompilationUnit cu : cus) { // collect declared objects Collection<String> objNames = Collections2.transform(cu.getObjectDeclarations(), new Function<ObjectDeclaration, String>() { @Override/*from w ww.ja v a2 s. co m*/ public String apply(ObjectDeclaration obj) { return obj.getName(); } }); for (RelationshipDefinition rel : cu.getRelationshipDefinitions()) { for (Rule rule : rel.getRules()) { if (rule.isFact()) { for (Variable var : rule.getHead().getVariables()) { if (!objNames.contains(var.getName())) { errorHandler.reportError(cu, "The term ", var, " at ", rule.getPosition(), " in the fact ", rule.getId(), " cannot be a free variable"); } } } } } } }