Example usage for java.util HashMap isEmpty

List of usage examples for java.util HashMap isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:com.activecq.api.plugins.PersistencePlugin.java

/**
 * Checks if any persisted data exists for the current component
 *
 * @return/*  ww  w  .j  a v  a2  s.  c o m*/
 */
public boolean isEmpty() {
    if (StringUtils.isBlank(this.componentKey)) {
        return true;
    }

    HashMap<String, Object> hashMap = (HashMap<String, Object>) this.request.getAttribute(this.componentKey);
    if (hashMap == null) {
        return true;
    }

    return hashMap.isEmpty();
}

From source file:org.rhwlab.dispim.nucleus.Division.java

static public HashMap<Nucleus, Division> bestDivisions(List<Nucleus> fromList, List<Nucleus> toList) {

    List<Nucleus> possibleParentList = possibleParents(fromList);

    // determine all possible divisions from each possible parent
    HashMap<Nucleus, Set<Division>> possibleFrom = new HashMap<>();
    for (Nucleus possibleParent : possibleParentList) {
        Set<Division> possibleDivs = possibleDivisions(possibleParent, toList.toArray(new Nucleus[0]));
        if (!possibleDivs.isEmpty()) {
            possibleFrom.put(possibleParent, possibleDivs);
        }/* w w w.j  a  v a 2  s.c om*/
    }

    // determine all the divsions ending on each 'to' nucleus
    HashMap<Nucleus, Set<Division>> possibleTo = new HashMap<>();
    for (Nucleus fromNuc : possibleFrom.keySet()) {
        Set<Division> divs = possibleFrom.get(fromNuc);
        for (Division div : divs) {
            Nucleus to1 = div.child1;
            Nucleus to2 = div.child2;

            Set<Division> toDivs = possibleTo.get(to1);
            if (toDivs == null) {
                toDivs = new HashSet<>();
                possibleTo.put(to1, toDivs);
            }
            toDivs.add(div);

            toDivs = possibleTo.get(to2);
            if (toDivs == null) {
                toDivs = new HashSet<>();
                possibleTo.put(to2, toDivs);
            }
            toDivs.add(div);
        }
    }
    // use the 'best' division for each 'to' nucleus
    HashMap<Nucleus, Division> ret = new HashMap<>();
    while (!possibleTo.isEmpty()) {
        Nucleus first = possibleTo.keySet().iterator().next();
        Set<Division> divs = possibleTo.get(first);
        Division best = bestDivision(divs);
        ret.put(first, best);

        // remove any divisions that are no longer possible
        possibleTo.remove(best.child1);
        possibleTo.remove(best.child2);
    }

    return ret;
}

From source file:de.rrze.idmone.utils.jidgen.cli.IdGenHelpFormatter.java

/**
 * Compile the fully formatted help message that should be 
 * reachable via the --help option and returns it as a string.
 * //  w  w  w .ja  va2s. co m
 * @param options
 *          options that should be included in the help message
 * @return the formatted help message as a string 
 */
public String getHelpString(IdGenOptions options, boolean longHelp) {
    StringBuffer sb = new StringBuffer();

    // usage string
    sb.append(Messages.getString("IdGenerator.HELP_USAGE"));

    if (!longHelp) {
        sb.append(Globals.NEWLINE);
        sb.append(Messages.getString("IdGenerator.HELP_SHORT_EXAMPLE"));
        sb.append(Globals.NEWLINE);
    }

    if (longHelp) {
        sb.append(Globals.NEWLINE);
        sb.append(Messages.getString("IdGenerator.HELP_INTRO"));
    }

    if (longHelp) {
        // predefined data
        sb.append(Globals.NEWLINE);
        HashMap<String, String> presets = Template.getPredefinedData();
        if (!presets.isEmpty()) {
            sb.append(format(Messages.getString("IdGenereator.HELP_PREDEFINED_STRINGS")));
            for (Iterator<String> iter = presets.keySet().iterator(); iter.hasNext();) {
                String key = iter.next();
                sb.append(
                        format(key + "\t" + Messages.getString("Template.HELP_DATA_PRESET_" + key.toUpperCase())
                                + " (" + presets.get(key) + ")" + Messages.getString("IdGenerator.NEW_LINE")));
            }
            sb.append(Globals.NEWLINE);
        }
    }

    if (longHelp) {
        // template syntax
        sb.append(Globals.NEWLINE);
        sb.append(format(Messages.getString("IdGenerator.HELP_TEMPLATE_SYNTAX")));
    }

    // command line options
    sb.append(Globals.NEWLINE);
    sb.append(format(Messages.getString("IdGenerator.HELP_CLI_OPTIONS")));
    sb.append(this.renderOptions(options));

    if (longHelp) {
        // example string
        sb.append(Globals.NEWLINE);
        sb.append(Messages.getString("IdGenerator.HELP_LONG_EXAMPLE"));
    }

    return sb.toString();
}

From source file:com.wordpress.ebc81.rtl_ais_android.tools.DialogManager.java

@SuppressLint("NewApi")
private Dialog genUSBDeviceDialog() {

    try {/*from w w w. j  a va 2s.c o m*/
        if (!(getActivity() instanceof DeviceOpenActivity))
            return null;
        final DeviceOpenActivity sdrviewer = (DeviceOpenActivity) getActivity();

        final UsbManager manager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
        final HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
        if (deviceList.isEmpty()) {
            sdrviewer.finishWithError(err_info.no_devices_found);
            return null;
        }
        final String[] options = new String[deviceList.size()];
        int i = 0;
        for (final String s : deviceList.keySet())
            options[i++] = s;

        return new AlertDialog.Builder(getActivity()).setItems(options, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                final String selected = options[which];

                final UsbDevice selected_device = deviceList.get(selected);

                sdrviewer.openDevice(selected_device);
            }
        }).setOnCancelListener(new AlertDialog.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                sdrviewer.finishWithError(err_info.no_devices_found);
            }
        }).setTitle(R.string.choose_device).create();
    } catch (Throwable t) {
        t.printStackTrace();
        return null;
    }
}

From source file:net.lordsofcode.zephyrus.spells.Conjure.java

@Override
public void run(Player player, String[] args) {
    int id;/* w w  w.ja  v  a  2 s.c o m*/
    byte data = 0;
    int amount = 1;
    if (args[1].contains("\\:")) {
        String[] ids = args[1].split("\\:");
        id = Integer.parseInt(ids[0]);
        data = Byte.parseByte(ids[1]);
    } else {
        id = Integer.parseInt(args[1]);
    }
    if (args.length == 3) {
        amount = Integer.parseInt(args[2]);
    }
    ItemStack item = new ItemStack(Material.getMaterial(id), amount, data);
    HashMap<Integer, ItemStack> map = player.getInventory().addItem(item);
    if (!map.isEmpty()) {
        player.sendMessage(ChatColor.GRAY + "Your inventory is full!");
    } else {
        player.sendMessage(ChatColor.GRAY + "You have conjured " + ChatColor.GOLD + amount + " "
                + WordUtils.capitalizeFully(item.getType().toString().replace("_", " ")));
        LevelManager.drainMana(player, getValue(id) * amount);
    }
}

From source file:podd.resources.services.ExternalFileUploadAttachmentService.java

protected void attachAndTransferRedirectFiles()
        throws DataAccessException, RawDataHandlingException, EntityException, MimeTypeHandlingException {
    try {//  w w w.j a v a2 s . c  o  m
        // note: we used the loaded datastore when transferring the file, as it has more information than can be supplied by the user
        remoteFileHelper.attachRedirectFiles(dbLoadedDatastore, poddObject, fileMap, fileDescMap,
                authenticatedUser.getUserName());

        final HashMap<String, String> transferErrorMap = remoteFileHelper.uploadFiles(dbLoadedDatastore,
                poddObject);
        if (!transferErrorMap.isEmpty()) {
            // errors transferring some or all of the files, ensure the user gets the error messages back
            getResponse().setStatus(SERVER_ERROR_INTERNAL);
            errorMap.putAll(transferErrorMap);
            // rollback any changes to the object
            objectDao.refresh(poddObject);
        }

    } catch (IOException e) {
        final String msg = "Error transferring files to server - " + dbLoadedDatastore.getAddress()
                + " directory - " + dbLoadedDatastore.getDefaultDirectory();
        errorMap.put("errorMessage", msg);
        LOGGER.error(msg, e);
        auditLogHelper.auditAction(ERROR, authenticatedUser, "External File Attachment Service: " + msg,
                e.toString());
        objectDao.refresh(poddObject);
    }
}

From source file:com.antelink.sourcesquare.client.scan.SourceSquareFSWalker.java

private synchronized void analyzeMap(HashMap<String, String> tempMap) throws InterruptedException {
    if (tempMap == null || tempMap.isEmpty()) {
        return;/*from   w  w  w  .  j  a v a 2s .  c o  m*/
    }
    ProcessWorker worker = null;
    while ((worker = getAvailableProcessor()) == null) {
        synchronized (this.lock) {
            this.lock.wait();
        }

    }
    worker.process(new HashMap<String, String>(tempMap));
    tempMap.clear();
}

From source file:uk.ac.cam.cl.dtg.util.locations.IPInfoDBLocationResolver.java

/**
 * //  ww w.j a v  a 2 s  .  co  m
 * @param json
 *            response form IPInfoDB
 * @return A location object with as much detail as we can gather
 * @throws IOException
 *             if we cannot read the response from the server.
 * @throws LocationServerException
 *             - if the server returns a problem.
 */
private Location convertJsonToLocation(final String json) throws IOException, LocationServerException {
    ObjectMapper objectMapper = new ObjectMapper();

    @SuppressWarnings("unchecked")
    HashMap<String, String> response = objectMapper.readValue(json, HashMap.class);

    if (response == null || response.isEmpty()) {
        throw new IOException("The response from the IPInfoDBLocationResolver was null");
    }

    if (response.get(IPInfoDBLocationResponseProperties.STATUS_CODE + "") != null
            && response.get(IPInfoDBLocationResponseProperties.STATUS_CODE + "")
                    .equals(IPInfoDBLocationResponseProperties.ERROR_STATUS_CODE + "")) {
        throw new LocationServerException(String.format(
                "Unable to complete ip address to location lookup, "
                        + "server responded with the following message: %s",
                response.get(IPInfoDBLocationResponseProperties.STATUS_MESSAGE + "")));
    }

    Address partialAddress = new Address(null, null,
            response.get(IPInfoDBLocationResponseProperties.CITY_NAME + ""), null,
            response.get(IPInfoDBLocationResponseProperties.ZIP_CODE + ""),
            response.get(IPInfoDBLocationResponseProperties.COUNTRY_NAME + ""));
    String latString = response.get(IPInfoDBLocationResponseProperties.LATITUDE + "");
    String lonString = response.get(IPInfoDBLocationResponseProperties.LONGITUDE + "");

    Double lat;
    Double lon;
    if (null == latString || null == lonString) {
        lat = null;
        lon = null;
    } else {
        lat = Double.parseDouble(latString);
        lon = Double.parseDouble(lonString);
    }

    Location result = new Location(partialAddress, lat, lon);

    return result;
}

From source file:com.tongbanjie.tarzan.server.client.ClientManager.java

public void unregister(final String group, final ClientChannelInfo clientChannelInfo) {
    try {// w  ww  .j a  v a2s  .  co  m
        if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
            try {
                HashMap<Channel, ClientChannelInfo> channelTable = this.groupChannelTable.get(group);
                if (null != channelTable && !channelTable.isEmpty()) {
                    ClientChannelInfo old = channelTable.remove(clientChannelInfo.getChannel());
                    if (old != null) {
                        LOGGER.info("unregister a client[{}] from groupChannelTable {}", group,
                                clientChannelInfo.toString());
                    }

                    if (channelTable.isEmpty()) {
                        this.groupChannelTable.remove(group);
                        LOGGER.info("unregister a client group[{}] from groupChannelTable", group);
                    }
                }
            } finally {
                this.groupChannelLock.unlock();
            }
        } else {
            LOGGER.warn("ClientManager unregister client lock timeout");
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        LOGGER.error("", e);
    }
}

From source file:at.medevit.elexis.ehc.core.internal.EhcCoreServiceTest.java

@Test
public void testGetPatientDocument() {
    EhcCoreServiceImpl service = new EhcCoreServiceImpl();
    CdaCh cda = service.getCdaChDocument(patient, mandant);
    assertNotNull(cda);/*from  w w w .j  av  a2s . c  o  m*/
    org.ehealth_connector.common.Patient cdaPatient = cda.getPatient();
    assertNotNull(cdaPatient);
    assertEquals("name", cdaPatient.getName().getFamilyName());
    assertEquals("firstname", cdaPatient.getName().getGivenNames());
    assertEquals(AdministrativeGender.FEMALE, cdaPatient.getAdministrativeGenderCode());
    Calendar bDay = Calendar.getInstance();
    bDay.set(2000, 00, 01, 00, 00, 00);
    bDay.set(Calendar.MILLISECOND, 00);
    assertEquals(bDay.getTime(), cdaPatient.getBirthday());
    List<Address> addresses = cdaPatient.getAddresses();
    assertFalse(addresses.isEmpty());
    assertEquals("City", addresses.get(0).getCity());

    HashMap<String, AddressUse> phones = cdaPatient.getTelecoms().getPhones();
    assertFalse(phones.isEmpty());
    assertTrue(phones.containsKey("tel:+01555123"));
}