Example usage for java.util HashMap values

List of usage examples for java.util HashMap values

Introduction

In this page you can find the example usage for java.util HashMap values.

Prototype

public Collection<V> values() 

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:com.wasteofplastic.beaconz.BeaconListeners.java

/**
 * Handles the event of hitting a beacon with paper or a map
 * @param event/*w w w . j  a  v  a 2s  .  c  o  m*/
 */
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPaperMapUse(final PlayerInteractEvent event) {
    //getLogger().info("DEBUG: paper map " + event.getEventName());
    if (Settings.pairLinking) {
        // Not used if pair linking is used
        return;
    }
    if (!event.hasItem()) {
        return;
    }
    if (!event.getItem().getType().equals(Material.PAPER) && !event.getItem().getType().equals(Material.MAP)) {
        return;
    }
    if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    World world = event.getClickedBlock().getWorld();
    if (!world.equals(getBeaconzWorld())) {
        //getLogger().info("DEBUG: not right world");
        return;
    }
    Player player = event.getPlayer();
    // Get the player's team
    Team team = getScorecard().getTeam(player);
    if (team == null) {
        // TODO: Probably should put the player in a team
        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You must be in a team to play in this world");
        return;
    }
    // Apply triangle effects
    applyEffects(player,
            getRegister().getTriangle(player.getLocation().getBlockX(), player.getLocation().getBlockZ()),
            team);

    // Check if the block is a beacon or the surrounding pyramid
    Block b = event.getClickedBlock();
    final BeaconObj beacon = getRegister().getBeacon(b);
    if (beacon == null) {
        //getLogger().info("DEBUG: not a beacon");
        return;
    }
    // Check the team
    if (beacon.getOwnership() == null || !beacon.getOwnership().equals(team)) {
        player.sendMessage(ChatColor.RED + "You must capture this beacon first!");
        event.setCancelled(true);
        return;
    }
    if (event.getItem().getType().equals(Material.PAPER)) {
        // Make a map!
        player.sendMessage(
                ChatColor.GREEN + "You made a beacon map! Take it to another beacon to link them up!");
        int amount = event.getItem().getAmount() - 1;
        MapView map = Bukkit.createMap(getBeaconzWorld());
        //map.setWorld(getBeaconzWorld());
        map.setCenterX(beacon.getX());
        map.setCenterZ(beacon.getZ());
        map.getRenderers().clear();
        map.addRenderer(new BeaconMap(getBeaconzPlugin()));
        event.getItem().setType(Material.MAP);
        event.getItem().setAmount(1);
        event.getItem().setDurability(map.getId());
        // Each map is unique and the durability defines the map ID, register it
        getRegister().addBeaconMap(map.getId(), beacon);
        //getLogger().info("DEBUG: beacon id = " + beacon.getId());
        if (amount > 0) {
            HashMap<Integer, ItemStack> leftOver = player.getInventory()
                    .addItem(new ItemStack(Material.PAPER, amount));
            if (!leftOver.isEmpty()) {
                for (ItemStack stack : leftOver.values()) {
                    player.getLocation().getWorld().dropItemNaturally(player.getLocation(), stack);
                }
            }
        }
        ItemMeta meta = event.getItem().getItemMeta();
        meta.setDisplayName("Beacon map for " + beacon.getName());
        event.getItem().setItemMeta(meta);
        // Stop the beacon inventory opening
        event.setCancelled(true);
        return;
    } else {
        // Map!
        BeaconObj mappedBeacon = getRegister().getBeaconMap(event.getItem().getDurability());
        if (mappedBeacon == null) {
            // This is not a beacon map
            return;
        }
        event.setCancelled(true);
        if (Settings.linkDistance >= 0 && Settings.expDistance > 0) {
            // Check if the player has sufficient experience to link the beacons
            double distance = beacon.getLocation().distance(mappedBeacon.getLocation());
            distance -= Settings.linkDistance;
            if (distance > 0) {
                if (!testForExp(player, (int) (distance / Settings.expDistance))) {
                    player.sendMessage(
                            ChatColor.RED + "You do not have enough experience to link to this beacon!");
                    player.sendMessage(ChatColor.RED + "You can link up to "
                            + (int) (Settings.expDistance * player.getTotalExperience()) + " blocks away.");
                    player.sendMessage(ChatColor.RED + "This beacon is " + (int) distance + " blocks away.");
                    return;
                }
            }
        }
        if (linkBeacons(player, team, beacon, mappedBeacon)) {
            player.sendMessage(ChatColor.GREEN + "The map disintegrates!");
            player.setItemInHand(null);
        }
    }
}

From source file:gov.llnl.lc.smt.command.port.SmtPort.java

/**
 * Describe the method here/*from  ww  w  .  ja v  a2  s  .  c o m*/
 *
 * @see     describe related java objects
 *
 * @param subCommandArg
 * @return
 ***********************************************************/
private HashMap<String, OSM_Port> getOSM_PortsByString(String subCommandArg) {
    // get all the ports, and return the ones with a matching string
    // in the node description, guid, etc.
    HashMap<String, OSM_Port> ports = getOSM_Ports();
    HashMap<String, OSM_Port> matchPorts = null;

    if ((ports != null) && ports.size() > 0) {
        matchPorts = new HashMap<String, OSM_Port>();

        for (OSM_Port port : ports.values()) {
            // if this port has this string anywhere, then add it to the map
            if (port.hasError()) {
                matchPorts.put(OSM_Fabric.getOSM_PortKey(port), port);
            }
        }
    }
    return matchPorts;
}

From source file:de.gfz_potsdam.datasync.Datasync.java

private void addContainerMembers(String parentdir, Container parent, ArrayList<VersionableResource> children)
        throws Exception {
    if (parent == null || children == null)
        return;//w  ww .j av a2  s.  c  om

    HashMap<String, VersionableResource> ids = new HashMap<String, VersionableResource>();

    for (VersionableResource child : children) {
        ids.put(child.getObjid(), child);
    }
    //do not add twice
    if (parent.getStructMap() != null) {
        for (MemberRef m : parent.getStructMap()) {
            if (ids.containsKey(m.getObjid()))
                ids.remove(m.getObjid());
        }
    }

    if (ids.isEmpty())
        return;

    DateTime r = srv.containerAddMembers(parent, ids.values());

    File dir = new File(directory + File.separator + parentdir);

    App.db.storeMapping(parentdir, parent.getObjid(), dir.lastModified(), r, SyncDB.DIRECTORY);
    log.log(Level.INFO, "added members : {0}", new Object[] { dir.getAbsoluteFile() });

}

From source file:net.sf.jrf.domain.PersistentObjectDynaClass.java

/** Factory method to create a <code>PersistentObjectDynaClass</code> based on bean properties
 * of the <code>PersistentObject</code> managed by the <code>AbstractDomain</code> instance parameter.
 * If the object is a composite, <code>Map</code> and <code>List</code> properties will
 * be included.//w  ww  .  j  av  a  2 s. com
 * @param domain <code>AbstractDomain</code> instance to inspect.
 * @param beanClass class name of the implementer of <code>DynaBean</code>
 *  returned <code>PersistentObjectDynaClass</code>'s <code>PersistentObjectDynaProperty</code> list.
 * @return <code>PersistentObjectDynaClass</code> based on internal column specifications.
 */
static public PersistentObjectDynaClass createPersistentObjectDynaClass(AbstractDomain domain,
        Class beanClass) {
    BeanInfo beanInfo;
    PersistentObject obj = domain.newPersistentObject();
    // Introspect the Persistent Object.
    try {
        beanInfo = Introspector.getBeanInfo(obj.getClass());
    } catch (IntrospectionException ex) {
        throw new ConfigurationException(ex, "Unexpected introspection exception on " + obj.getClass());
    }
    PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
    HashMap propertyMap = new HashMap();
    for (int i = 0; i < properties.length; i++) {
        if (properties[i].getReadMethod() != null) {
            Class returnType = properties[i].getReadMethod().getReturnType();
            /** NO - include them
             (Ignore Maps and Lists from composites)
            if (java.util.Map.class.isAssignableFrom(returnType) ||
                java.util.List.class.isAssignableFrom(returnType))
                continue;
            **/
            String writeMethodName = properties[i].getWriteMethod() == null ? null
                    : properties[i].getWriteMethod().getName();

            propertyMap.put(properties[i].getName(), new PersistentObjectDynaProperty(properties[i].getName(),
                    returnType, properties[i].getReadMethod().getName(), writeMethodName));
        }
    }
    // Reconcile bean properties with the column specifications.
    Iterator columnSpecs = domain.getColumnSpecs().iterator();
    while (columnSpecs.hasNext()) {
        ColumnSpec c = (ColumnSpec) columnSpecs.next();
        if (c instanceof CompoundPrimaryKeyColumnSpec) {
            CompoundPrimaryKeyColumnSpec cp = (CompoundPrimaryKeyColumnSpec) c;
            Iterator iter = cp.getColumnSpecs().iterator();
            while (iter.hasNext()) {
                PersistentObjectDynaProperty p = updatePropertyMap((ColumnSpec) iter.next(), propertyMap);
                // Force dyna property for primary key to true.  Value for compound keys does not
                // have this value set automatically.
                p.setPrimaryKey(true);
            }
        } else {
            updatePropertyMap(c, propertyMap);
        }
    }
    List list = new ArrayList(propertyMap.values());
    return new PersistentObjectDynaClass(domain.getPropertyName(), beanClass, obj.getClass(), list);
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultObjectPropertyFormGenerator.java

protected List<VClass> getRangeTypes(VitroRequest vreq) {
    // This first part needs a WebappDaoFactory with no filtering/RDFService
    // funny business because it needs to be able to retrieve anonymous union
    // classes by their "pseudo-bnode URIs".
    // Someday we'll need to figure out a different way of doing this.
    //WebappDaoFactory ctxDaoFact = ModelAccess.on(
    //        vreq.getSession().getServletContext()).getWebappDaoFactory();
    WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory();

    List<VClass> types = new ArrayList<VClass>();
    Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
    String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
    String rangeUri = EditConfigurationUtils.getRangeUri(vreq);
    if (rangeUri != null && !rangeUri.isEmpty()) {
        VClass rangeVClass = ctxDaoFact.getVClassDao().getVClassByURI(rangeUri);
        if (rangeVClass != null) {
            if (!rangeVClass.isUnion()) {
                types.add(rangeVClass);/*from  w w w.j  a  va  2  s  .c om*/
            } else {
                for (VClass unionComponent : rangeVClass.getUnionComponents()) {
                    types.add(unionComponent);
                }
            }
            return types;
        } else {
            log.error("Range VClass does not exist for " + rangeUri);
        }
    }
    WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory();
    //Get all vclasses applicable to subject
    if (subject != null) {
        List<VClass> vClasses = subject.getVClasses();
        HashMap<String, VClass> typesHash = new HashMap<String, VClass>();
        for (VClass vclass : vClasses) {
            List<VClass> rangeVclasses = wDaoFact.getVClassDao().getVClassesForProperty(vclass.getURI(),
                    predicateUri);
            if (rangeVclasses != null) {
                for (VClass range : rangeVclasses) {
                    //a hash will keep a unique list of types and so prevent duplicates
                    typesHash.put(range.getURI(), range);
                }
            }
        }
        types.addAll(typesHash.values());
    } else {
        log.error("Subject individual was null for");
    }
    return types;
}

From source file:mil.army.usace.data.dataquery.rdbms.RdbmsDataQuery.java

private String getSqlFields(HashMap<?, String> fieldMapping) {
    String fields = null;/*from   w  w  w.j  a va  2  s.  c  o m*/
    for (String fieldName : fieldMapping.values()) {
        if (fields == null) {
            fields = fieldName;
        } else {
            fields += "," + fieldName;
        }
    }
    return fields;
}

From source file:gov.nih.nci.cabig.caaers.service.synchronizer.StudyOrganizationSynchronizer.java

private void syncStudyPersonnels(StudyOrganization dbStudyOrganization, StudyOrganization xmlStudyOrganization,
        Organization organization, DomainObjectImportOutcome<Study> studyImportOutcome) {

    //do nothing if there is no personnel in the xmlStudy Organization
    if (CollectionUtils.isEmpty(xmlStudyOrganization.getStudyPersonnels())) {
        return;/*  ww w  . j  a v a  2  s .c  om*/
    }

    //generate and index of existing study StudyPersonnel
    HashMap<String, StudyPersonnel> dbStudyPersonnelIndexMap = new HashMap<String, StudyPersonnel>();
    for (StudyPersonnel sp : dbStudyOrganization.getStudyPersonnels()) {
        dbStudyPersonnelIndexMap.put(generateIndexKey(sp), sp);
    }

    //loop through xmlStudy Organization StudyPersonnel, then add and modify details
    for (StudyPersonnel xmlSp : xmlStudyOrganization.getStudyPersonnels()) {
        StudyPersonnel sp = dbStudyPersonnelIndexMap.remove(generateIndexKey(xmlSp));
        if (sp == null) {
            //new one so add it to Study
            dbStudyOrganization.addStudyPersonnel(xmlSp);
            continue;
        }
        //update existing study personnel
        sp.setEndDate(xmlSp.getEndDate());
        sp.setStartDate(xmlSp.getStartDate());
        sp.setRoleCode(xmlSp.getRoleCode());
    }

    //deactivate the study staff which are not present in xmlStudy Organization
    for (StudyPersonnel sp : dbStudyPersonnelIndexMap.values()) {
        sp.deactivate();
    }

}

From source file:org.powertac.balancemkt.BalancingMarketService.java

/**
 * Generates a list of Transactions that balance the overall market.
 * Transactions are generated on a per-broker basis depending on the broker's
 * balance within its own market.//  ww w  .j a v  a  2s  . c  o  m
 * 
 * @return List of ChargeInfo instances
 */
public HashMap<Broker, ChargeInfo> balanceTimeslot(Timeslot currentTimeslot, List<Broker> brokerList,
        BalanceReport report) {
    HashMap<Broker, ChargeInfo> chargeInfoMap = new HashMap<Broker, ChargeInfo>();

    // create the ChargeInfo instances for each broker
    for (Broker broker : brokerList) {
        double imbalance = getMarketBalance(broker);
        ChargeInfo info = new ChargeInfo(broker, imbalance);
        report.addImbalance(imbalance);
        chargeInfoMap.put(broker, info);
    }

    // retrieve and allocate the balancing orders
    Collection<BalancingOrder> boc = tariffRepo.getBalancingOrders();
    for (BalancingOrder order : boc) {
        ChargeInfo info = chargeInfoMap.get(order.getBroker());
        info.addBalancingOrder(order);
    }

    // gather up the list of ChargeInfo instances and settle
    log.info("balancing prices: pPlus=" + getPPlus() + ", pMinus=" + getPMinus());
    List<ChargeInfo> brokerData = new ArrayList<ChargeInfo>(chargeInfoMap.values());
    getSettlementProcessor().settle(this, brokerData);

    // add balancing transactions - note that debits/credits for balancing
    // orders (p2 values) will already have been posted in the process of
    // exercising orders.
    for (ChargeInfo info : brokerData) {
        double balanceCharge = info.getBalanceChargeP1();
        if (balanceCharge != 0.0) {
            accountingService.addBalancingTransaction(info.getBroker(), info.getNetLoadKWh(), balanceCharge);
        }
    }
    return chargeInfoMap;
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public Invoice[] getDistinctLicPlates() {
    if (!ArrayUtils.isEmpty(invoices)) {
        HashMap veaLicPlatesMap = new HashMap();
        for (int i = 0; i < invoices.length; i++) {
            veaLicPlatesMap.put(invoices[i].getLicPlateNumber() + invoices[i].getLicPlateState(), invoices[i]);
        }/* w w w .  j  ava 2s  .  c  o  m*/
        return (Invoice[]) veaLicPlatesMap.values().toArray(new Invoice[0]);
    }
    return null;
}

From source file:gov.nih.nci.cabig.caaers.service.synchronizer.StudyOrganizationSynchronizer.java

private void syncStudyInvestigators(StudyOrganization dbStudyOrganization,
        StudyOrganization xmlStudyOrganization, Organization organization,
        DomainObjectImportOutcome<Study> studyImportOutcome) {

    //do nothing if there is no investigator in the xmlStudy Organization
    if (CollectionUtils.isEmpty(xmlStudyOrganization.getStudyInvestigators())) {
        return;/*from  w ww . ja va  2  s . co  m*/
    }

    //generate and index of existing study investigators
    HashMap<String, StudyInvestigator> dbStudyInvIndexMap = new HashMap<String, StudyInvestigator>();
    for (StudyInvestigator si : dbStudyOrganization.getStudyInvestigators()) {
        dbStudyInvIndexMap.put(generateIndexKey(si), si);
    }

    //loop through xmlStudy Organization StudyInvestigators, then add and modify details
    for (StudyInvestigator xmlSi : xmlStudyOrganization.getStudyInvestigators()) {
        StudyInvestigator si = dbStudyInvIndexMap.remove(generateIndexKey(xmlSi));
        if (si == null) {
            //new one so add it to Study
            dbStudyOrganization.addStudyInvestigators(xmlSi);
            continue;
        }
        //update existing investigator
        si.setEndDate(xmlSi.getEndDate());
        si.setStartDate(xmlSi.getStartDate());
        si.setRoleCode(xmlSi.getRoleCode());
    }

    //deactivate the study investigators which are not present in xmlStudy Organization
    for (StudyInvestigator si : dbStudyInvIndexMap.values()) {
        si.deactivate();
    }

}