use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class PagingUtil method createLinkHeader.
/**
* Generates link header value from the page object and base uri.
* <a href="https://tools.ietf.org/html/rfc5988">The Link header spec</a>
*
* @param page
* the page used to generate link
* @param uri
* the uri which is used for adding {@code skipCount} & {@code maxItems} query parameters
* @return 'Link' header value
* @throws NullPointerException
* when either {@code page} or {@code uri} is null
*/
public static String createLinkHeader(Page<?> page, URI uri) {
requireNonNull(page, "Required non-null page");
requireNonNull(uri, "Required non-null uri");
final ArrayList<Pair<String, Page.PageRef>> pageRefs = new ArrayList<>(4);
pageRefs.add(Pair.of("first", page.getFirstPageRef()));
pageRefs.add(Pair.of("last", page.getLastPageRef()));
if (page.hasPreviousPage()) {
pageRefs.add(Pair.of("prev", page.getPreviousPageRef()));
}
if (page.hasNextPage()) {
pageRefs.add(Pair.of("next", page.getNextPageRef()));
}
final UriBuilder ub = UriBuilder.fromUri(uri);
return pageRefs.stream().map(refPair -> format("<%s>; rel=\"%s\"", ub.clone().replaceQueryParam("skipCount", refPair.second.getItemsBefore()).replaceQueryParam("maxItems", refPair.second.getPageSize()).build().toString(), refPair.first)).collect(joining(LINK_HEADER_SEPARATOR));
}
use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class FactoryDaoTest method shouldFindFactoryByEmbeddedAttributes.
@Test(dependsOnMethods = "shouldUpdateFactory")
public void shouldFindFactoryByEmbeddedAttributes() throws Exception {
final List<Pair<String, String>> attributes = ImmutableList.of(Pair.of("policies.match", "match"), Pair.of("policies.create", "perClick"), Pair.of("workspace.defaultEnv", "env1"));
final FactoryImpl factory1 = factories[1];
final FactoryImpl factory3 = factories[3];
factory1.getPolicies().setCreate("perAccount");
factory3.getPolicies().setMatch("update");
factoryDao.update(factory1);
factoryDao.update(factory3);
final List<FactoryImpl> result = factoryDao.getByAttribute(factories.length, 0, attributes);
assertEquals(new HashSet<>(result), ImmutableSet.of(factories[0], factories[2], factories[4]));
}
use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class LocalVirtualFileTest method countsMd5Sums.
@Test
public void countsMd5Sums() throws Exception {
VirtualFile root = getRoot();
VirtualFile folder = root.createFolder(generateFolderName());
VirtualFile file1 = folder.createFile(generateFileName(), DEFAULT_CONTENT);
VirtualFile file2 = folder.createFile(generateFileName(), "xxx");
root.createFolder(generateFolderName());
Set<Pair<String, String>> expected = newHashSet(Pair.of(countMd5Sum(file1), file1.getPath().subPath(folder.getPath()).toString()), Pair.of(countMd5Sum(file2), file2.getPath().subPath(folder.getPath()).toString()));
assertEquals(expected, newHashSet(folder.countMd5Sums()));
}
use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class MavenModelReader method readMavenProject.
public MavenModelReaderResult readMavenProject(File pom, MavenServerManager serverManager) {
Pair<ModelReadingResult, Pair<List<String>, List<String>>> readResult = readModel(pom);
MavenModel model = readResult.first.model;
model = serverManager.interpolateModel(model, pom.getParentFile());
Pair<List<String>, List<String>> profilesPair = readResult.second;
return new MavenModelReaderResult(model, profilesPair.first, profilesPair.first, readResult.first.problems, Collections.emptySet());
}
use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class UserLinksInjectorTest method shouldInjectLinks.
@Test
public void shouldInjectLinks() throws Exception {
final UserDto userDto = DtoFactory.newDto(UserDto.class).withId("user123").withEmail("user@codenvy.com").withName("user");
linksInjector.injectLinks(userDto, serviceContext);
// [rel, method] pairs links
final Set<Pair<String, String>> links = userDto.getLinks().stream().map(link -> Pair.of(link.getMethod(), link.getRel())).collect(Collectors.toSet());
final Set<Pair<String, String>> expectedLinks = new HashSet<>(asList(Pair.of("GET", Constants.LINK_REL_SELF), Pair.of("GET", Constants.LINK_REL_CURRENT_USER), Pair.of("GET", Constants.LINK_REL_PROFILE), Pair.of("GET", Constants.LINK_REL_CURRENT_USER_SETTINGS), Pair.of("GET", Constants.LINK_REL_PREFERENCES), Pair.of("POST", Constants.LINK_REL_CURRENT_USER_PASSWORD)));
assertEquals(links, expectedLinks, "Difference " + Sets.symmetricDifference(links, expectedLinks) + "\n");
}
Aggregations