Java Code Examples for com.google.common.collect.Lists.transform()

The following are Jave code examples for showing how to use transform() of the com.google.common.collect.Lists class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Equella   File: TermServiceImpl.java   View Source Code Vote up 7 votes
@Override
public Pair<Long, List<TermResult>> searchTerms(Taxonomy taxonomy, String query, SelectionRestriction restriction,
	int limit, boolean searchFullTerms)
{
	final String searchField = (searchFullTerms ? "fullValue" : "value");
	final Criterion c1 = Restrictions.eq("taxonomy", taxonomy);
	final Criterion c2 = Restrictions.ilike(searchField, query.replace('*', '%'));
	final Criterion c3 = getSearchRestrictionCriterion(restriction);
	final long totalCount = termDao.countByCriteria(c1, c2, c3);

	List<TermResult> results = Collections.emptyList();
	if( totalCount > 0 )
	{
		List<Term> terms = termDao.findAllByCriteria(Order.asc(searchField), -1, limit, c1, c2, c3);
		results = Lists.transform(terms, new Function<Term, TermResult>()
		{
			@Override
			public TermResult apply(Term term)
			{
				return new TermResult(term.getValue(), term.getFullValue(), term.isLeaf());
			}
		});
	}

	return new Pair<Long, List<TermResult>>(totalCount, results);
}
 
Example 2
Project: googles-monorepo-demo   File: LineBufferTest.java   View Source Code Vote up 6 votes
private static void bufferHelper(String input, String... expect)
    throws IOException {

  List<String> expectProcess = Arrays.asList(expect);
  List<String> expectRead = Lists.transform(expectProcess,
      new Function<String, String>() {
        @Override
        public String apply(String value) {
          return value.replaceAll("[\\r\\n]", "");
        }
      });

  for (int chunk : CHUNK_SIZES) {
    chunk = Math.max(1, Math.min(chunk, input.length()));
    assertEquals(expectProcess, bufferHelper(input, chunk));
    assertEquals(expectRead, readUsingJava(input, chunk));
    assertEquals(expectRead, readUsingReader(input, chunk, true));
    assertEquals(expectRead, readUsingReader(input, chunk, false));
  }
}
 
Example 3
Project: Equella   File: UtilsScriptWrapper.java   View Source Code Vote up 6 votes
@Override
public List<ItemScriptType> getResults()
{
	if( resultList == null )
	{
		resultList = Lists.transform(results.getResults(), new Function<Item, ItemScriptType>()
		{
			@Override
			public ItemScriptType apply(Item item)
			{
				return new ItemScriptTypeImpl(itemService, itemHelper, item);
			}
		});
	}
	return resultList;
}
 
Example 4
Project: Equella   File: RoleSelectorWebControl.java   View Source Code Vote up 6 votes
@Override
public List<SelectedRole> getCurrentSelectedRoles(final SectionInfo info)
{
	return Lists.transform(storageControl.getValues(), new Function<String, SelectedRole>()
	{
		@Override
		public SelectedRole apply(String id)
		{
			final RoleBean roleBean = userService.getInformationForRole(id);
			final String displayName;
			if( roleBean == null )
			{
				displayName = id;
			}
			else
			{
				displayName = Format.format(roleBean);
			}
			return new SelectedRole(id, displayName);
		}
	});
}
 
Example 5
Project: Elasticsearch   File: DocKeys.java   View Source Code Vote up 5 votes
public Optional<List<BytesRef>> partitionValues() {
    if (partitionIdx == null || partitionIdx.isEmpty()) {
        return Optional.absent();
    }
    List<BytesRef> values = Lists.transform(partitionIdx, new Function<Integer, BytesRef>() {
        @Nullable
        @Override
        public BytesRef apply(Integer input) {
            return ValueSymbolVisitor.BYTES_REF.process(key.get(input));
        }
    });
    return Optional.of(values);
}
 
Example 6
Project: Equella   File: DynamicPrivilegeTreeNode.java   View Source Code Vote up 5 votes
public static List<SecurityTreeNode> getSecurityTargetsAsTreeNodes(final PluginService pluginService,
	final RemotePrivilegeTreeService service, final SecurityTarget target)
{
	return Lists.transform(service.getChildTargets(target), new Function<SecurityTarget, SecurityTreeNode>()
	{
		@Override
		public SecurityTreeNode apply(SecurityTarget input)
		{
			return new DynamicPrivilegeTreeNode(pluginService, service, input);
		}
	});
}
 
Example 7
Project: dremio-oss   File: DatasetSummary.java   View Source Code Vote up 5 votes
public static DatasetSummary newInstance(DatasetConfig datasetConfig, int jobCount, int descendants)
    throws NamespaceException {
  List<String> fullPath = datasetConfig.getFullPathList();

  DatasetType datasetType = datasetConfig.getType();
  List<Field> fields;
  DatasetVersion datasetVersion;

  List<com.dremio.dac.model.common.Field> fieldList = DatasetsUtil.getFieldsFromDatasetConfig(datasetConfig);
  if (fieldList == null) {
    fields = null;
  } else {
    fields = Lists.transform(fieldList, new Function<com.dremio.dac.model.common.Field, Field>() {
      @Override
      public Field apply(com.dremio.dac.model.common.Field input) {
        return new Field(input.getName(), input.getType().name());
      }
    });
  }

  if (datasetType == DatasetType.VIRTUAL_DATASET) {
    final VirtualDataset virtualDataset = datasetConfig.getVirtualDataset();
    datasetVersion = virtualDataset.getVersion();
  } else {
    datasetVersion = null;
  }

  return new DatasetSummary(fullPath, jobCount, descendants, fields, datasetType, datasetVersion);
}
 
Example 8
Project: Reer   File: CrossVersionPerformanceTestHistory.java   View Source Code Vote up 5 votes
public List<MeasuredOperationList> getScenarios() {
    return Lists.transform(getKnownVersions(), new Function<String, MeasuredOperationList>() {
        public MeasuredOperationList apply(String version) {
            return result.version(version).getResults();
        }
    });
}
 
Example 9
Project: Equella   File: CloudServiceImpl.java   View Source Code Vote up 5 votes
@Override
public List<NameValue> call()
{
	final CloudFacetSearchResults searchResults = facetSearch(facet);
	final List<NameValue> nameVals = new ArrayList<>(
		Lists.transform(searchResults.getResults(), getTransformer()));
	clean(nameVals);
	Collections.sort(nameVals, new NameValueComparator());
	return nameVals;
}
 
Example 10
Project: Pogamut3   File: RaycastDataFileTools.java   View Source Code Vote up 5 votes
static List<RaycastRequest> resultsToRequests( List<PrecomputedRaycastResult> results ) {
	return Lists.transform(
			results,
			new Function<PrecomputedRaycastResult, RaycastRequest>() {
				@Override
				public RaycastRequest apply(PrecomputedRaycastResult input) {
					return input.request;
				}
			}
		);
}
 
Example 11
Project: dremio-oss   File: Views.java   View Source Code Vote up 5 votes
public static List<FieldType> relDataTypeToFieldType(final RelDataType rowType) {
  return Lists.transform(rowType.getFieldList(), new Function<RelDataTypeField, FieldType>() {
    @Nullable
    @Override
    public FieldType apply(@Nullable final RelDataTypeField field) {
      return new FieldType(field.getName(), field.getType());
    }
  });
}
 
Example 12
Project: GitHub   File: RequestOptionsGenerator.java   View Source Code Vote up 5 votes
private List<MethodSpec> generateInstanceMethodOverridesForRequestOptions() {
  return Lists.transform(
      processorUtil.findInstanceMethodsReturning(requestOptionsType, requestOptionsType),
      new Function<ExecutableElement, MethodSpec>() {
        @Override
        public MethodSpec apply(ExecutableElement input) {
          return generateRequestOptionOverride(input);
        }
      });
}
 
Example 13
Project: azure-libraries-for-java   File: RedisCacheImpl.java   View Source Code Vote up 5 votes
@Override
public List<ScheduleEntry> listPatchSchedules() {
    RedisPatchScheduleInner patchSchedules =  this.manager().inner().patchSchedules().get(resourceGroupName(), name());
    if (patchSchedules != null) {
        return Lists.transform(patchSchedules.scheduleEntries(),
                new Function<ScheduleEntryInner, ScheduleEntry>() {
                    public ScheduleEntry apply(ScheduleEntryInner entryInner) {
                        return new ScheduleEntry(entryInner);
                    }
                });
    }
    return null;
}
 
Example 14
Project: airsonic   File: MediaFile.java   View Source Code Vote up 4 votes
public static List<Integer> toIdList(List<MediaFile> from) {
    return Lists.transform(from, toId());
}
 
Example 15
Project: Equella   File: ShowSelectionHomePortalsSection.java   View Source Code Vote up 4 votes
private synchronized Pair<List<SectionId>, List<SectionId>> getPortalLayout(RenderEventContext context)
{
	if( portletLayout == null )
	{
		List<LayoutData> left = new ArrayList<LayoutData>();
		List<LayoutData> right = new ArrayList<LayoutData>();
		List<LayoutData> dynamic = new ArrayList<LayoutData>();

		List<SectionId> childIds = context.getChildIds(this);
		for( SectionId childId : childIds )
		{
			LayoutData data = new LayoutData();
			String idStr = childId.getSectionId();
			data.setSectionId(childId);

			String layout = context.getLayout(idStr);
			try
			{
				JSONObject json = JSONObject.fromObject(layout);
				data.setOrder(json.getInt("order")); //$NON-NLS-1$

				if( json.get("column").equals("dynamic") ) //$NON-NLS-1$//$NON-NLS-2$
				{
					dynamic.add(data);
				}
				else
				{
					(json.get("column").equals("left") ? left : right).add(data); //$NON-NLS-1$ //$NON-NLS-2$
				}
			}
			catch( RuntimeException ex )
			{
				throw new SectionsRuntimeException("The layout property for " + childId
					+ " is missing or incorrect.  Must be in JSON format with properties"
					+ " \"{order: 1234, column: 'left'|'right'}\", but it was \"" + layout + "\"", ex);
			}
		}

		Collections.sort(left, NumberOrderComparator.LOWEST_FIRST);
		Collections.sort(right, NumberOrderComparator.LOWEST_FIRST);

		portletLayout = new Pair<List<SectionId>, List<SectionId>>(Lists.transform(left, DATA_TO_SECTION_ID),
			Lists.transform(right, DATA_TO_SECTION_ID));

		dymanicPortals = Lists.transform(dynamic, DATA_TO_SECTION_ID);
	}

	return portletLayout;
}
 
Example 16
Project: generator-thundr-gae-react   File: UserController.java   View Source Code Vote up 4 votes
@Authenticated
@Authorised(any = Roles.Admin)
public JsonView search(String email) {
    return new JsonView(Lists.transform(userService.search(email), TO_USER_DTO));
}
 
Example 17
Project: ProjectAres   File: Tournament.java   View Source Code Vote up 4 votes
default List<String> acceptedTeamNames() {
    return Lists.transform(accepted_teams(), team.Id::name);
}
 
Example 18
Project: Reer   File: CrossVersionPerformanceTestHistory.java   View Source Code Vote up 4 votes
@Override
public List<? extends ScenarioDefinition> getScenarios() {
    if (newestFirst.isEmpty()) {
        return Collections.emptyList();
    }
    final CrossVersionPerformanceResults mostRecent = newestFirst.get(0);
    return Lists.transform(getKnownVersions(), new Function<String, ScenarioDefinition>() {
        @Override
        public ScenarioDefinition apply(final String input) {
            return new ScenarioDefinition() {
                @Override
                public String getDisplayName() {
                    return input;
                }

                @Override
                public String getTestProject() {
                    return mostRecent.getTestProject();
                }

                @Override
                public List<String> getTasks() {
                    return mostRecent.getTasks();
                }

                @Override
                public List<String> getArgs() {
                    return mostRecent.getArgs();
                }

                @Nullable
                @Override
                public List<String> getGradleOpts() {
                    return mostRecent.getGradleOpts();
                }

                @Nullable
                @Override
                public Boolean getDaemon() {
                    return mostRecent.getDaemon();
                }
            };
        }
    });
}
 
Example 19
Project: ProjectAres   File: Node.java   View Source Code Vote up 4 votes
public static List<Node> fromAttrs(Element el) throws InvalidXMLException {
    return Lists.transform(el.getAttributes(), Node::of);
}
 
Example 20
Project: eds   File: DispatcherRouter.java   View Source Code Vote up 4 votes
@Override
	public void configure() throws Exception {
//		camelContext.setTracing(true);
	  onException(Exception.class)
  	  .handled(false)
  	  .bean("dispatcherHelper","error");
		errorHandler(
				defaultErrorHandler()
				.maximumRedeliveries(6) // 消费6次不成功进入死信队列 -1 永远不进入死信队列
				.logger(new CamelLogger(LoggerNames.DISPATCH_ERROR_LOGGER, LoggingLevel.ERROR))
				.retryAttemptedLogLevel(LoggingLevel.WARN)
				.backOffMultiplier(1.5)  // 指数退避
				.useExponentialBackOff()
				);
		Set<String> enabledGroupSet = dispatcherConfig.getEnabledDispatchGroupSet();
		Set<String> enabledNameSet = dispatcherConfig.getEnabledDispatchNameSet();
		// 控制开关 shutdown hook
		for(final Element ele : dispatcherConfig.getList()){
		  String name = ele.getName();
		  if(enabledNameSet.size() > 0 && !enabledNameSet.contains(name)){
		    continue;
		  }
		  String group = ele.getGroup();
		  if(enabledGroupSet.size() > 0 && !enabledGroupSet.contains(group)){
		    continue;
		  }
			String from = ele.getFromProtocol() + ':' + EdsConstants.QUEUE_PREFIX + ele.getFrom();
			List<String> to = ele.getTo();
			to = Lists.transform(to,new Function<String,String>() {
				@Override
				public String apply(String input) {
					return ele.getToProtocol() + ':' +EdsConstants.QUEUE_PREFIX + input;
				}
			});
			int poolSize = ele.getConcurrencyMin();
			int maxPoolSize = ele.getConcurrencyMax();
			String[] tos = new String[to.size()];
			tos = to.toArray(tos);
			// 定义dispatch routes
//			RouteDefinition rd = 
			from(from)
			  .routeId("dispath_"+name)
			  .id(name)
			  .transacted()
			  .threads(poolSize, maxPoolSize, threadPoolProfile.getId())
			  .bean("dispatcherHelper","before")
  			  .log(LoggingLevel.INFO, LoggerNames.DISPATCH_LOGGER, "${headers}|${body}")
  			  .multicast()
   			  .to(tos)
 			  .bean("dispatcherHelper","success");
		}
	}