当前位置: 首页>>代码示例>>Java>>正文


Java Strings类代码示例

本文整理汇总了Java中com.google.common.base.Strings的典型用法代码示例。如果您正苦于以下问题:Java Strings类的具体用法?Java Strings怎么用?Java Strings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Strings类属于com.google.common.base包,在下文中一共展示了Strings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: withLineNumbers

import com.google.common.base.Strings; //导入依赖的package包/类
private String withLineNumbers(String code) {
	try {
		return CharStreams.readLines(new StringReader(code), new LineProcessor<String>() {

			private final StringBuilder lines = new StringBuilder();
			private int lineNo = 1;

			@Override
			public boolean processLine(String line) throws IOException {
				lines.append(Strings.padStart(String.valueOf(lineNo++), 3, ' ')).append(": ").append(line)
						.append("\n");
				return true;
			}

			@Override
			public String getResult() {
				return lines.toString();
			}
		});
	} catch (IOException e) {
		throw new IllegalStateException(e.getMessage());
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:24,代码来源:PositiveAnalyser.java

示例2: printException

import com.google.common.base.Strings; //导入依赖的package包/类
private void printException(TestDescriptor descriptor, Throwable exception, boolean cause, int indentLevel, StringBuilder builder) {
    String indent = Strings.repeat(INDENT, indentLevel);
    builder.append(indent);
    if (cause) {
        builder.append("Caused by: ");
    }
    String className = exception instanceof PlaceholderException
            ? ((PlaceholderException) exception).getExceptionClassName() : exception.getClass().getName();
    builder.append(className);

    StackTraceFilter filter = new StackTraceFilter(new ClassMethodNameStackTraceSpec(descriptor.getClassName(), null));
    List<StackTraceElement> stackTrace = filter.filter(exception);
    if (stackTrace.size() > 0) {
        StackTraceElement element = stackTrace.get(0);
        builder.append(" at ");
        builder.append(element.getFileName());
        builder.append(':');
        builder.append(element.getLineNumber());
    }
    builder.append('\n');

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), true, indentLevel + 1, builder);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:ShortExceptionFormatter.java

示例3: filterNotifications

import com.google.common.base.Strings; //导入依赖的package包/类
private Map<String, ApolloConfigNotification> filterNotifications(String appId,
                                                                  List<ApolloConfigNotification> notifications) {
  Map<String, ApolloConfigNotification> filteredNotifications = Maps.newHashMap();
  for (ApolloConfigNotification notification : notifications) {
    if (Strings.isNullOrEmpty(notification.getNamespaceName())) {
      continue;
    }
    //strip out .properties suffix
    String originalNamespace = namespaceUtil.filterNamespaceName(notification.getNamespaceName());
    notification.setNamespaceName(originalNamespace);
    //fix the character case issue, such as FX.apollo <-> fx.apollo
    String normalizedNamespace = namespaceUtil.normalizeNamespace(appId, originalNamespace);

    // in case client side namespace name has character case issue and has difference notification ids
    // such as FX.apollo = 1 but fx.apollo = 2, we should let FX.apollo have the chance to update its notification id
    // which means we should record FX.apollo = 1 here and ignore fx.apollo = 2
    if (filteredNotifications.containsKey(normalizedNamespace) &&
        filteredNotifications.get(normalizedNamespace).getNotificationId() < notification.getNotificationId()) {
      continue;
    }

    filteredNotifications.put(normalizedNamespace, notification);
  }
  return filteredNotifications;
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:26,代码来源:NotificationControllerV2.java

示例4: checkPath

import com.google.common.base.Strings; //导入依赖的package包/类
/**
 * Produce collection of files found within the given path
 *
 * @param path A file location.
 * @return The list of files at the file location.
 */
static Collection<Path> checkPath(String path) {
	Collection<Path> existingFiles = new LinkedList<>();

	if (Strings.isNullOrEmpty(path)) {
		return existingFiles;
	}
	if (path.contains("*")) {
		return manyPath(path);
	}

	Path file = fileSystem.getPath(path);
	if (Files.exists(file)) {
		existingFiles.add(file);
	} else {
		DEV_LOG.error(FILE_DOES_NOT_EXIST, file.toAbsolutePath());
	}
	return existingFiles;
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:25,代码来源:ConversionEntry.java

示例5: onLogin

import com.google.common.base.Strings; //导入依赖的package包/类
@Override
public CompletableFuture<Long> onLogin(ChannelHandlerContext ctx, SocketASK ask) {
    // 整个消息就是 token
    ByteString tokenArg = ask.getBody().getArgs(0);
    if (tokenArg == null) {
        logger.info("Token arg must be input.");
        return null;
    }
    String token = tokenArg.toStringUtf8();
    if (Strings.isNullOrEmpty(token)) {
        logger.info("Token arg must be input.");
        return null;
    }
    return CompletableFuture.supplyAsync(() -> {
        String parseToken = new String(BaseEncoding.base64Url().decode(token));
        List<String> tokenChars = Splitter.on('|').splitToList(parseToken);
        return Long.valueOf(tokenArg.toStringUtf8());
    });
}
 
开发者ID:freedompy,项目名称:commelina,代码行数:20,代码来源:NioSocketEventHandlerForAkka.java

示例6: sendMessageToAll

import com.google.common.base.Strings; //导入依赖的package包/类
@Override
public void sendMessageToAll(final List<IncomingMessage> incomingMessageList) {
    final Set<Prefs.UserPrefs> subscribers = PrefsController.instance.getPrefs().getEventListeners();
    es.submit(new Runnable() {
        @Override
        public void run() {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(botService.getString(com.rai220.securityalarmbot.R.string.incoming_messages));
            for (IncomingMessage message : incomingMessageList) {
                stringBuilder.append(message.getPhone());
                if (!Strings.isNullOrEmpty(message.getName())) {
                    stringBuilder.append(" (").append(message.getName()).append(")");
                }
                stringBuilder.append(": \"").append(message.getMessage()).append("\"\n");
            }

            for (final Prefs.UserPrefs user : subscribers) {
                bot.execute(new SendMessage(user.lastChatId, stringBuilder.toString()));
            }
        }
    });
}
 
开发者ID:Rai220,项目名称:Telephoto,代码行数:23,代码来源:TelegramService.java

示例7: updateTileViewModel

import com.google.common.base.Strings; //导入依赖的package包/类
@Subscribe
public final void updateTileViewModel( final BuildTypeData data ) {
    if ( data != _buildTypeData )
        return;

    Platform.runLater( ( ) -> {
        _displayedName.set( Strings.isNullOrEmpty( data.getAliasName( ) ) ? data.getName( ) : data.getAliasName( ) );
        _running.setValue( data.hasRunningBuild( ) );
        _queued.setValue( data.isQueued( ) );

        updateLastFinishedDate( );
        updateTimeLeft( );
        updatePercentageComplete( );
        updateBackground( );
        updateIcon( );
    } );
}
 
开发者ID:u2032,项目名称:wall-t,代码行数:18,代码来源:TileViewModel.java

示例8: filterRequest

import com.google.common.base.Strings; //导入依赖的package包/类
@Override
public FilterResult filterRequest(HttpServletRequest request, HttpServletResponse response) throws IOException,
	ServletException
{
	if( CurrentInstitution.get() != null )
	{
		String path = (request.getServletPath() + Strings.nullToEmpty(request.getPathInfo())).substring(1);

		// Disallow overriding of CSS files supplied by plugins. Clients
		// should always override CSS rules in customer.css
		if( CSS_PROVIDED_BY_PLUGIN.matcher(path).matches() )
		{
			return FilterResult.FILTER_CONTINUE;
		}

		// Remove the version number from the path which is there to
		// facilitate long expiry dates.
		final Matcher m = REMOVE_VERSION_FROM_PATH.matcher(path);
		if( m.matches() )
		{
			path = "p/r/" + m.group(1);
		}

		CustomisationFile customFile = new CustomisationFile();
		if( fileService.fileExists(customFile, path) )
		{
			String mimeType = mimeTypeService.getMimeTypeForFilename(path);
			FileContentStream contentStream = fileService.getContentStream(customFile, path, mimeType);
			contentStreamWriter.outputStream(request, response, contentStream);
			response.flushBuffer();
		}
	}
	return FilterResult.FILTER_CONTINUE;
}
 
开发者ID:equella,项目名称:Equella,代码行数:35,代码来源:CustomerFilter.java

示例9: addNewExample

import com.google.common.base.Strings; //导入依赖的package包/类
void addNewExample(Example origEx) {
  // Create the new example, but only add relevant information.
  Example ex = new Example.Builder()
      .setId(origEx.id)
      .setUtterance(origEx.utterance)
      .setContext(origEx.context)
      .setTargetFormula(origEx.targetFormula)
      .setTargetValue(origEx.targetValue)
      .createExample();

  if (!Strings.isNullOrEmpty(opts.newExamplesPath)) {
    LogInfo.begin_track("Adding new example");
    Dataset.appendExampleToFile(opts.newExamplesPath, ex);
    LogInfo.end_track();
  }

  if (opts.onlineLearnExamples) {
    LogInfo.begin_track("Updating parameters");
    learner.onlineLearnExample(origEx);
    if (!Strings.isNullOrEmpty(opts.newParamsPath))
      builder.params.write(opts.newParamsPath);
    LogInfo.end_track();
  }
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:25,代码来源:Master.java

示例10: getUrl

import com.google.common.base.Strings; //导入依赖的package包/类
@Override
public String getUrl() {
    String name = "e";
    try {
        name = URLEncoder.encode(getEvent().map(Event::getName)
                .map(newName -> newName.replace(" ", "_"))
                .map(newName -> newName.replace("/", ""))
                .map(newName -> Strings.padStart(newName, 1, 'e'))
                .orElse("#"), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        logger.info("[Occurrence] [getUrl] Failure To Encode URL", e);
    }

    return String.format(
            "/Events/%s/%s?startTime=%s",
            getEvent().map(Event::getIdBase64).orElse(""),
            name, // uuidToBase64(getEvent().getId()),
            String.valueOf(getStartTime().getMillis())
    );
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:21,代码来源:Occurrence.java

示例11: renderDebugInfoLeft

import com.google.common.base.Strings; //导入依赖的package包/类
protected void renderDebugInfoLeft()
{
    List list = this.call();

    for (int i = 0; i < list.size(); ++i)
    {
        String s = (String)list.get(i);

        if (!Strings.isNullOrEmpty(s))
        {
            int j = this.fontRenderer.FONT_HEIGHT;
            int k = this.fontRenderer.getStringWidth(s);
            boolean flag = true;
            int l = 2 + j * i;
            drawRect(1, l - 1, 2 + k + 1, l + j - 1, -1873784752);
            this.fontRenderer.drawString(s, 2, l, 14737632);
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:20,代码来源:GuiOverlayDebug.java

示例12: create

import com.google.common.base.Strings; //导入依赖的package包/类
/**
 * Creates a {@link FileSelection selection} with the given file statuses and selection root.
 *
 * @param statuses  list of file statuses
 * @param root  root path for selections
 *
 * @return  null if creation of {@link FileSelection} fails with an {@link IllegalArgumentException}
 *          otherwise a new selection.
 *
 */
private static FileSelection create(StatusType status, final ImmutableList<FileStatus> statuses, final String root) {
  if (statuses == null || statuses.size() == 0) {
    return null;
  }

  final String selectionRoot;
  if (Strings.isNullOrEmpty(root)) {
    throw new IllegalArgumentException("Selection root is null or empty" + root);
  }
  final Path rootPath = handleWildCard(root);
  final URI uri = statuses.get(0).getPath().toUri();
  final Path path = new Path(uri.getScheme(), uri.getAuthority(), rootPath.toUri().getPath());
  selectionRoot = Path.getPathWithoutSchemeAndAuthority(path).toString();
  return new FileSelection(status, statuses, selectionRoot);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:FileSelection.java

示例13: serviceInbox

import com.google.common.base.Strings; //导入依赖的package包/类
public static Topic serviceInbox(@NotNull String serviceName, String inboxName) {
    StringBuilder topic = new StringBuilder();
    topic.append("inbox");

    if (!Strings.isNullOrEmpty(inboxName)) {
        topic.append("_");
        topic.append(inboxName);
    }

    if (Strings.isNullOrEmpty(serviceName)) {
        throw new IllegalArgumentException("service name must not be null or empty");
    }

    topic.append("-");
    topic.append(serviceName);


    return new Topic(topic.toString());
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:20,代码来源:Topic.java

示例14: parametersOk

import com.google.common.base.Strings; //导入依赖的package包/类
static boolean parametersOk(final String[] keys, final String[] values) {
    if (keys == null || values == null) {
        return false;
    }
    if (keys.length != values.length) {
        return false;
    }
    for (final String key : keys) {
        if (Strings.isNullOrEmpty(key)) {
            return false;
        }
    }
    for (final String value : values) {
        if (Strings.isNullOrEmpty(value)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:secondbase,项目名称:secondbase,代码行数:20,代码来源:SecondBaseLogger.java

示例15: hackNatives

import com.google.common.base.Strings; //导入依赖的package包/类
private static void hackNatives()
{
    String paths = System.getProperty("java.library.path");
    String nativesDir = "C:/Users/Sergio/.gradle/caches/minecraft/net/minecraft/natives/1.8";
    
    if (Strings.isNullOrEmpty(paths))
        paths = nativesDir;
    else
        paths += File.pathSeparator + nativesDir;
    
    System.setProperty("java.library.path", paths);
    
    // hack the classloader now.
    try
    {
        final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
        sysPathsField.setAccessible(true);
        sysPathsField.set(null, null);
    }
    catch(Throwable t) {};
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:22,代码来源:GradleStart.java


注:本文中的com.google.common.base.Strings类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。