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


Java Preconditions.checkNotNull方法代码示例

本文整理汇总了Java中com.stackify.api.common.util.Preconditions.checkNotNull方法的典型用法代码示例。如果您正苦于以下问题:Java Preconditions.checkNotNull方法的具体用法?Java Preconditions.checkNotNull怎么用?Java Preconditions.checkNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.stackify.api.common.util.Preconditions的用法示例。


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

示例1: autoReportLast

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Auto reports any metrics that are missing a value from the current iteration
 * @param autoMetrics The metrics that need to me auto reported as the last value
 */
public void autoReportLast(final Set<MetricIdentity> autoMetrics) {
	Preconditions.checkNotNull(autoMetrics);
	
	for (MetricIdentity identity : autoMetrics) {
		if (!aggregateExistsForCurrentMinute(identity)) {
			MetricAggregate aggregate = getAggregate(identity);
			
			aggregate.setCount(1);
			
			if (lastValues.containsKey(identity)) {
				aggregate.setValue(lastValues.get(identity));
			} else {
				aggregate.setValue(0.0);					
			}
		}
	}
}
 
开发者ID:stackify,项目名称:stackify-metrics,代码行数:22,代码来源:MetricAggregator.java

示例2: getSessionAttributes

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Returns a Map from session attribute name to masked value
 * @param request The HTTP servlet request
 * @return Map from session attribute name to masked value
 */
private static Map<String, String> getSessionAttributes(final HttpServletRequest request) {
	Preconditions.checkNotNull(request);

	HttpSession session = request.getSession(false);
	
	if (session != null) {
		
		@SuppressWarnings("unchecked")
		Enumeration<String> attributeNames = session.getAttributeNames();
		
		if ((attributeNames != null) && (attributeNames.hasMoreElements())) {
			
			Map<String, String> attributeMap = new HashMap<String, String>();
			
			while (attributeNames.hasMoreElements()) {
				String name = attributeNames.nextElement();
				attributeMap.put(name, MASKED);
			}
			
			return attributeMap;
		}			
	}
	
	return null;
}
 
开发者ID:stackify,项目名称:stackify-log-servlet,代码行数:31,代码来源:HttpServletRequests.java

示例3: getCookies

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Returns a Map from cookie name to masked value
 * @param request The HTTP servlet request
 * @return Map from cookie name to masked value
 */
private static Map<String, String> getCookies(final HttpServletRequest request) {
	Preconditions.checkNotNull(request);

	Cookie[] cookies = request.getCookies();
	
	if ((cookies != null) && (0 < cookies.length)) {
		
		Map<String, String> cookieMap = new HashMap<String, String>();
		
		for (int i = 0; i < cookies.length; ++i) {
			Cookie cookie = cookies[i];				
			String name = cookie.getName();
			cookieMap.put(name, MASKED);
		}

		return cookieMap;
	}
	
	return null;
}
 
开发者ID:stackify,项目名称:stackify-log-servlet,代码行数:26,代码来源:HttpServletRequests.java

示例4: MetricSender

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Constructor
 * @param apiConfig API configuration
 * @param objectMapper JSON object mapper
 * @param monitorService Monitor service
 */
public MetricSender(final ApiConfiguration apiConfig, final ObjectMapper objectMapper, final MetricMonitorService monitorService) {
	Preconditions.checkNotNull(apiConfig);
	Preconditions.checkNotNull(objectMapper);
	Preconditions.checkNotNull(monitorService);
	this.apiConfig = apiConfig;
	this.objectMapper = objectMapper;
	this.monitorService = monitorService;
}
 
开发者ID:stackify,项目名称:stackify-metrics,代码行数:15,代码来源:MetricSender.java

示例5: toMap

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Returns a Map from query parameter name to value
 * @param request The HTTP servlet request
 * @return Map from query parameter name to value
 */
public static Map<String, String> toMap(final String queryString) {
	Preconditions.checkNotNull(queryString);

	Map<String, String> queryMap = new HashMap<String, String>();

	String decoded = queryString;
	
	try {
		decoded = URLDecoder.decode(queryString, "UTF-8");
	} catch (UnsupportedEncodingException e) {
		// do nothing
	}
	
	String[] params = decoded.split("[&;]");
	
	if ((params != null) && (0 < params.length)) {
	
		for (String param : params) {

			String[] kv = param.split("=");
			
			if ((kv != null) && (kv.length == 2)) {
			
				String key = kv[0];
				String value = kv[1];
				
				if (queryMap.containsKey(key)) {
					value = queryMap.get(key) + "," + value;
				}
				
				queryMap.put(key, value);
			}
		}
	}
	
	return queryMap;
}
 
开发者ID:stackify,项目名称:stackify-log-servlet,代码行数:43,代码来源:QueryStrings.java

示例6: MetricIdentity

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Constructor
 * @param category Metric category
 * @param name Metric name
 * @param type Metric monitor type
 */
public MetricIdentity(final String category, final String name, final MetricMonitorType type) {
	Preconditions.checkNotNull(category);
	Preconditions.checkArgument(!category.isEmpty());
	Preconditions.checkNotNull(name);
	Preconditions.checkArgument(!name.isEmpty());
	Preconditions.checkNotNull(type);
	
	this.category = category;
	this.name = name;
	this.type = type;
}
 
开发者ID:stackify,项目名称:stackify-metrics,代码行数:18,代码来源:MetricIdentity.java

示例7: MetricMonitorService

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Constructor
 * @param apiConfig API configuration
 * @param objectMapper JSON object mapper
 * @param appIdentityService Application identity service
 */
public MetricMonitorService(final ApiConfiguration apiConfig, final ObjectMapper objectMapper, final AppIdentityService appIdentityService) {
	Preconditions.checkNotNull(apiConfig);
	Preconditions.checkNotNull(objectMapper);
	Preconditions.checkNotNull(appIdentityService);
	this.apiConfig = apiConfig;
	this.objectMapper = objectMapper;
	this.appIdentityService = appIdentityService;
}
 
开发者ID:stackify,项目名称:stackify-metrics,代码行数:15,代码来源:MetricMonitorService.java

示例8: MetricAggregator

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Constructor
 * @param currentMinute Current minute
 * @param lastValues Last values for the metrics
 */
public MetricAggregator(final long currentMinute, final Map<MetricIdentity, Double> lastValues) {
	Preconditions.checkArgument(0 < currentMinute);
	Preconditions.checkNotNull(lastValues);
	this.currentMinute = currentMinute;
	this.lastValues = lastValues;
}
 
开发者ID:stackify,项目名称:stackify-metrics,代码行数:12,代码来源:MetricAggregator.java

示例9: add

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Aggregates a single metric into the collection of aggregates
 * @param metric The metric
 */
public void add(final Metric metric) {
	Preconditions.checkNotNull(metric);
	
	// get the aggregate for this minute
	
	MetricAggregate aggregate = getAggregate(metric.getIdentity());
	
	// add the current metric into the aggregate
	
	switch (metric.getIdentity().getType()) {
		case COUNTER: 
		case TIMER: 
		case AVERAGE:
			aggregate.setCount(aggregate.getCount() + 1);
			aggregate.setValue(aggregate.getValue() + metric.getValue());
		    break;
		case GAUGE:
			aggregate.setCount(1);
			if (metric.isIncrement()) {
				aggregate.setValue(aggregate.getValue() + metric.getValue());
			} else {
				aggregate.setValue(metric.getValue());
			}
		    break;	
		default:
			LOGGER.info("Unable to aggregate {} metric type", metric.getIdentity().getType());
			break;
	}
}
 
开发者ID:stackify,项目名称:stackify-metrics,代码行数:34,代码来源:MetricAggregator.java

示例10: autoReportZero

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Auto reports any metrics that are missing a value from the current iteration
 * @param autoMetrics The metrics that need to me auto reported as zero
 */
public void autoReportZero(final Set<MetricIdentity> autoMetrics) {
	Preconditions.checkNotNull(autoMetrics);
	
	for (MetricIdentity identity : autoMetrics) {
		if (!aggregateExistsForCurrentMinute(identity)) {
			MetricAggregate aggregate = getAggregate(identity);
			
			aggregate.setCount(1);
			aggregate.setValue(0.0);
		}
	}
}
 
开发者ID:stackify,项目名称:stackify-metrics,代码行数:17,代码来源:MetricAggregator.java

示例11: aggregateExistsForCurrentMinute

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Determines if the specified aggregate metric exists for the current minute
 * @param identity The metric identity
 * @return True if the metric exists, false otherwise
 */
private boolean aggregateExistsForCurrentMinute(final MetricIdentity identity) {
	Preconditions.checkNotNull(identity);
	
	if (aggregates.containsKey(identity)) {			
		if (aggregates.get(identity).containsKey(currentMinute)) {
			return true;
		}
	}
	
	return false;
}
 
开发者ID:stackify,项目名称:stackify-metrics,代码行数:17,代码来源:MetricAggregator.java

示例12: addAll

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * @see java.util.Collection#addAll(java.util.Collection)
 */
@Override
public synchronized boolean addAll(Collection<? extends E> c) {
	Preconditions.checkNotNull(c);
	
	for (E e : c) {
		add(e);
	}
	
	return true;
}
 
开发者ID:stackify,项目名称:stackify-api-java,代码行数:14,代码来源:SynchronizedEvictingQueue.java

示例13: add

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * @see java.util.Queue#add(java.lang.Object)
 */
@Override
public synchronized boolean add(E e) {
	Preconditions.checkNotNull(e);
	
	if (deque.size() == maxSize) {
		deque.remove();
	}
	
	deque.add(e);
	
	return true;
}
 
开发者ID:stackify,项目名称:stackify-api-java,代码行数:16,代码来源:SynchronizedEvictingQueue.java

示例14: send

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Sends a group of log messages to Stackify
 * @param group The log message group
 * @return The HTTP status code returned from the HTTP POST
 * @throws IOException
 */
public int send(final LogMsgGroup group) throws IOException {
	Preconditions.checkNotNull(group);

	executeMask(group);
	executeSkipJsonTag(group);

	HttpClient httpClient = new HttpClient(apiConfig);

	// retransmit any logs on the resend queue

	resendQueue.drain(httpClient, LOG_SAVE_PATH, true);

	// convert to json bytes

	byte[] jsonBytes = objectMapper.writer().writeValueAsBytes(group);

	// post to stackify

	int statusCode = HttpURLConnection.HTTP_INTERNAL_ERROR;

	try {
		httpClient.post(LOG_SAVE_PATH, jsonBytes, true);
		statusCode = HttpURLConnection.HTTP_OK;
	} catch (IOException t) {
		LOGGER.info("Queueing logs for retransmission due to IOException");
		resendQueue.offer(jsonBytes, t);
		throw t;
	} catch (HttpException e) {
		statusCode = e.getStatusCode();
		LOGGER.info("Queueing logs for retransmission due to HttpException", e);
		resendQueue.offer(jsonBytes, e);
	}

	return statusCode;
}
 
开发者ID:stackify,项目名称:stackify-api-java,代码行数:42,代码来源:LogSender.java

示例15: LogBackgroundService

import com.stackify.api.common.util.Preconditions; //导入方法依赖的package包/类
/**
 * Constructor
 * @param collector The LogMsg collector
 * @param sender The LogMsgGroup HTTP sender
 */
public LogBackgroundService(final LogCollector collector, final LogSender sender) {
	Preconditions.checkNotNull(collector);
	Preconditions.checkNotNull(sender);
	this.collector = collector;
	this.sender = sender;
}
 
开发者ID:stackify,项目名称:stackify-api-java,代码行数:12,代码来源:LogBackgroundService.java


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