Java Code Examples for java.util.HashMap#size()
The following examples show how to use
java.util.HashMap#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShardRequestExecutor.java From crate with Apache License 2.0 | 6 votes |
public List<CompletableFuture<Long>> executeBulk(List<Row> bulkParams, SubQueryResults subQueryResults) { HashMap<ShardId, Req> requests = new HashMap<>(); IntArrayList bulkIndices = new IntArrayList(bulkParams.size() * docKeys.size()); int location = 0; for (int resultIdx = 0; resultIdx < bulkParams.size(); resultIdx++) { int prevLocation = location; Row params = bulkParams.get(resultIdx); grouper.bind(params, subQueryResults); location = addRequests(location, params, requests, subQueryResults); for (int i = prevLocation; i < location; i++) { bulkIndices.add(resultIdx); } } BulkShardResponseListener listener = new BulkShardResponseListener(requests.size(), bulkParams.size(), bulkIndices); for (Req req : requests.values()) { transportAction.accept(req, listener); } return listener.rowCountFutures(); }
Example 2
Source File: CommunityDetector.java From StoryForest with GNU General Public License v3.0 | 6 votes |
/** * Extract connected components from a graph. * <p> * @param nodes The graph we want to extract connected components from. * @return cc Array list of sub graphs. Each sub graph is a connected component. */ public ArrayList<HashMap<String, KeywordNode>> findConnectedComponents(HashMap<String, KeywordNode> nodes) { ArrayList<HashMap<String, KeywordNode>> cc = new ArrayList<HashMap<String, KeywordNode>>(); while (nodes.size() > 0) { KeywordNode source = nodes.values().iterator().next(); HashMap<String, KeywordNode> subNodes = new HashMap<String, KeywordNode>(); ArrayList<KeywordNode> q = new ArrayList<KeywordNode>(); q.add(0, source); while (q.size() > 0) { KeywordNode n = q.remove(0); n.visited = true; nodes.remove(n.keyword.baseForm); subNodes.put(n.keyword.baseForm, n); for (KeywordEdge e : n.edges.values()) { KeywordNode n2 = e.opposite(n); if (!n2.visited) { n2.visited = true; q.add(n2); } } } cc.add(subNodes); } return cc; }
Example 3
Source File: ARAMNetworkSparseH.java From meka with GNU General Public License v3.0 | 6 votes |
private double ART_Calculate_MatchB(double[] Data, HashMap fweights, double suminput ) { if (suminput == 0) { return 0.0; } int lnumFeatures = Data.length; if (lnumFeatures != fweights.size()) { return 0.0; } double[] matchVector = new double[lnumFeatures]; double summatch = 0; //double suminput = 0; for (int j = 0; j < lnumFeatures; j++) { double w =(Double) fweights.get(j); matchVector[j] = ((Data[j] < w) ? Data[j] :w); summatch += matchVector[j]; //suminput += Data[j]; } return summatch / suminput; }
Example 4
Source File: FilesHandlers.java From TelegramBotsExample with GNU General Public License v3.0 | 6 votes |
private void onDeleteCommandWithoutParameters(Message message, String language) throws InvalidObjectException, TelegramApiException { DatabaseManager.getInstance().addUserForFile(message.getFrom().getId(), DELETE_UPLOADED_STATUS); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText(LocalisationService.getString("deleteUploadedFile", language)); sendMessageRequest.setChatId(message.getChatId()); HashMap<String, String> files = DatabaseManager.getInstance().getFilesByUser(message.getFrom().getId()); ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup(); if (files.size() > 0) { List<KeyboardRow> commands = new ArrayList<>(); for (Map.Entry<String, String> entry : files.entrySet()) { KeyboardRow commandRow = new KeyboardRow(); commandRow.add(Commands.deleteCommand + " " + entry.getKey() + " " + Emoji.LEFT_RIGHT_ARROW.toString() + " " + entry.getValue()); commands.add(commandRow); } replyKeyboardMarkup.setResizeKeyboard(true); replyKeyboardMarkup.setOneTimeKeyboard(true); replyKeyboardMarkup.setKeyboard(commands); } sendMessageRequest.setReplyMarkup(replyKeyboardMarkup); execute(sendMessageRequest); }
Example 5
Source File: EcrfFieldValueBean.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
public void setInputModelErrorMsgs(Object data) { HashMap<Long, HashMap<Long, String>> errorMessagesMap; try { errorMessagesMap = (HashMap<Long, HashMap<Long, String>>) data; } catch (ClassCastException e) { errorMessagesMap = null; } if (errorMessagesMap != null && errorMessagesMap.size() > 0) { Iterator<EcrfFieldInputModelList> modelListIt = inputModelsMap.values().iterator(); while (modelListIt.hasNext()) { Iterator<EcrfFieldInputModel> modelIt = modelListIt.next().iterator(); while (modelIt.hasNext()) { EcrfFieldInputModel inputModel = modelIt.next(); HashMap<Long, String> indexErrorMessagesMap = errorMessagesMap.get(inputModel.getEcrfFieldId()); if (indexErrorMessagesMap != null && indexErrorMessagesMap.containsKey(inputModel.getSeriesIndex())) { inputModel.setErrorMessage(indexErrorMessagesMap.get(inputModel.getSeriesIndex())); } else { inputModel.setErrorMessage(null); } } } } else { clearInputModelErrorMsgs(); } }
Example 6
Source File: RunAsAppFormDeviceHandler.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) public List<IOSDevice> getIosDevice(){ List<IOSDevice> iMobiles = new ArrayList<IOSDevice>(); HashMap<String, IOSDevice> ideviceMap = IOSDevice.connectedDevices; if(ideviceMap.size()>0){ Iterator iterator = ideviceMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, IOSDevice> entry = (Entry<String, IOSDevice>) iterator .next(); iMobiles.add(entry.getValue()); } } return iMobiles; }
Example 7
Source File: ConfigsFragment.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
@Override public int listViewNumberOfRowsInSection(ListView listView, int section) { String sectionKey = listSectionNames.get(section); if (mapData != null) { HashMap<String,String> mapSectionRows = mapData.get(sectionKey); if( mapSectionRows != null ) { return mapSectionRows.size(); } } return 0; }
Example 8
Source File: Table2Map.java From AML-Project with Apache License 2.0 | 5 votes |
/** * @param keyA: the first level key to search in the Table * @return the number of entries with keyA */ public int entryCount(A keyA) { HashMap<B,C> mapsA = multimap.get(keyA); if(mapsA == null) return 0; return mapsA.size(); }
Example 9
Source File: DataSet.java From moa with GNU General Public License v3.0 | 5 votes |
/** * Counts the number of classes that are present in the data set. * !!! It does not check whether all classes are contained !!! * @return the number of distinct class labels */ public int getNrOfClasses() { HashMap<Integer, Integer> classes = new HashMap<Integer, Integer>(); for (DataObject currentObject : dataList) { if (!classes.containsKey(currentObject.getClassLabel())) classes.put(currentObject.getClassLabel(), 1); } return classes.size(); }
Example 10
Source File: CopyOnWriteStateMapTest.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Tuple3<Integer, Integer, ArrayList<Integer>>[] manualDeepDump( HashMap<Tuple2<Integer, Integer>, ArrayList<Integer>> map) { Tuple3<Integer, Integer, ArrayList<Integer>>[] result = new Tuple3[map.size()]; int pos = 0; for (Map.Entry<Tuple2<Integer, Integer>, ArrayList<Integer>> entry : map.entrySet()) { Integer key = entry.getKey().f0; Integer namespace = entry.getKey().f1; result[pos++] = new Tuple3<>(key, namespace, new ArrayList<>(entry.getValue())); } return result; }
Example 11
Source File: BasicVo.java From mybatis-daoj with Apache License 2.0 | 5 votes |
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof BasicVo)) { return false; } BasicVo vo2 = ((BasicVo) o); HashMap<String, Class<?>> ftMap2 = vo2.fieldNameTypeMap(); if (fieldNameTypeMap.size() != ftMap2.size()) { return false; } try { for (Iterator<String> it = fieldNameTypeMap.keySet().iterator(); it.hasNext(); ) { String filedName = it.next(); Object obj1 = this.get(filedName); Object obj2 = vo2.get(filedName); if (!(obj1 == null ? obj2 == null : obj1.equals(obj2))) { return false; } } } catch (Exception e) { e.printStackTrace(); } return true; }
Example 12
Source File: BeanDaoImpl.java From kripton with Apache License 2.0 | 5 votes |
/** * for param serializer2 serialization */ private byte[] serializer2(HashMap<EnumType, Byte> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; int fieldCount=0; jacksonSerializer.writeStartObject(); if (value!=null) { // write wrapper tag if (value.size()>0) { jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (Map.Entry<EnumType, Byte> item: value.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField(null, item.getKey().toString()); if (item.getValue()==null) { jacksonSerializer.writeNullField(null); } else { jacksonSerializer.writeNumberField(null, item.getValue()); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("element"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 13
Source File: KafkaConnectHdfsProvider.java From hudi with Apache License 2.0 | 5 votes |
@Override public String getCheckpoint() throws HoodieException { final KafkaConnectPathFilter filter = new KafkaConnectPathFilter(); ArrayList<FileStatus> fileStatus; try { fileStatus = listAllFileStatus(this.path, filter); } catch (IOException e) { throw new HoodieException(e.toString()); } if (fileStatus.size() == 0) { throw new HoodieException("No valid Kafka Connect Hdfs file found under:" + this.path.getName()); } final String topic = fileStatus.get(0).getPath().getName().split(FILENAME_SEPARATOR)[0]; int maxPartition = -1; final HashMap<Integer, Integer> checkpointMap = new HashMap<>(); for (final FileStatus status : fileStatus) { final String filename = status.getPath().getName(); final String[] groups = filename.split(FILENAME_SEPARATOR); final int partition = Integer.parseInt(groups[1]); final int offsetUpper = Integer.parseInt(groups[3]); maxPartition = Math.max(maxPartition, partition); if (checkpointMap.containsKey(partition)) { checkpointMap.put(partition, Math.max(checkpointMap.get(partition), offsetUpper)); } else { checkpointMap.put(partition, offsetUpper); } } if (checkpointMap.size() != maxPartition + 1) { throw new HoodieException("Missing partition from the file scan, " + "max partition found(start from 0): " + maxPartition + " total partitions number appear in " + this.path.getName() + " is: " + checkpointMap.size() + " total partitions number expected: " + (maxPartition + 1)); } return buildCheckpointStr(topic, checkpointMap); }
Example 14
Source File: ReadOnceTreeLoader.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public boolean hasChildren(Object element){ HashMap children = allNodes.get(element); if (children == null) { return getChildren(element).length > 0; } return children.size() > 0; }
Example 15
Source File: HttpKit.java From tieba-api with MIT License | 5 votes |
/** * 构建header头信息 * @param headerMaps headerMaps * @return Header[] */ public Header[] build(HashMap<String, Header> headerMaps) { Header[] headers = new Header[headerMaps.size()]; int i = 0; for (Header header : headerMaps.values()) { headers[i] = header; i++; } headerMaps.clear(); headerMaps = null; return headers; }
Example 16
Source File: HAManager.java From DDMQ with Apache License 2.0 | 4 votes |
public RoleChangeInfo selectNewMaster(String cluster, String brokerName) { BrokerData brokerData = namesrvController.getRouteInfoManager().getBrokerData(brokerName); if (brokerData == null || !cluster.equals(brokerData.getCluster())) { log.warn("no broker data for broker name:{}, broker data:{}", brokerName, brokerData); return null; } HashMap<Long, String> brokerAddrs = new HashMap<>(brokerData.getBrokerAddrs()); for (Iterator<Map.Entry<Long, String>> it = brokerAddrs.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Long, String> item = it.next(); if (item.getKey() > namesrvController.getNamesrvConfig().getMaxIdForRoleSwitch()) { it.remove(); } } //no broker if (brokerAddrs == null || brokerAddrs.isEmpty()) { log.warn("no broker addrs, for broker name:{}, broker data:{}", brokerName, brokerData); return null; } //only one, and master if (brokerAddrs.size() == 1 && brokerAddrs.get(MixAll.MASTER_ID) != null) { log.warn("only on broker, but it is current master"); return null; } //slave exist RoleChangeInfo roleChangeInfo = new RoleChangeInfo(); SortedSet<Long> ids = new TreeSet<>(brokerAddrs.keySet()); if (ids.first() == MixAll.MASTER_ID) { roleChangeInfo.oldMaster = new RoleInChange(brokerAddrs.get(ids.first()), ids.first(), ids.last() + 1); } long newMasterId = pickMaster(brokerAddrs); if (newMasterId == -1) { //newMasterId = ids.last(); log.error("do not get master, broker name:{}", brokerName); return null; } roleChangeInfo.newMaster = new RoleInChange(brokerAddrs.get(newMasterId), newMasterId, MixAll.MASTER_ID); return roleChangeInfo; }
Example 17
Source File: LockSpace.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** Add a lock to a group. */ protected synchronized void addLock(Object group, Lock lock) throws StandardException { Lock lockInGroup = null; HashMap dl = (HashMap) groups.get(group); if (dl == null) { dl = getGroupMap(group); } else if (lock.getCount() != 1) { lockInGroup = (Lock) dl.get(lock); } if (lockInGroup == null) { lockInGroup = lock.copy(); dl.put(lockInGroup, lockInGroup); } lockInGroup.count++; if (inLimit) return; if (!group.equals(callbackGroup)) return; int groupSize = dl.size(); if (groupSize > nextLimitCall) { inLimit = true; callback.reached(this, group, limit, new LockList(java.util.Collections.enumeration(dl.keySet())), groupSize); inLimit = false; // see when the next callback should occur, if the callback // failed to release a sufficent amount of locks then // delay until another "limit" locks are obtained. int newGroupSize = dl.size(); if (newGroupSize < (limit / 2)) nextLimitCall = limit; else if (newGroupSize < (nextLimitCall / 2)) nextLimitCall -= limit; else nextLimitCall += limit; } }
Example 18
Source File: JobControlCompiler.java From spork with Apache License 2.0 | 4 votes |
/** * Reads the global counters produced by a job on the group labeled with PIG_MAP_RANK_NAME. * Then, it is calculated the cumulative sum, which consists on the sum of previous cumulative * sum plus the previous global counter value. * @param job with the global counters collected. * @param operationID After being collected on global counters (POCounter), * these values are passed via configuration file to PORank, by using the unique * operation identifier */ private void saveCounters(Job job, String operationID) { Counters counters; Group groupCounters; Long previousValue = 0L; Long previousSum = 0L; ArrayList<Pair<String,Long>> counterPairs; try { counters = HadoopShims.getCounters(job); String groupName = getGroupName(counters.getGroupNames()); // In case that the counter group was not find, we need to find // out why. Only acceptable state is that the relation has been // empty. if (groupName == null) { Counter outputRecords = counters.getGroup(MRPigStatsUtil.TASK_COUNTER_GROUP) .getCounterForName(MRPigStatsUtil.MAP_OUTPUT_RECORDS); if(outputRecords.getCounter() == 0) { globalCounters.put(operationID, new ArrayList<Pair<String, Long>>()); return; } else { throw new RuntimeException("Did not found RANK counter group for operationId: " + operationID); } } groupCounters = counters.getGroup(groupName); Iterator<Counter> it = groupCounters.iterator(); HashMap<Integer,Long> counterList = new HashMap<Integer, Long>(); while(it.hasNext()) { try{ Counter c = it.next(); counterList.put(Integer.valueOf(c.getDisplayName()), c.getValue()); } catch (Exception ex) { ex.printStackTrace(); } } counterSize = counterList.size(); counterPairs = new ArrayList<Pair<String,Long>>(); for(int i = 0; i < counterSize; i++){ previousSum += previousValue; previousValue = counterList.get(Integer.valueOf(i)); counterPairs.add(new Pair<String, Long>(JobControlCompiler.PIG_MAP_COUNTER + operationID + JobControlCompiler.PIG_MAP_SEPARATOR + i, previousSum)); } globalCounters.put(operationID, counterPairs); } catch (Exception e) { String msg = "Error to read counters into Rank operation counterSize "+counterSize; throw new RuntimeException(msg, e); } }
Example 19
Source File: ValiditySegmentCache.java From OpenRate with Apache License 2.0 | 4 votes |
/** * processControlEvent is the method that will be called when an event * is received for a module that has registered itself as a client of the * External Control Interface * * @param Command - command that is understand by the client module * @param Init - we are performing initial configuration if true * @param Parameter - parameter for the command * @return The result string of the operation */ @Override public String processControlEvent(String Command, boolean Init, String Parameter) { HashMap<String, ValidityNode> tmpResource; Collection<String> tmpGroups; Iterator<String> GroupIter; String tmpGroupName; int Objects = 0; int ResultCode = -1; // Return the number of objects in the cache if (Command.equalsIgnoreCase(SERVICE_GROUP_COUNT)) { return Integer.toString(GroupCache.size()); } if (Command.equalsIgnoreCase(SERVICE_OBJECT_COUNT)) { tmpGroups = GroupCache.keySet(); GroupIter = tmpGroups.iterator(); while (GroupIter.hasNext()) { tmpGroupName = GroupIter.next(); tmpResource = GroupCache.get(tmpGroupName); Objects += tmpResource.size(); } return Integer.toString(Objects); } if (ResultCode == 0) { OpenRate.getOpenRateFrameworkLog().debug(LogUtil.LogECICacheCommand(getSymbolicName(), Command, Parameter)); return "OK"; } else { return super.processControlEvent(Command,Init,Parameter); } }
Example 20
Source File: Tr069DMAdapter.java From SI with BSD 2-Clause "Simplified" License | 3 votes |
protected Document execute(String deviceId, HashMap<String, Object> mos) throws HitDMException { if(timeout < 0) { timeout = 3000; } String to = "/devices/" + deviceId + "/tasks?timeout=" + this.timeout + "&connection_request"; Document content = new Document(); content.put("name", "setParameterValues"); List<Object> resultParams = new ArrayList<Object>(); if(mos.size() > 0) { List<Object> keyValue = null; for(Iterator it = mos.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); Object value = mos.get(key); keyValue = new ArrayList<Object>(); keyValue.add(key); keyValue.add(value); resultParams.add(keyValue); keyValue = null; } } content.put("parameterValues", resultParams); Document resultDoc = callPostApi(to, content); return resultDoc; }