java.util.HashMap#values ( )源码实例Demo

下面列出了java.util.HashMap#values ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: metanome-algorithms   文件: PLIBuilder.java
protected static List<PositionListIndex> fetchPositionListIndexesStatic(List<HashMap<String, IntArrayList>> clusterMaps, boolean isNullEqualNull) {
	List<PositionListIndex> clustersPerAttribute = new ArrayList<>();
	for (int columnId = 0; columnId < clusterMaps.size(); columnId++) {
		List<IntArrayList> clusters = new ArrayList<>();
		HashMap<String, IntArrayList> clusterMap = clusterMaps.get(columnId);
		
		if (!isNullEqualNull)
			clusterMap.remove(null);
		
		for (IntArrayList cluster : clusterMap.values())
			if (cluster.size() > 1)
				clusters.add(cluster);
		
		clustersPerAttribute.add(new PositionListIndex(columnId, clusters));
	}
	return clustersPerAttribute;
}
 
源代码2 项目: hbase   文件: HMaster.java
public HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>>
    getReplicationLoad(ServerName[] serverNames) {
  List<ReplicationPeerDescription> peerList = this.getReplicationPeerManager().listPeers(null);
  if (peerList == null) {
    return null;
  }
  HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>> replicationLoadSourceMap =
      new HashMap<>(peerList.size());
  peerList.stream()
      .forEach(peer -> replicationLoadSourceMap.put(peer.getPeerId(), new ArrayList<>()));
  for (ServerName serverName : serverNames) {
    List<ReplicationLoadSource> replicationLoadSources =
        getServerManager().getLoad(serverName).getReplicationLoadSourceList();
    for (ReplicationLoadSource replicationLoadSource : replicationLoadSources) {
      replicationLoadSourceMap.get(replicationLoadSource.getPeerID())
          .add(new Pair<>(serverName, replicationLoadSource));
    }
  }
  for (List<Pair<ServerName, ReplicationLoadSource>> loads : replicationLoadSourceMap.values()) {
    if (loads.size() > 0) {
      loads.sort(Comparator.comparingLong(load -> (-1) * load.getSecond().getReplicationLag()));
    }
  }
  return replicationLoadSourceMap;
}
 
public static void main(String[] args) {

    //create HashMap object
    HashMap hMap = new HashMap();

    //add key value pairs to HashMap
    hMap.put("1", "One");
    hMap.put("2", "Two");
    hMap.put("3", "Three");

    /*
      get Collection of values contained in HashMap using
      Collection values() method of HashMap class
    */
    Collection c = hMap.values();

    //obtain an Iterator for Collection
    Iterator itr = c.iterator();

    //iterate through HashMap values iterator
    while (itr.hasNext()) System.out.println(itr.next());
  }
 
源代码4 项目: OSPREY3   文件: PositionConfSpace.java
public int maxNumRCsPerResType(){
    //maximum (over all residue types) of the number of RCs of that residue type
    HashMap<String,Integer> resTypeRCCounts = new HashMap<>();
    
    for(RC rc : RCs){
        String type = rc.AAType;
        if(resTypeRCCounts.containsKey(type))
            resTypeRCCounts.put(type, resTypeRCCounts.get(type)+1);
        else
            resTypeRCCounts.put(type, 1);
    }
    
    int maxNumRCs = 0;
    for(int count : resTypeRCCounts.values())
        maxNumRCs = Math.max(maxNumRCs,count);
    
    return maxNumRCs;
}
 
源代码5 项目: talkback   文件: LanguageMenuProcessor.java
private static List<ContextMenuItem> getMenuItems(
    TalkBackService service, ContextMenuItemBuilder menuItemBuilder) {
  if (service == null) {
    return null;
  }

  HashMap<Locale, String> languagesAvailable = getInstalledLanguages(service);

  if (languagesAvailable == null) {
    return null;
  }
  LanguageMenuItemClickListener clickListener =
      new LanguageMenuItemClickListener(service, languagesAvailable);
  List<ContextMenuItem> menuItems = new ArrayList<>();

  for (String value : languagesAvailable.values()) {
    ContextMenuItem val =
        menuItemBuilder.createMenuItem(service, R.id.group_language, Menu.NONE, Menu.NONE, value);
    val.setOnMenuItemClickListener(clickListener);
    menuItems.add(val);
  }

  return menuItems;
}
 
源代码6 项目: metanome-algorithms   文件: Partition.java
public Collection<Partition> refineBy(int target) {
	HashMap<Cluster, Partition> map = new HashMap<Cluster, Partition>();
	for(TIntIterator iter = array.iterator(); iter.hasNext();) {
		int next = iter.next();
		Cluster c = StrippedPartition.clusters.get(next)[target];
		if(c == null) {
			continue;
		}
		if(map.containsKey(c)) {
			map.get(c).add(next);
		} else {
			Partition p = new Partition();
			p.add(next);
			map.put(c, p);
		}
	}
	return map.values();
}
 
源代码7 项目: ctsms   文件: QueryUtil.java
private static void appendJoins(StringBuilder statement, HashMap<String, AssociationPath> explicitJoinsMap) {
	ArrayList<AssociationPath> joins = new ArrayList<AssociationPath>(explicitJoinsMap.values());
	Collections.sort(joins, new JoinComparator());
	Iterator<AssociationPath> it = joins.iterator();
	while (it.hasNext()) {
		AssociationPath join = it.next();
		StringBuilder joinSb = new StringBuilder(" left join ");
		joinSb.append(join.getAliasedPathString());
		joinSb.append(" as ");
		joinSb.append(join.getJoinAlias());
		statement.append(joinSb);
	}
}
 
源代码8 项目: JavaExercises   文件: Solution.java
public static int getCountTheSameFirstName(HashMap<String, String> map, String name) {
    int count = 0;
    /*for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry value = (Map.Entry) iterator.next();
        if (value.getValue().equals(name))
            count++;
    }*/
    for (String value : map.values())
        if (value.equals(name)) count++;
    return count;
}
 
private void updateTrackedBeacons(@NonNull Beacon beacon) {
    HashMap<Integer,Beacon> matchingTrackedBeacons = mBeaconsByKey.get(getBeaconKey(beacon));
    if (null != matchingTrackedBeacons) {
        for (Beacon matchingTrackedBeacon : matchingTrackedBeacons.values()) {
            matchingTrackedBeacon.setRssi(beacon.getRssi());
            matchingTrackedBeacon.setExtraDataFields(beacon.getDataFields());
        }
    }
}
 
源代码10 项目: dsworkbench   文件: StatManager.java
public void takeSnapshot() {
    long now = System.currentTimeMillis();
    logger.debug("Taking stat snapshot from '" + now + "'");
    for(Integer allyKey: data.keySet()) {
        HashMap<Integer, TribeStatsElement> tribes = data.get(allyKey);
        for(TribeStatsElement elem: tribes.values()) {
            elem.takeSnapshot(now);
        }
    }
}
 
private ArrayList<Package> getPackages() {
	HashMap<String, Package> pkgs = new HashMap<String, Package>();
	PackageInfoVector packageInfoVector = packageManager.getServerPackages();
	for (int i = 0; i < packageInfoVector.size(); i++) {
		PackageInfo packageInfo = packageInfoVector.get(i);

		// Get the list of names for this package. Each package may have multiple names,
		// packages are grouped using '/' as a separator, so the the full name for Sweden
		// is "Europe/Northern Europe/Sweden". We display packages as a tree, so we need
		// to extract only relevant packages belonging to the current folder.
		StringVector packageNames = packageInfo.getNames(language);
		for (int j = 0; j < packageNames.size(); j++) {
			String packageName = packageNames.get(j);
			if (!packageName.startsWith(currentFolder)) {
				continue; // belongs to a different folder, so ignore
			}
			packageName = packageName.substring(currentFolder.length());
			int index = packageName.indexOf('/');
			Package pkg;
			if (index == -1) {
				// This is actual package
				PackageStatus packageStatus = packageManager.getLocalPackageStatus(packageInfo.getPackageId(), -1);
				pkg = new Package(packageName, packageInfo, packageStatus);
			} else {
				// This is package group
				packageName = packageName.substring(0, index);
				if (pkgs.containsKey(packageName)) {
					continue;
				}
				pkg = new Package(packageName, null, null);
			}
			pkgs.put(packageName, pkg);
		}
	}
	return new ArrayList<Package>(pkgs.values());
}
 
源代码12 项目: SpyGlass   文件: HBaseInputFormatRegional.java
private HBaseTableSplitRegional[] convertToRegionalSplitArray(
            HBaseTableSplitGranular[] splits) throws IOException {

        if (splits == null)
            throw new IOException("The list of splits is null => " + splits);

        HashMap<String, HBaseTableSplitRegional> regionSplits = new HashMap<String, HBaseTableSplitRegional>();

        for (HBaseTableSplitGranular hbt : splits) {
            HBaseTableSplitRegional mis = null;
            if (regionSplits.containsKey(hbt.getRegionName())) {
                mis = regionSplits.get(hbt.getRegionName());
            } else {
                regionSplits.put(hbt.getRegionName(), new HBaseTableSplitRegional(
                        hbt.getRegionLocation(), hbt.getRegionName()));
                mis = regionSplits.get(hbt.getRegionName());
            }

            mis.addSplit(hbt);
            regionSplits.put(hbt.getRegionName(), mis);
        }

//        for(String region : regionSplits.keySet() ) {
//            regionSplits.get(region)
//        }

        Collection<HBaseTableSplitRegional> outVals = regionSplits.values();

        LOG.debug("".format("Returning array of splits : %s", outVals));

        if (outVals == null)
            throw new IOException("The list of multi input splits were null");

        return outVals.toArray(new HBaseTableSplitRegional[outVals.size()]);
    }
 
源代码13 项目: hop   文件: CompressionProviderFactoryTest.java
/**
 * Test that all core compression plugins (None, Zip, GZip) are available via the factory
 */
@Test
public void getCoreProviders() {
  @SuppressWarnings( "serial" ) final HashMap<String, Boolean> foundProvider = new HashMap<String, Boolean>() {
    {
      put( "None", false );
      put( "Zip", false );
      put( "GZip", false );
      put( "Snappy", false );
      put( "Hadoop-snappy", false );
    }
  };

  Collection<ICompressionProvider> providers = factory.getCompressionProviders();
  assertNotNull( providers );
  for ( ICompressionProvider provider : providers ) {
    assertNotNull( foundProvider.get( provider.getName() ) );
    foundProvider.put( provider.getName(), true );
  }

  boolean foundAllProviders = true;
  for ( Boolean b : foundProvider.values() ) {
    foundAllProviders = foundAllProviders && b;
  }

  assertTrue( foundAllProviders );
}
 
源代码14 项目: TrakEM2   文件: Patch.java
@Override
protected void setAlpha(final float alpha, final boolean update) {
	if (isStack()) {
		final HashMap<Double,Patch> ht = new HashMap<Double,Patch>();
		getStackPatchesNR(ht);
		for (final Patch pa : ht.values()) {
			pa.alpha = alpha;
			pa.updateInDatabase("alpha");
			Display.repaint(pa.layer, pa, 5);
		}
		Display3D.setTransparency(this, alpha);
	} else super.setAlpha(alpha, update);
}
 
源代码15 项目: sax-vsm_classic   文件: TextProcessor.java
/**
 * Normalize the vector to the norm of 1.
 * 
 * @param vector the vector.
 * @return normalized vector.
 */
public HashMap<String, Double> normalizeToUnitVector(HashMap<String, Double> vector) {
  double sum = 0d;
  for (double value : vector.values()) {
    sum = sum + value * value;
  }
  sum = Math.sqrt(sum);
  HashMap<String, Double> res = new HashMap<String, Double>();
  for (Entry<String, Double> e : vector.entrySet()) {
    res.put(e.getKey(), e.getValue() / sum);
  }
  return res;
}
 
源代码16 项目: lams   文件: TaskListUserDAOHibernate.java
@Override
   @SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
   public Collection<TaskListUserDTO> getPagedUsersBySession(Long sessionId, int page, int size, String sortBy,
    String sortOrder, String searchString, IUserManagementService userManagementService) {

String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id");

StringBuilder bldr = new StringBuilder(LOAD_USERS_SELECT)
	.append(portraitStrings[0])
	.append(LOAD_USERS_FROM)
	.append(portraitStrings[1])
	.append(LOAD_USERS_JOINS)
	.append(sortOrder);

NativeQuery query = getSession().createNativeQuery(bldr.toString());
query.setParameter("sessionId", sessionId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setParameter("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
List<Object[]> list = query.list();

//group by userId as long as it returns all completed visitLogs for each user
HashMap<Long, TaskListUserDTO> userIdToUserDto = new LinkedHashMap<Long, TaskListUserDTO>();
if (list != null && list.size() > 0) {
    for (Object[] element : list) {

	Long userId = ((Number) element[0]).longValue();
	String fullName = (String) element[1];
	boolean isVerifiedByMonitor =  element[2] == null ? false : (Boolean) element[2];
	Long completedTaskUid = element[3] == null ? 0 : ((Number) element[3]).longValue();
	Long portraitId = element[4] == null ? null : ((Number) element[4]).longValue();

	TaskListUserDTO userDto = (userIdToUserDto.get(userId) == null) ? new TaskListUserDTO()
		: userIdToUserDto.get(userId);
	userDto.setUserId(userId);
	userDto.setFullName(fullName);
	userDto.setVerifiedByMonitor(isVerifiedByMonitor);
	userDto.getCompletedTaskUids().add(completedTaskUid);
	userDto.setPortraitId(portraitId);

	userIdToUserDto.put(userId, userDto);
    }
}

return userIdToUserDto.values();
   }
 
源代码17 项目: compiler   文件: TreedMapper.java
private <E> int length(HashMap<E, Integer> vector) {
	int len = 0;
	for (int val : vector.values())
		len += val;
	return len;
}
 
源代码18 项目: JavaRushTasks   文件: Solution.java
public static void main(String[] args) throws Exception {
    Scanner reader = new Scanner(System.in);
    String filename = reader.nextLine();

    FileInputStream f = new FileInputStream(filename);

    HashMap<Integer, Integer> mapOfByte = new HashMap<Integer, Integer>();

    int value = 0;
    Integer count = 0;
    while (f.available() > 0) {
        value = f.read();

        count = mapOfByte.get(value);
        if (count != null)
            count++;
        else
            count = 0;

        mapOfByte.put(value, count);
    }

    f.close();


    //int min = Collections.min(mapOfByte.values());


    //Находим минимальное число повторений
    boolean first = true;
    int min = 0;
    for (int amountByte : mapOfByte.values()) {
        if (first) {
            min = amountByte;
            first = false;
        }
        if (min > amountByte)
            min = amountByte;
    }


    //Выводим
    for (Map.Entry pair : mapOfByte.entrySet()) {
        if (min == (int) pair.getValue())
            System.out.print(" " + pair.getKey());
    }

}
 
源代码19 项目: ForbiddenMagic   文件: VisNetHandler.java
public static WeakReference<TileVisNode> addNode(World world, TileVisNode vn) {
	WeakReference ref = new WeakReference(vn);

	HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
			.get(world.provider.dimensionId);
	if (sourcelist == null) {
		sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
		return null;
	}

	ArrayList<Object[]> nearby = new ArrayList<Object[]>();

	for (WeakReference<TileVisNode> root : sourcelist.values()) {
		if (!isNodeValid(root))
			continue;

		TileVisNode source = root.get();

		float r = inRange(world, vn.getLocation(), source.getLocation(),
				vn.getRange());
		if (r > 0) {
			nearby.add(new Object[] { source, r - vn.getRange() * 2 });
		}
		
		nearby = findClosestNodes(vn, source, nearby);
		cache.clear();
	}

	float dist = Float.MAX_VALUE;
	TileVisNode closest = null;
	if (nearby.size() > 0) {
		for (Object[] o : nearby) {
			if ((Float) o[1] < dist &&
				(vn.getAttunement() == -1 || ((TileVisNode) o[0]).getAttunement() == -1 || 
					vn.getAttunement() == ((TileVisNode) o[0]).getAttunement())//) {
				 && canNodeBeSeen(vn,(TileVisNode)o[0])) {
				dist = (Float) o[1];
				closest = (TileVisNode) o[0];					
			}
		}
	}
	if (closest != null) {
		closest.getChildren().add(ref);
		nearbyNodes.clear();
		return new WeakReference(closest);
	}

	return null;
}
 
源代码20 项目: ForbiddenMagic   文件: VisNetHandler.java
private static void calculateNearbyNodes(World world, int x, int y, int z) {

		HashMap<WorldCoordinates, WeakReference<TileVisNode>> sourcelist = sources
				.get(world.provider.dimensionId);
		if (sourcelist == null) {
			sourcelist = new HashMap<WorldCoordinates, WeakReference<TileVisNode>>();
			return;
		}

		ArrayList<WeakReference<TileVisNode>> cn = new ArrayList<WeakReference<TileVisNode>>();
		WorldCoordinates drainer = new WorldCoordinates(x, y, z,
				world.provider.dimensionId);

		ArrayList<Object[]> nearby = new ArrayList<Object[]>();

		for (WeakReference<TileVisNode> root : sourcelist.values()) {
			
			if (!isNodeValid(root))
				continue;

			TileVisNode source = root.get();
			
			TileVisNode closest = null;
			float range = Float.MAX_VALUE;

			float r = inRange(world, drainer, source.getLocation(),
					source.getRange());
			if (r > 0) {
				range = r;
				closest = source;
			}
			
			ArrayList<WeakReference<TileVisNode>> children = new ArrayList<WeakReference<TileVisNode>>();
			children = getAllChildren(source,children);
			
			for (WeakReference<TileVisNode> child : children) {
				TileVisNode n = child.get();
				if (n != null && !n.equals(root)) {
					
					float r2 = inRange(n.getWorldObj(), n.getLocation(),
							drainer, n.getRange());
					if (r2 > 0 && r2 < range) {
						range = r2;
						closest = n;
					}
				}
			}

			if (closest != null) {
				
				cn.add(new WeakReference(closest));
			}
		}

		nearbyNodes.put(drainer, cn);
	}