Java Code Examples for org.springframework.data.util.Pair#of()

The following examples show how to use org.springframework.data.util.Pair#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RqueueUtilityServiceImpl.java    From rqueue with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Pair<String, String> getLatestVersion() {
  if (System.currentTimeMillis() - versionFetchTime > Constants.MILLIS_IN_A_DAY) {
    Map<String, Object> response =
        readUrl(Constants.GITHUB_API_FOR_LATEST_RELEASE, LinkedHashMap.class);
    if (response != null) {
      String tagName = (String) response.get("tag_name");
      if (tagName != null && !tagName.isEmpty()) {
        if (Character.toLowerCase(tagName.charAt(0)) == 'v') {
          releaseLink = (String) response.get("html_url");
          latestVersion = tagName.substring(1);
          versionFetchTime = System.currentTimeMillis();
        }
      }
    }
  }
  return Pair.of(releaseLink, latestVersion);
}
 
Example 2
Source File: WebSocketTransport.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
public void stompConnect(String userName, String password) throws BrokerException {
    WeEventStompCommand stompCommand = new WeEventStompCommand();
    String req = stompCommand.encodeConnect(userName, password);

    this.sequence2Id.put(Long.toString(0L), 0L);
    getStompHeaderAccessor(stompCommand, req, 0L, "stompConnect");
    log.info("stomp connect success.");

    this.account = Pair.of(userName, password);

    // initialize connection context
    this.cleanup();
    this.receiptId2SubscriptionId.clear();
    this.subscriptionId2ReceiptId.clear();
    this.connected = true;
}
 
Example 3
Source File: PageableDataProvider.java    From spring-data-provider with Apache License 2.0 6 votes vote down vote up
public static Pair<Integer, Integer> limitAndOffsetToPageSizeAndNumber(
        int offset, int limit) {
    int minPageSize = limit;
    int lastIndex = offset + limit - 1;
    int maxPageSize = lastIndex + 1;

    for (double pageSize = minPageSize; pageSize <= maxPageSize; pageSize++) {
        int startPage = (int) (offset / pageSize);
        int endPage = (int) (lastIndex / pageSize);
        if (startPage == endPage) {
            // It fits on one page, let's go with that
            return Pair.of((int) pageSize, startPage);
        }
    }

    // Should not really get here
    return Pair.of(maxPageSize, 0);
}
 
Example 4
Source File: CleanupService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public Pair<Set<String>, Map<String, String>> revokeCerts(Long stackId, Set<String> hosts) throws FreeIpaClientException {
    FreeIpaClient client = getFreeIpaClient(stackId);
    Set<String> certCleanupSuccess = new HashSet<>();
    Map<String, String> certCleanupFailed = new HashMap<>();
    Set<Cert> certs = client.findAllCert();
    certs.stream()
            .filter(cert -> hosts.stream().anyMatch(host -> substringBefore(host, ".").equals(substringBefore(removeStart(cert.getSubject(), "CN="), "."))))
            .filter(cert -> !cert.isRevoked())
            .forEach(cert -> {
                try {
                    client.revokeCert(cert.getSerialNumber());
                    certCleanupSuccess.add(cert.getSubject());
                } catch (FreeIpaClientException e) {
                    LOGGER.error("Couldn't revoke certificate: {}", cert, e);
                    certCleanupFailed.put(cert.getSubject(), e.getMessage());
                }
            });
    return Pair.of(certCleanupSuccess, certCleanupFailed);
}
 
Example 5
Source File: CleanupService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public Pair<Set<String>, Map<String, String>> removeRoles(Long stackId, Set<String> roles) throws FreeIpaClientException {
    FreeIpaClient client = getFreeIpaClient(stackId);
    Set<String> roleCleanupSuccess = new HashSet<>();
    Map<String, String> roleCleanupFailed = new HashMap<>();
    Set<String> roleNames = client.findAllRole().stream().map(Role::getCn).collect(Collectors.toSet());
    roles.stream().filter(roleNames::contains).forEach(role -> {
        try {
            LOGGER.debug("Delete role: {}", role);
            client.deleteRole(role);
            roleCleanupSuccess.add(role);
        } catch (FreeIpaClientException e) {
            if (FreeIpaClientExceptionUtil.isNotFoundException(e)) {
                roleCleanupSuccess.add(role);
            } else {
                LOGGER.info("Role delete failed for role: {}", role, e);
                roleCleanupFailed.put(role, e.getMessage());
            }
        }
    });
    return Pair.of(roleCleanupSuccess, roleCleanupFailed);
}
 
Example 6
Source File: CleanupService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public Pair<Set<String>, Map<String, String>> removeVaultEntries(Long stackId, Set<String> hosts) throws FreeIpaClientException {
    Set<String> vaultCleanupSuccess = new HashSet<>();
    Map<String, String> vaultCleanupFailed = new HashMap<>();
    Stack stack = stackService.getStackById(stackId);
    FreeIpaClient freeIpaClient = getFreeIpaClient(stackId);
    for (String host : hosts) {
        try {
            HostRequest hostRequest = new HostRequest();
            hostRequest.setEnvironmentCrn(stack.getEnvironmentCrn());
            hostRequest.setServerHostName(host);
            kerberosMgmtV1Service.removeHostRelatedKerberosConfiguration(hostRequest, stack.getAccountId(), freeIpaClient);
            vaultCleanupSuccess.add(host);
        } catch (DeleteException | FreeIpaClientException e) {
            LOGGER.info("Vault secret cleanup failed for host: {}", host, e);
            vaultCleanupFailed.put(host, e.getMessage());
        }
    }
    return Pair.of(vaultCleanupSuccess, vaultCleanupFailed);
}
 
Example 7
Source File: ExtensionProcessor.java    From openvsx with Eclipse Public License 2.0 5 votes vote down vote up
private Pair<byte[], String> readFromAlternateNames(String[] names) {
    for (var name : names) {
        var bytes = ArchiveUtil.readEntry(zipFile, name);
        if (bytes != null) {
            var lastSegmentIndex = name.lastIndexOf('/');
            var lastSegment = name.substring(lastSegmentIndex + 1);
            return Pair.of(bytes, lastSegment);
        }
    }
    return null;
}
 
Example 8
Source File: VSCodeAdapter.java    From openvsx with Eclipse Public License 2.0 5 votes vote down vote up
private Pair<String, FileResource> getFile(ExtensionVersion extVersion, String assetType) {
    switch (assetType) {
        case FILE_VSIX:
            return Pair.of(
                extVersion.getExtensionFileName(),
                repositories.findFile(extVersion, FileResource.DOWNLOAD)
            );
        case FILE_MANIFEST:
            return Pair.of(
                "package.json",
                repositories.findFile(extVersion, FileResource.MANIFEST)
            );
        case FILE_DETAILS:
            return Pair.of(
                extVersion.getReadmeFileName(),
                repositories.findFile(extVersion, FileResource.README)
            );
        case FILE_LICENSE:
            return Pair.of(
                extVersion.getLicenseFileName(),
                repositories.findFile(extVersion, FileResource.LICENSE)
            );
        case FILE_ICON:
            return Pair.of(
                extVersion.getIconFileName(),
                repositories.findFile(extVersion, FileResource.ICON)
            );
        default:
           return null;
    }
}
 
Example 9
Source File: PatternUtil.java    From coderadar with MIT License 5 votes vote down vote up
/**
 * Transforms the given FilePatterns to the corresponding regex representation and returns them as
 * a pair.
 *
 * @param filePatterns FilePatterns to transform to regex pattern.
 * @return Pair of regex patterns, first list: includes, second list: excludes
 */
public static Pair<List<String>, List<String>> mapPatternsToRegex(
    List<FilePattern> filePatterns) {
  List<String> includes = new ArrayList<>();
  List<String> excludes = new ArrayList<>();
  for (FilePattern filePattern : filePatterns) {
    if (filePattern.getInclusionType().equals(InclusionType.INCLUDE)) {
      includes.add(toPattern(filePattern.getPattern()).toString());
    } else {
      excludes.add(toPattern(filePattern.getPattern()).toString());
    }
  }
  return Pair.of(includes, excludes);
}
 
Example 10
Source File: CleanupService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public Pair<Set<String>, Map<String, String>> removeDnsEntries(Long stackId, Set<String> hosts, Set<String> ips, String domain)
        throws FreeIpaClientException {
    FreeIpaClient client = getFreeIpaClient(stackId);
    Set<String> dnsCleanupSuccess = new HashSet<>();
    Map<String, String> dnsCleanupFailed = new HashMap<>();
    Set<String> allDnsZoneName = client.findAllDnsZone().stream().map(DnsZoneList::getIdnsname).collect(Collectors.toSet());
    for (String zone : allDnsZoneName) {
        removeHostNameRelatedDnsRecords(hosts, domain, client, dnsCleanupSuccess, dnsCleanupFailed, zone);
        removeIpRelatedRecords(ips, client, dnsCleanupSuccess, dnsCleanupFailed, zone);
    }
    return Pair.of(dnsCleanupSuccess, dnsCleanupFailed);
}
 
Example 11
Source File: MyTest2.java    From ACManager with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void test5() throws Exception {
    Pair<String, double[]> pair = Pair.of("abc", new double[]{1, 2, 3, 4});
    System.out.println(pair);
}