List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:com.kegare.caveworld.client.renderer.RenderCaveman.java
@Override public void doRender(Entity entity, double par2, double par3, double par4, float par5, float par6) { super.doRender(entity, par2, par3, par4, par5, par6); if (Config.cavemanShowHealthBar && entity instanceof EntityCaveman) { Minecraft mc = FMLClientHandler.instance().getClient(); EntityPlayer player = mc.thePlayer; EntityCaveman living = (EntityCaveman) entity; if (living.isTamed() && player.getGameProfile().getId().toString() .equals(Strings.nullToEmpty(living.func_152113_b())) && living.getEntitySenses().canSee(player) && living.getDistanceToEntity(player) <= 3.5F && mc.objectMouseOver.typeOfHit == MovingObjectType.ENTITY && mc.objectMouseOver.entityHit == living) { float scale = 0.01666667F * 1.5F; int width = 15; double top = 5.0D; double under = top + 2.0D; GL11.glPushMatrix();//from w w w .java 2 s . c o m GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glTranslatef((float) par2, (float) par3 + 2.3F, (float) par4); GL11.glNormal3f(0.0F, 1.0F, 0.0F); GL11.glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F); GL11.glRotatef(RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F); GL11.glScalef(-scale, -scale, scale); GL11.glDisable(GL11.GL_LIGHTING); GL11.glTranslatef(0.0F, (living.isSittingAndStopped() ? 0.6F : 0.12F) / scale, 0.0F); GL11.glDepthMask(false); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(770, 771); int x = living.getBrightnessForRender((float) par2); int y = x % 65536; int z = x / 65536; OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, y / 1.0F, z / 1.0F); Tessellator tessellator = Tessellator.instance; GL11.glDisable(GL11.GL_TEXTURE_2D); tessellator.startDrawingQuads(); tessellator.setColorRGBA_I(0, 115); tessellator.addVertex(-width - 1, top - 0.5D, 0.0D); tessellator.addVertex(-width - 1, under + 0.5D, 0.0D); tessellator.addVertex(width + 1, under + 0.5D, 0.0D); tessellator.addVertex(width + 1, top - 0.5D, 0.0D); tessellator.draw(); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_BLEND); GL11.glDepthMask(true); Tessellator tessellator1 = Tessellator.instance; GL11.glDisable(GL11.GL_TEXTURE_2D); float max = living.getMaxHealth(); int health = (int) (2.0D * width * living.getHealth() / max); if (renderHealth < 0.0D) { renderHealth = health; } else { double dh = renderHealth - health; double distance = Math.abs(Math.sqrt(dh * dh)); if ((int) renderHealth < health) { if (distance > 10.0D) { renderHealth += 0.35D; } else if (distance < 1.5D) { renderHealth += 0.01D; } else { renderHealth += 0.1D; } } else if ((int) renderHealth > health) { if (distance > 10.0D) { renderHealth -= 0.35D; } else if (distance < 1.5D) { renderHealth -= 0.01D; } else { renderHealth -= 0.1D; } } } int color = Color.GREEN.getRGB(); if (renderHealth < max / 4) { color = Color.RED.getRGB(); } else if (renderHealth < max / 2) { color = Color.YELLOW.getRGB(); } tessellator1.startDrawingQuads(); tessellator1.setColorRGBA_I(color, 145); tessellator1.addVertex(-width, top, 0.0D); tessellator1.addVertex(-width, under, 0.0D); tessellator1.addVertex(-width + renderHealth, under, 0.0D); tessellator1.addVertex(-width + renderHealth, top, 0.0D); tessellator1.draw(); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); } else { renderHealth = -1.0D; } } }
From source file:org.jclouds.vcloud.director.testng.FormatApiResultsListener.java
private String getOperation(ITestResult res) { return Strings.nullToEmpty(res.getMethod().getDescription()); }
From source file:ealvatag.tag.datatype.StringHashMap.java
public String toString() { if (value != null) { return Strings.nullToEmpty(simpleStringStringMap.getValue(value.toString())); }//from w w w. j a v a 2 s. c o m return ""; }
From source file:ratpack.server.internal.InferringPublicAddress.java
private URI getAbsoluteRequestUri(Request request) { String rawUri = Strings.nullToEmpty(request.getRawUri()); if (rawUri.isEmpty() || rawUri.startsWith("/")) { return null; }/* w w w . j a v a 2 s. c o m*/ return URI.create(rawUri); }
From source file:com.attribyte.relay.DusterClient.java
/** * Creates the client.// ww w. jav a2 s. co m * <ul> * <li>imageDimensionURL - The duster service URL</li> * <li>imageDimensionUsername - The duster service auth username</li> * <li>imageDimensionPassword - The duster service auth password</li> * <li>minWidth - The minimum width</li> * <li>minHeight - The minimum height</li> * <li>minAspect - The minimum aspect ratio</li> * <li>maxAspect - The maximum aspect ratio</li> * <li>pregenAllTransforms - Should all available transforms be pre-generated, async?</li> * </ul> * @param props The configuration properties. * @param httpClient The HTTP client. * @param logger A logger. * @throws Exception on invalid properties or initialization problem. */ public DusterClient(final Properties props, final AsyncClient httpClient, final Logger logger) throws Exception { this.imageDimensionURL = props.getProperty("imageDimensionURL"); if (this.imageDimensionURL == null) { throw new Exception("The 'imageDimensionURL' must be specified"); } String username = Strings.nullToEmpty(props.getProperty("imageDimensionUsername")).trim(); if (username.isEmpty()) { throw new Exception("The 'imageDimensionUsername' must be specified"); } String password = Strings.nullToEmpty(props.getProperty("imageDimensionPassword")).trim(); if (password.isEmpty()) { throw new Exception("The 'imageDimensionPassword' must be specified"); } this.auth = BasicAuthScheme.buildAuthHeaderValue(username, password); this.minWidth = Integer.parseInt(props.getProperty("minWidth", "50")); this.minHeight = Integer.parseInt(props.getProperty("minHeight", "50")); this.minAspect = Double.parseDouble(props.getProperty("minAspect", "0.25")); this.maxAspect = Double.parseDouble(props.getProperty("maxAspect", "5")); this.httpClient = httpClient; this.availableTransforms = ImmutableList.copyOf(Splitter.on(',').omitEmptyStrings().trimResults() .split(Strings.nullToEmpty(props.getProperty("transforms")))); if (props.getProperty("pregenerateAll", "false").trim().equalsIgnoreCase("true")) { pregenerateTransformQuery = "transformAll=true"; } else if (this.availableTransforms.size() == 0) { pregenerateTransformQuery = "transformAll=false"; } else { pregenerateTransformQuery = Joiner.on('&').join(this.availableTransforms.stream() .map(transform -> "transform=" + transform).collect(Collectors.toList())); } this.transformPath = props.getProperty("transformPath", ""); this.logger = logger; }
From source file:com.facebook.buck.plugin.intellij.ui.MessageTreeRenderer.java
@Override protected void initComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof ProgressNode) { ProgressNode node = (ProgressNode) value; String[] text = new String[] { node.getName() }; String prefix;//from www .j a v a2s . c om Icon icon; switch (node.getType()) { case DIRECTORY: prefix = ""; icon = AllIcons.General.Filter; break; case BUILDING: prefix = "Building"; icon = AllIcons.Process.Step_1; break; case BUILT: prefix = "Built"; icon = AllIcons.Ant.Message; break; case BUILT_CACHED: prefix = "Built"; icon = AllIcons.General.Gear; break; case BUILD_ERROR: prefix = "Error"; icon = AllIcons.General.Error; break; case TEST_CASE_SUCCESS: prefix = "Test"; icon = AllIcons.Modules.TestRoot; break; case TEST_CASE_FAILURE: prefix = "Test Failure"; icon = AllIcons.General.Error; break; case TEST_RESULT_SUCCESS: prefix = ""; icon = AllIcons.Nodes.Advice; break; case TEST_RESULT_FAILURE: prefix = ""; icon = AllIcons.General.Error; break; default: icon = AllIcons.General.Error; prefix = ""; } setText(text, prefix); setIcon(icon); } else { String[] text = new String[] { value == null ? "" : value.toString() }; text[0] = Strings.nullToEmpty(text[0]); setText(text, null); setIcon(null); } }
From source file:com.google.gitiles.GitwebRedirectFilter.java
@Override public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException { GitilesView gitwebView = ViewFilter.getView(req); if (!isGitwebStyleQuery(req)) { chain.doFilter(req, res);//from w ww . ja v a2 s. c om return; } ListMultimap<String, String> params = parse(req.getQueryString()); String action = getFirst(params, "a"); String project = getFirst(params, "p"); String path = Strings.nullToEmpty(getFirst(params, "f")); // According to gitweb's perl source code, the primary parameters are these // short abbreviated names. When pointing to blob or subtree hash,hashParent // are the blob or subtree SHA-1s and hashBase,hashParentBase are commits. // When pointing to commits or tags, hash is the commit/tag. Its messy. Revision hash = toRevision(getFirst(params, "h")); Revision hashBase = toRevision(getFirst(params, "hb")); Revision hashParent = toRevision(getFirst(params, "hp")); Revision hashParentBase = toRevision(getFirst(params, "hpb")); GitilesView.Builder view; if ("project_index".equals(action)) { view = GitilesView.hostIndex(); project = null; } else if ("summary".equals(action) || "tags".equals(action)) { view = GitilesView.repositoryIndex(); } else if (("commit".equals(action) || "tag".equals(action)) && hash != null) { view = GitilesView.revision().setRevision(hash); } else if ("log".equals(action) || "shortlog".equals(action)) { view = GitilesView.log().setRevision(firstNonNull(hash, Revision.HEAD)); } else if ("tree".equals(action)) { view = GitilesView.path().setRevision(firstNonNull(hashBase, Revision.HEAD)).setPathPart(path); } else if (("blob".equals(action) || "blob_plain".equals(action)) && hashBase != null && !path.isEmpty()) { view = GitilesView.path().setRevision(hashBase).setPathPart(path); } else if ("commitdiff".equals(action) && hash != null) { view = GitilesView.diff().setOldRevision(firstNonNull(hashParent, Revision.NULL)).setRevision(hash) .setPathPart(""); } else if ("blobdiff".equals(action) && !path.isEmpty() && hashParentBase != null && hashBase != null) { view = GitilesView.diff().setOldRevision(hashParentBase).setRevision(hashBase).setPathPart(path); } else if ("history".equals(action) && !path.isEmpty()) { view = GitilesView.log().setRevision(firstNonNull(hashBase, Revision.HEAD)).setPathPart(path); } else { // Gitiles does not provide an RSS feed (a=rss,atom,opml) // Any other URL is out of date and not valid anymore. res.sendError(SC_GONE); return; } if (!Strings.isNullOrEmpty(project)) { view.setRepositoryName(cleanProjectName(project)); } String url; try { url = view.setHostName(gitwebView.getHostName()).setServletPath(gitwebView.getServletPath()).toUrl(); } catch (InvalidViewException e) { res.setStatus(SC_GONE); return; } res.setStatus(SC_MOVED_PERMANENTLY); res.setHeader(LOCATION, url); }
From source file:org.apache.sentry.provider.file.LocalGroupMappingService.java
private void parseGroups(FileSystem fileSystem, Path resourcePath) throws IOException { Ini ini = PolicyFiles.loadFromPath(fileSystem, resourcePath); Section usersSection = ini.getSection(PolicyFileConstants.USERS); if (usersSection == null) { LOGGER.warn("No section " + PolicyFileConstants.USERS + " in the " + resourcePath); return;//from ww w . j a va 2 s .c om } for (Entry<String, String> userEntry : usersSection.entrySet()) { String userName = Strings.nullToEmpty(userEntry.getKey()).trim(); String groupNames = Strings.nullToEmpty(userEntry.getValue()).trim(); if (userName.isEmpty()) { LOGGER.error("Invalid user name in the " + resourcePath); continue; } if (groupNames.isEmpty()) { LOGGER.warn("No groups available for user " + userName + " in the " + resourcePath); continue; } List<String> groupList = Lists .newArrayList(PolicyFileConstants.ROLE_SPLITTER.trimResults().split(groupNames)); LOGGER.debug("Got user mapping: " + userName + ", Groups: " + groupNames); groupMap.put(userName, groupList); } }
From source file:com.googlesource.gerrit.plugins.wip.BaseAction.java
private ChangeMessage newMessage(Input input, Change change) throws OrmException { StringBuilder msg = new StringBuilder("Change " + change.getId().get() + ": " + ((change.getStatus() == Status.WORKINPROGRESS) ? "Work In Progress" : "Ready For Review")); if (!Strings.nullToEmpty(input.message).trim().isEmpty()) { msg.append("\n\n"); msg.append(input.message.trim()); }//from w w w .j a va2 s .c o m ChangeMessage message = new ChangeMessage( new ChangeMessage.Key(change.getId(), ChangeUtil.messageUUID(dbProvider.get())), ((IdentifiedUser) userProvider.get()).getAccountId(), change.getLastUpdatedOn(), change.currentPatchSetId()); message.setMessage(msg.toString()); return message; }
From source file:com.eucalyptus.tags.TagHelper.java
/** * Validate the given list of tags for the current context. * * @param resourceTags/*w w w .ja va 2 s . com*/ * @throws MetadataException */ public static void validateTags(@Nullable final List<ResourceTag> resourceTags) throws MetadataException { final Set<String> tagKeys = Sets.newHashSet(); if (resourceTags != null) for (final ResourceTag resourceTag : resourceTags) { final String key = resourceTag.getKey(); final String value = Strings.nullToEmpty(resourceTag.getValue()).trim(); if (isReserved(key)) { throw new InvalidTagMetadataException( "Tag keys starting with 'aws:' and 'euca:' are reserved for internal use"); } if (Strings.isNullOrEmpty(key) || key.trim().length() > 127) { throw new InvalidTagMetadataException("Tag key exceeds the maximum length of 127 characters"); } if (value.length() > 255) { throw new InvalidTagMetadataException("Tag value exceeds the maximum length of 255 characters"); } if (!tagKeys.add(key)) { throw new InvalidTagMetadataException("Duplicate tag key"); } } }