Example usage for com.google.common.base Strings nullToEmpty

List of usage examples for com.google.common.base Strings nullToEmpty

Introduction

In this page you can find the example usage for com.google.common.base Strings nullToEmpty.

Prototype

public static String nullToEmpty(@Nullable String string) 

Source Link

Document

Returns the given string if it is non-null; the empty string otherwise.

Usage

From source file:org.robotframework.ide.eclipse.main.plugin.model.RobotVariable.java

@Override
public String getName() {
    return Strings.nullToEmpty(holder.getName());
}

From source file:org.apache.sqoop.submission.spark.LocalSqoopSparkClient.java

public void addResources(String addedFiles) {
    for (String addedFile : CSV_SPLITTER.split(Strings.nullToEmpty(addedFiles))) {
        if (!localFiles.contains(addedFile)) {
            localFiles.add(addedFile);/*from   w  w w . j ava 2  s.  c o m*/
            sc.addFile(addedFile);
        }
    }
}

From source file:com.android.tools.idea.uibuilder.handlers.preference.PreferenceHandler.java

@NotNull
@Override
public String getTitle(@NotNull NlComponent component) {
    return Strings.nullToEmpty(component.getAndroidAttribute(ATTR_TITLE));
}

From source file:org.eclipse.che.ide.ui.smartTree.presentation.DefaultPresentationRenderer.java

private Element createPresentableTextElement(NodePresentation presentation) {
    DivElement textElement = Document.get().createDivElement();

    textElement.setInnerText(Strings.nullToEmpty(presentation.getPresentableText()));
    textElement.setAttribute("style", presentation.getPresentableTextCss());

    //TODO support text colorization

    return textElement;
}

From source file:eu.interedition.text.tei.MilestoneAnnotationGenerator.java

@Override
public boolean accept(XMLStreamReader reader) {
    if (reader.isStartElement()) {
        final QName elementName = reader.getName();
        final String elementNs = Strings.nullToEmpty(elementName.getNamespaceURI());
        boolean handled = false;
        if (NamespaceMapping.TEI_NS_URI.equals(elementNs)) {
            final boolean handledSpanningElement = handleSpanningElements(reader, elementName);
            final boolean handledMilestoneElement = handleMilestoneElements(reader, elementName);
            handled = (handledSpanningElement || handledMilestoneElement);
        }/*from w  w  w  .j a  v  a2  s  . c  om*/
        handledElements.push(handled);
        return !handled;
    } else if (reader.isEndElement()) {
        return !handledElements.pop();
    }
    return true;
}

From source file:io.druid.segment.filter.LikeFilter.java

@Override
public ImmutableBitmap getBitmapIndex(BitmapIndexSelector selector) {
    if (extractionFn == null
            && likeMatcher.getSuffixMatch() == LikeDimFilter.LikeMatcher.SuffixMatch.MATCH_EMPTY) {
        // dimension equals prefix
        return selector.getBitmapIndex(dimension, likeMatcher.getPrefix());
    } else if (extractionFn == null && !likeMatcher.getPrefix().isEmpty()) {
        // dimension startsWith prefix and is accepted by likeMatcher.matchesSuffixOnly
        final BitmapIndex bitmapIndex = selector.getBitmapIndex(dimension);

        if (bitmapIndex == null) {
            // Treat this as a column full of nulls
            return likeMatcher.matches(null) ? Filters.allTrue(selector) : Filters.allFalse(selector);
        }/*from  w w  w.  jav  a 2  s .  c o  m*/

        // search for start, end indexes in the bitmaps; then include all matching bitmaps between those points
        final Indexed<String> dimValues = selector.getDimensionValues(dimension);

        final String lower = Strings.nullToEmpty(likeMatcher.getPrefix());
        final String upper = Strings.nullToEmpty(likeMatcher.getPrefix()) + Character.MAX_VALUE;
        final int startIndex; // inclusive
        final int endIndex; // exclusive

        final int lowerFound = bitmapIndex.getIndex(lower);
        startIndex = lowerFound >= 0 ? lowerFound : -(lowerFound + 1);

        final int upperFound = bitmapIndex.getIndex(upper);
        endIndex = upperFound >= 0 ? upperFound + 1 : -(upperFound + 1);

        // Union bitmaps for all matching dimension values in range.
        // Use lazy iterator to allow unioning bitmaps one by one and avoid materializing all of them at once.
        return selector.getBitmapFactory().union(new Iterable<ImmutableBitmap>() {
            @Override
            public Iterator<ImmutableBitmap> iterator() {
                return new Iterator<ImmutableBitmap>() {
                    int currIndex = startIndex;

                    @Override
                    public boolean hasNext() {
                        return currIndex < endIndex;
                    }

                    @Override
                    public ImmutableBitmap next() {
                        while (currIndex < endIndex
                                && !likeMatcher.matchesSuffixOnly(dimValues.get(currIndex))) {
                            currIndex++;
                        }

                        if (currIndex == endIndex) {
                            return bitmapIndex.getBitmapFactory().makeEmptyImmutableBitmap();
                        }

                        return bitmapIndex.getBitmap(currIndex++);
                    }

                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }
        });
    } else {
        // fallback
        return Filters.matchPredicate(dimension, selector,
                likeMatcher.predicateFactory(extractionFn).makeStringPredicate());
    }
}

From source file:com.skcraft.launcher.install.HttpDownloader.java

@Override
public synchronized File download(@NonNull List<URL> urls, @NonNull String key, long size, String name) {
    if (urls.isEmpty()) {
        throw new IllegalArgumentException("Can't download empty list of URLs");
    }/*from   w ww  .  jav a2  s . c o  m*/

    String hash = hf.hashString(Strings.nullToEmpty(key) + urls.get(0), Charsets.UTF_8).toString();
    hash = createUniqueKey(hash);
    File tempFile = new File(tempDir, hash.substring(0, 2) + "/" + hash);

    // If the file is already downloaded (such as from before), then don't re-download
    if (!tempFile.exists()) {
        total += size;
        left++;
        queue.add(new HttpDownloadJob(tempFile, urls, size, name != null ? name : tempFile.getName()));
    }

    return tempFile;
}

From source file:org.mitre.oauth2.service.impl.UriEncodedClientUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException {

    try {//  ww w  .  j  a v  a2 s. co m
        String decodedClientId = UriUtils.decode(clientId, "UTF-8");

        ClientDetailsEntity client = clientDetailsService.loadClientByClientId(decodedClientId);

        if (client != null) {

            String encodedPassword = UriUtils.encodePathSegment(Strings.nullToEmpty(client.getClientSecret()),
                    "UTF-8");

            if (config.isHeartMode() || // if we're running HEART mode turn off all client secrets
                    (client.getTokenEndpointAuthMethod() != null
                            && (client.getTokenEndpointAuthMethod().equals(AuthMethod.PRIVATE_KEY)
                                    || client.getTokenEndpointAuthMethod().equals(AuthMethod.SECRET_JWT)))) {

                // Issue a random password each time to prevent password auth from being used (or skipped)
                // for private key or shared key clients, see #715

                encodedPassword = new BigInteger(512, new SecureRandom()).toString(16);
            }

            boolean enabled = true;
            boolean accountNonExpired = true;
            boolean credentialsNonExpired = true;
            boolean accountNonLocked = true;
            Collection<GrantedAuthority> authorities = new HashSet<>(client.getAuthorities());
            authorities.add(ROLE_CLIENT);

            return new User(decodedClientId, encodedPassword, enabled, accountNonExpired, credentialsNonExpired,
                    accountNonLocked, authorities);
        } else {
            throw new UsernameNotFoundException("Client not found: " + clientId);
        }
    } catch (UnsupportedEncodingException | InvalidClientException e) {
        throw new UsernameNotFoundException("Client not found: " + clientId);
    }

}

From source file:org.jclouds.vsphere.functions.VirtualMachineToSshClient.java

@Override
public SshClient apply(final VirtualMachine vm) {
    SshClient client = null;/*  w w  w.j a  v  a2  s . co m*/
    String clientIpAddress = vm.getGuest().getIpAddress();
    String sshPort = "22";
    while (!vm.getGuest().getToolsStatus().equals(VirtualMachineToolsStatus.toolsOk)
            || clientIpAddress.isEmpty()) {
        int timeoutValue = 1000;
        int timeoutUnits = 500;
        Predicate<String> tester = Predicates2.retry(ipAddressTester, timeoutValue, timeoutUnits,
                TimeUnit.MILLISECONDS);
        boolean passed = false;
        while (vm.getRuntime().getPowerState().equals(VirtualMachinePowerState.poweredOn) && !passed) {
            clientIpAddress = Strings.nullToEmpty(vm.getGuest().getIpAddress());
            passed = tester.apply(clientIpAddress);
        }
    }
    LoginCredentials loginCredentials = LoginCredentials.builder().user("root").password(password).build();
    checkNotNull(clientIpAddress, "clientIpAddress");
    client = sshClientFactory.create(HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)),
            loginCredentials);
    checkNotNull(client);
    return client;
}

From source file:org.apache.awf.configuration.Configuration.java

/**
 * Retrieve the package under which <code>RequestHandler</code>
 * implementations are to be found, for example "org.apache.awf".
 * //from   w ww  . j a  v  a 2  s . co  m
 * @return the current package name.
 */
public String getHandlerPackage() {
    return Strings.nullToEmpty(handlerPacakge).trim().isEmpty() ? "" : handlerPacakge;
}