下面列出了com.google.common.collect.BiMap#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns the index of the entry that match the specified search string, or
* <code>-1</code> if the string can not be found when searching using the
* given options.
*
* @param findString
* the string to search for
* @param startIndex
* the index at which to start the search
* @param items
* The map of items in the time graph view
* @param options
* The options use for the search
* @return the index of the find entry following the options or
* <code>-1</code> if nothing found
*/
private int findNext(String findString, int startIndex, BiMap<ITimeGraphEntry, Integer> items, SearchOptions options) {
int index;
if (options.forwardSearch) {
index = startIndex == items.size() - 1 ? -1 : findNext(startIndex + 1, findString, items, options);
} else {
index = startIndex == 0 ? -1 : findNext(startIndex - 1, findString, items, options);
}
if (index == -1) {
if (okToUse(getShell())) {
getShell().getDisplay().beep();
}
if (options.wrapSearch) {
statusMessage(Messages.TimeGraphFindDialog_StatusWrappedLabel);
index = findNext(-1, findString, items, options);
}
}
return index;
}
private int findNext(int startIndex, String findString, BiMap<ITimeGraphEntry, Integer> items, SearchOptions options) {
FindTarget findTarget = fFindTarget;
if (findTarget != null) {
if (findString == null || findString.length() == 0) {
return -1;
}
final @NonNull Pattern pattern = getPattern(findString, options);
int index = adjustIndex(startIndex, items.size(), options.forwardSearch);
BiMap<Integer, ITimeGraphEntry> entries = items.inverse();
while (index >= 0 && index < entries.size()) {
final @Nullable ITimeGraphEntry entry = entries.get(index);
if (entry != null) {
String[] columnTexts = findTarget.getColumnTexts(entry);
for (int i = 0; i < columnTexts.length; i++) {
String columnText = columnTexts[i];
if (columnText != null && !columnText.isEmpty() && pattern.matcher(columnTexts[i]).find()) {
return index;
}
}
}
index = options.forwardSearch ? ++index : --index;
}
}
return -1;
}
/**
* Gets the ID of a BiMap
*
* @param map
* @param value
* @return
*/
public int getID(BiMap<Integer, String> map, String value) {
if (map.containsValue(value)) {
return map.inverse().get(value);
} else {
int size = map.size();
map.put(size + 1, value);
return size + 1;
}
}
/**
* This test indexes a specified number of values in the class being tested and checks correctness by
* comparing results against {@link BiMap} for the same input.
* <ul>
* <li> Size of the map (cardinality) should be as expected. </li>
* <li> For each value, id should be as expected. </li>
* <li> For each id, should return the expected value back. </li>
* </ul>
*/
@Test
public void test() {
BiMap<FixedIntArray, Integer> expectedMap = addValues(_idMap);
int numValues = expectedMap.size();
// Test invalid Value
Assert.assertEquals(_idMap.getId(new FixedIntArray(new int[]{})), IdMap.INVALID_ID);
Assert.assertEquals(_idMap.size(), numValues);
testValues(expectedMap);
}
public Map<String, List<SegmentSizeInfo>> getSegmentSizeInfoFromServers(BiMap<String, String> serverEndPoints,
String tableNameWithType, int timeoutMs) {
int numServers = serverEndPoints.size();
LOGGER.info("Reading segment sizes from {} servers for table: {} with timeout: {}ms", numServers, tableNameWithType,
timeoutMs);
List<String> serverUrls = new ArrayList<>(numServers);
BiMap<String, String> endpointsToServers = serverEndPoints.inverse();
for (String endpoint : endpointsToServers.keySet()) {
String tableSizeUri = "http://" + endpoint + "/table/" + tableNameWithType + "/size";
serverUrls.add(tableSizeUri);
}
// TODO: use some service other than completion service so that we know which server encounters the error
CompletionService<GetMethod> completionService =
new MultiGetRequest(_executor, _connectionManager).execute(serverUrls, timeoutMs);
Map<String, List<SegmentSizeInfo>> serverToSegmentSizeInfoListMap = new HashMap<>();
for (int i = 0; i < numServers; i++) {
GetMethod getMethod = null;
try {
getMethod = completionService.take().get();
URI uri = getMethod.getURI();
String instance = endpointsToServers.get(uri.getHost() + ":" + uri.getPort());
if (getMethod.getStatusCode() >= 300) {
LOGGER.error("Server: {} returned error: {}", instance, getMethod.getStatusCode());
continue;
}
TableSizeInfo tableSizeInfo =
JsonUtils.inputStreamToObject(getMethod.getResponseBodyAsStream(), TableSizeInfo.class);
serverToSegmentSizeInfoListMap.put(instance, tableSizeInfo.segments);
} catch (Exception e) {
// Ignore individual exceptions because the exception has been logged in MultiGetRequest
// Log the number of failed servers after gathering all responses
} finally {
if (getMethod != null) {
getMethod.releaseConnection();
}
}
}
int numServersResponded = serverToSegmentSizeInfoListMap.size();
if (numServersResponded != numServers) {
LOGGER.warn("Finish reading segment sizes for table: {} with {}/{} servers responded", tableNameWithType,
numServersResponded, numServers);
} else {
LOGGER.info("Finish reading segment sizes for table: {}", tableNameWithType);
}
return serverToSegmentSizeInfoListMap;
}
public MiningModelEvaluationContext(MiningModelEvaluator miningModelEvaluator){
super(miningModelEvaluator);
BiMap<String, Segment> entityRegistry = miningModelEvaluator.getEntityRegistry();
this.results = new HashMap<>(2 * entityRegistry.size());
}