List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:de.metas.ui.web.process.ProcessInstancesRepository.java
private ProcessInfo createProcessInfo(final int adProcessId, final JSONCreateProcessInstanceRequest request) { // Validate request's AD_Process_ID // (we are not using it, but just for consistency) if (request.getAD_Process_ID() > 0 && request.getAD_Process_ID() != adProcessId) { throw new IllegalArgumentException("Request's AD_Process_ID is not valid. It shall be " + adProcessId + " or none but it was " + request.getAD_Process_ID()); }//from w ww. j a v a2 s. co m Check.assume(adProcessId > 0, "adProcessId > 0"); final String tableName; final int recordId; final String sqlWhereClause; // // View final String viewId = Strings.emptyToNull(request.getViewId()); final String viewSelectedIdsAsStr; final DocumentPath singleDocumentPath = request.getSingleDocumentPath(); if (!Check.isEmpty(viewId)) { final IDocumentViewSelection view = documentViewsRepo.getView(viewId); final Set<DocumentId> viewDocumentIds = request.getViewDocumentIds(); viewSelectedIdsAsStr = DocumentId.toCommaSeparatedString(viewDocumentIds); final int view_AD_Window_ID = view.getAD_Window_ID(); tableName = documentDescriptorFactory.getTableNameOrNull(view_AD_Window_ID); if (viewDocumentIds.size() == 1) { final DocumentId singleDocumentId = viewDocumentIds.iterator().next(); recordId = singleDocumentId.toIntOr(-1); } else { recordId = -1; } sqlWhereClause = view.getSqlWhereClause(viewDocumentIds); } // // Single document call else if (singleDocumentPath != null) { viewSelectedIdsAsStr = null; if (singleDocumentPath.isRootDocument()) { tableName = documentDescriptorFactory.getTableNameOrNull(singleDocumentPath.getAD_Window_ID()); recordId = singleDocumentPath.getDocumentId().toInt(); } else { tableName = documentDescriptorFactory.getTableNameOrNull(singleDocumentPath.getAD_Window_ID(), singleDocumentPath.getDetailId()); recordId = singleDocumentPath.getSingleRowId().toInt(); } sqlWhereClause = null; } // // From menu else { viewSelectedIdsAsStr = null; tableName = null; recordId = -1; sqlWhereClause = null; } return ProcessInfo.builder().setCtx(Env.getCtx()).setCreateTemporaryCtx().setAD_Process_ID(adProcessId) .setRecord(tableName, recordId).setWhereClause(sqlWhereClause) // .setLoadParametersFromDB(true) // important: we need to load the existing parameters from database, besides the internal ones we are adding here .addParameter(ProcessInstance.PARAM_ViewId, viewId) // internal parameter .addParameter(ProcessInstance.PARAM_ViewSelectedIds, viewSelectedIdsAsStr) // internal parameter // .build(); }
From source file:com.google.gerrit.server.account.externalids.ExternalId.java
public static ExternalId createWithEmail(Key key, Account.Id accountId, @Nullable String email) { return new AutoValue_ExternalId(key, accountId, Strings.emptyToNull(email), null); }
From source file:org.dash.wallet.common.Configuration.java
public String getTrustedPeerHost() { return Strings.emptyToNull(prefs.getString(PREFS_KEY_TRUSTED_PEER, "").trim()); }
From source file:org.dcache.xrootd.plugins.AccessLogHandler.java
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof XrootdResponse<?> && logger.isErrorEnabled()) { XrootdResponse<?> response = (XrootdResponse<?>) msg; XrootdRequest request = response.getRequest(); NetLoggerBuilder.Level level; if (response instanceof ErrorResponse) { level = ERROR;//from w w w. ja va 2 s . c o m } else if (request instanceof WriteRequest || request instanceof ReadRequest || request instanceof ReadVRequest) { level = DEBUG; } else { level = INFO; } if (level == ERROR || level == INFO && logger.isInfoEnabled() || level == DEBUG && logger.isDebugEnabled()) { NetLoggerBuilder log = new NetLoggerBuilder(level, "org.dcache.xrootd.request").omitNullValues(); log.add("session", CDC.getSession()); log.add("request", getRequestId(request)); if (request instanceof PathRequest) { log.add("path", (Strings.emptyToNull(((PathRequest) request).getPath()))); log.add("opaque", (Strings.emptyToNull(((PathRequest) request).getOpaque()))); if (request instanceof OpenRequest) { if (!((OpenRequest) request).isReadOnly()) { int mode = ((OpenRequest) request).getUMask(); if (mode == 0) { log.add("mode", "0"); } else { log.add("mode", "0" + Integer.toOctalString(mode)); } } log.add("options", "0x" + Integer.toHexString(((OpenRequest) request).getOptions())); } else if (request instanceof LocateRequest) { log.add("options", "0x" + Integer.toHexString(((LocateRequest) request).getOptions())); } else if (request instanceof MkDirRequest) { log.add("options", "0x" + Integer.toHexString(((MkDirRequest) request).getOptions())); } else if (request instanceof StatRequest) { if (((StatRequest) request).getTarget() == Target.FHANDLE) { log.add("handle", ((StatRequest) request).getFhandle()); } log.add("vfs", ((StatRequest) request).isVfsSet()); } } else if (request instanceof CloseRequest) { log.add("handle", ((CloseRequest) request).getFileHandle()); } else if (request instanceof LoginRequest) { log.add("username", ((LoginRequest) request).getUserName()); log.add("capver", ((LoginRequest) request).getClientProtocolVersion()); log.add("pid", ((LoginRequest) request).getPID()); log.add("token", emptyToNull(((LoginRequest) request).getToken())); } else if (request instanceof MvRequest) { log.add("source", ((MvRequest) request).getSourcePath()); log.add("target", ((MvRequest) request).getTargetPath()); } else if (request instanceof PrepareRequest) { log.add("options", "0x" + Integer.toHexString(((PrepareRequest) request).getOptions())); if (((PrepareRequest) request).getPathList().length == 1) { log.add("path", ((PrepareRequest) request).getPathList()[0]); } else { log.add("files", ((PrepareRequest) request).getPathList().length); } } else if (request instanceof StatxRequest) { if (((StatxRequest) request).getPaths().length == 1) { log.add("path", ((StatxRequest) request).getPaths()[0]); } else { log.add("files", ((StatxRequest) request).getPaths().length); } } else if (request instanceof SetRequest) { final String APPID_PREFIX = "appid "; final int APPID_PREFIX_LENGTH = APPID_PREFIX.length(); final int APPID_MSG_LENGTH = 80; String data = ((SetRequest) request).getData(); if (data.startsWith(APPID_PREFIX)) { log.add("appid", data.substring(APPID_PREFIX_LENGTH, Math.min(APPID_PREFIX_LENGTH + APPID_MSG_LENGTH, data.length()))); } } else if (request instanceof EndSessionRequest) { log.add("sessionId", ((EndSessionRequest) request).getSessionId()); } else if (request instanceof SyncRequest) { log.add("handle", ((SyncRequest) request).getFileHandle()); } log.add("response", getStatusCode(response)); if (response instanceof ErrorResponse) { log.add("error.code", getErrorCode((ErrorResponse) response)); log.add("error.msg", ((ErrorResponse) response).getErrorMessage()); } else if (response instanceof RedirectResponse) { log.add("host", ((RedirectResponse) response).getHost()); log.add("port", ((RedirectResponse) response).getPort()); log.add("token", emptyToNull(((RedirectResponse) response).getToken())); } else if (response instanceof StatResponse) { log.add("flags", ((StatResponse) response).getFlags()); log.add("modtime", Instant.ofEpochSecond(((StatResponse) response).getModificationTime())); log.add("size", ((StatResponse) response).getSize()); } else if (response instanceof LoginResponse) { log.add("sessionId", ((LoginResponse) response).getSessionId()); log.add("sec", emptyToNull(((LoginResponse) response).getSec())); } else if (response instanceof OpenResponse) { log.add("handle", ((OpenResponse) response).getFileHandle()); FileStatus fs = ((OpenResponse) response).getFileStatus(); if (fs != null) { log.add("flags", fs.getFlags()); log.add("modtime", Instant.ofEpochSecond(fs.getModificationTime())); log.add("size", fs.getSize()); } } log.toLogger(logger); } } ctx.write(msg, promise); }
From source file:com.stormpath.beanpole.system.BeanstalkEnvironmentPropertiesFactory.java
private String getSystemPropVal(String name) { String val = getSystemProperty(name); if (val != null) { val = Strings.emptyToNull(CharMatcher.WHITESPACE.trimFrom(val)); }/*from w w w. j a v a2 s. com*/ return val; }
From source file:org.jboss.as.console.client.administration.accesscontrol.ui.PrincipalDialog.java
private Principal beanToModel(PrincipalBean bean) { return Principal.transientPrincipal(type, bean.getName(), Strings.emptyToNull(bean.getRealm())); }
From source file:org.dcache.alarms.server.LogEntryServerWrapper.java
public void setPass(String pass) { this.pass = Strings.emptyToNull(pass); }
From source file:org.jclouds.glesys.compute.functions.ServerDetailsToNodeMetadata.java
@Override public NodeMetadata apply(ServerDetails from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname());// www . j a v a2 s. co m builder.hostname(from.getHostname()); Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(from.getDatacenter())) .orNull(); checkState(location != null, "no location matched ServerDetails %s", from); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname())); // TODO: get glesys to stop stripping out equals and commas! if (!isNullOrEmpty(from.getDescription()) && from.getDescription().matches("^[0-9A-Fa-f]+$")) { String decoded = new String(base16().lowerCase().decode(from.getDescription()), UTF_8); addMetadataAndParseTagsFromCommaDelimitedValue(builder, Splitter.on('\n').withKeyValueSeparator("=").split(decoded)); } builder.imageId(from.getTemplateName() + ""); builder.operatingSystem(parseOperatingSystem(from)); builder.hardware(new HardwareBuilder().ids(from.getId() + "").ram(from.getMemorySizeMB()) .processors(ImmutableList.of(new Processor(from.getCpuCores(), 1.0))) .volumes(ImmutableList.<Volume>of(new VolumeImpl((float) from.getDiskSizeGB(), true, true))) .hypervisor(from.getPlatform()).build()); builder.status(serverStateToNodeStatus.get(from.getState())); Iterable<String> addresses = Iterables .filter(Iterables.transform(from.getIps(), new Function<Ip, String>() { @Override public String apply(Ip arg0) { return Strings.emptyToNull(arg0.getIp()); } }), Predicates.notNull()); builder.publicAddresses(Iterables.filter(addresses, Predicates.not(IsPrivateIPAddress.INSTANCE))); builder.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE)); return builder.build(); }
From source file:fathom.conf.Settings.java
public String getApplicationName() { return Optional.fromNullable(Strings.emptyToNull(getString(Setting.application_name, null))) .or("<APPLICATION>"); }
From source file:org.eclipse.buildship.ui.wizard.project.AbstractWizardPage.java
private Composite createWizardPageContent(Composite parent) { // create a scrollable root to handle resizing ScrolledComposite externalRoot = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); externalRoot.setExpandHorizontal(true); externalRoot.setExpandVertical(true); externalRoot.setMinSize(new Point(230, 380)); // add the controls inside the root composite Composite container = new Composite(externalRoot, SWT.NONE); createWidgets(container);//w w w. ja v a 2 s .c o m // add context information to the bottom of the page if the page defines it String contextInformation = Strings.emptyToNull(getPageContextInformation()); if (contextInformation != null) { createWidgetsForContextInformation(container, contextInformation); } // also compute the size of the container, otherwise the ScrolledComposite's content is not // rendered properly Point containerSize = container.computeSize(SWT.DEFAULT, SWT.DEFAULT); container.setSize(containerSize); // set the root's content and return it externalRoot.setContent(container); return externalRoot; }