Example usage for java.util HashMap clear

List of usage examples for java.util HashMap clear

Introduction

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

Prototype

public void clear() 

Source Link

Document

Removes all of the mappings from this map.

Usage

From source file:com.qpark.maven.plugin.relativeschemalocation.ToRelativeSchemaLocationMojo.java

/**
 * @see org.apache.maven.plugin.Mojo#execute()
 *//*from ww w  .java2  s .  c  om*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    StaticLoggerBinder.getSingleton().setLog(this.getLog());
    this.getLog().debug("+execute");
    this.getLog().debug("get xsds");

    Map<String, XsdContainer> map = XsdsUtil.getXsdContainers(this.baseDirectory);
    HashMap<String, String> replacements = new HashMap<String, String>();
    for (XsdContainer xc : map.values()) {
        replacements.clear();
        try {
            String xml = Util.readFile(xc.getFile());
            String basePath = Util.getRelativePathTranslated(this.baseDirectory, xc.getFile());
            this.getLog().debug(basePath);
            String backPath = this.getBackPath(basePath);
            String xsdPath;
            String newPath;
            int index = xml.indexOf("schemaLocation=\"http", 0);
            int quoteIndex;
            while (index > 0) {
                quoteIndex = xml.indexOf('"', index + 16);
                if (quoteIndex < 0) {
                    break;
                }
                xsdPath = xml.substring(index + 16, quoteIndex);
                newPath = this.getNewPath(xsdPath, backPath, map.values());
                if (newPath != null) {
                    this.getLog().debug(new StringBuffer(xsdPath.length() + 5 + newPath.length())
                            .append(xsdPath).append(" => ").append(newPath).toString());
                    replacements.put(xsdPath, newPath);
                }
                index = xml.indexOf("schemaLocation=\"http", quoteIndex);
            }
            for (String key : replacements.keySet()) {
                xml = StringUtils.replace(xml, key, replacements.get(key));
            }
            File f = Util.getFile(this.outputDirectory, basePath);
            this.getLog().info(new StringBuffer().append("Write ").append(f.getAbsolutePath()));
            Util.writeToFile(f, xml);
        } catch (IOException e) {
            this.getLog().error(e.getMessage());
            e.printStackTrace();
        }
    }
    this.getLog().debug("-execute");
}

From source file:com.mobileman.moments.core.security.UserSecurityService.java

private void sanitizeUserCacheInfo(UserCacheInfo userCacheInfo) {
    if (false) {//w  w w. j av a 2  s  . c o  m
        HashMap<String, Date> tokens = userCacheInfo.getTokens();
        if (tokens.size() > 10) {
            tokens.clear(); // Protection against too many devices
        }
        // remove older items
        Date now = DateUtils.addSeconds(new Date(), -60 * 10);
        HashSet<String> ks = new HashSet<String>(tokens.keySet());
        for (String key : ks) {
            Date d = tokens.get(key);
            if (now.after(d)) {
                tokens.remove(key);
            }
        }
    }
}

From source file:com.datatorrent.lib.logs.TopNUniqueSiteStatsTest.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(TopNUnique oper) {
    CollectorTestSink sortSink = new CollectorTestSink();
    oper.top.setSink(sortSink);/*from   ww w  . jav  a 2  s .  c  o m*/
    oper.setN(3);

    oper.beginWindow(0);
    HashMap<String, DimensionObject<String>> input = new HashMap<String, DimensionObject<String>>();

    input.put("url", new DimensionObject<String>(new MutableDouble(10), "abc"));
    oper.data.process(input);

    input.clear();
    input.put("url", new DimensionObject<String>(new MutableDouble(1), "def"));
    input.put("url1", new DimensionObject<String>(new MutableDouble(1), "def"));
    oper.data.process(input);

    input.clear();
    input.put("url", new DimensionObject<String>(new MutableDouble(101), "ghi"));
    input.put("url1", new DimensionObject<String>(new MutableDouble(101), "ghi"));
    oper.data.process(input);

    input.clear();
    input.put("url", new DimensionObject<String>(new MutableDouble(50), "jkl"));
    oper.data.process(input);

    input.clear();
    input.put("url", new DimensionObject<String>(new MutableDouble(50), "jkl"));
    input.put("url3", new DimensionObject<String>(new MutableDouble(50), "jkl"));
    oper.data.process(input);
    oper.endWindow();

    Assert.assertEquals("number emitted tuples", 3, sortSink.collectedTuples.size());
    for (Object o : sortSink.collectedTuples) {
        log.debug(o.toString());
    }
    log.debug("Done testing round\n");
}

From source file:com.datatorrent.lib.util.AbstractBaseFrequentKeyValueMap.java

/**
 * Emits the result.//  ww w  .  ja v a 2 s .  c  om
 */
@Override
public void endWindow() {
    HashMap<V, Object> vmap = new HashMap<V, Object>();
    for (Map.Entry<K, HashMap<V, MutableInt>> e : keyvals.entrySet()) {
        V val = null;
        int kval = -1;
        vmap.clear();
        HashMap<V, MutableInt> vals = e.getValue();
        for (Map.Entry<V, MutableInt> v : vals.entrySet()) {
            if (kval == -1) {
                val = v.getKey();
                kval = v.getValue().intValue();
                vmap.put(val, null);
            } else if (compareValue(v.getValue().intValue(), kval)) {
                val = v.getKey();
                kval = v.getValue().intValue();
                vmap.clear();
                vmap.put(val, null);
            } else if (v.getValue().intValue() == kval) {
                vmap.put(v.getKey(), null);
            }
        }
        if ((val != null) && (kval > 0)) { // key is null if no
            HashMap<K, HashMap<V, Integer>> tuple = new HashMap<K, HashMap<V, Integer>>(1);
            HashMap<V, Integer> valpair = new HashMap<V, Integer>();
            for (Map.Entry<V, Object> v : vmap.entrySet()) {
                valpair.put(v.getKey(), new Integer(kval));
            }
            tuple.put(e.getKey(), valpair);
            emitTuple(tuple);
        }
    }
    keyvals.clear();
}

From source file:org.n52.v3d.triturus.t3dutil.operatingsystem.PropertyLoader.java

public HashMap getPropertiesForPrefix(String pPrefix, HashMap pMap) {
    Iterator it = mPropertiesMap.keySet().iterator();
    pMap.clear();
    while (it.hasNext()) {
        String key = (String) it.next();
        if (key.indexOf(pPrefix) == 0)
            pMap.put(key, mPropertiesMap.get(key));
    }/*from   w ww .j  a v  a  2  s .  com*/
    return pMap;
}

From source file:com.wms.studio.cache.memcache.MemCacheMapCache.java

@Override
public void clear() throws CacheException {
    // ??????memcache?????
    synchronized (name) {
        try {//  w  ww . j  a v a 2 s .  c  o  m
            memcachedClient.cas(name, new CASOperation<HashMap<K, V>>() {

                @Override
                public int getMaxTries() {
                    return reCount;
                }

                @Override
                public HashMap<K, V> getNewValue(long currentCAS, HashMap<K, V> currentValue) {

                    if (currentValue == null) {
                        currentValue = new HashMap<>();
                    }
                    currentValue.clear();
                    return currentValue;
                }
            });
        } catch (TimeoutException | InterruptedException | MemcachedException e) {
            log.fatal("MemCache", e);
        }
    }
}

From source file:com.github.haixing_hu.bean.DefaultProperty.java

@Override
public final void setMappedValue(final HashMap<String, Object> map) {
    checkKind(PropertyKind.MAPPED);/*  w w w  .j  a va2s  . c om*/
    requireNonNull("map", map);
    for (final Object obj : map.values()) {
        checkType(obj);
    }
    @SuppressWarnings("unchecked")
    final HashMap<String, Object> valueMap = (HashMap<String, Object>) value;
    valueMap.clear();
    valueMap.putAll(map);
}

From source file:it.cnr.icar.eric.client.xml.registry.RegistryFacadeTest.java

/**
 * Test executing WSDL Discovery queries.
 *//*from w  ww.j a  v a  2s .  co m*/
public void testExecuteQuery() throws Exception {
    HashMap<String, String> queryParams = new HashMap<String, String>();
    Collection<?> registryObjects = null;

    //WSDLDiscoveryQuery: Find all WSDL files
    queryParams.clear();
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_WSDL_DISCOVERY, queryParams);
    assertTrue("This is a known failure that needs to be investigated and fixed by Farrukh. "
            + "Failed to find WSDL documents.", registryObjects.size() >= 1);

    //WSDLDiscoveryQuery: Find WSDL files with $targetNamespace matching "%urn:goes:here"
    queryParams.clear();
    queryParams.put("$targetNamespace", "%urn:goes:here");
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_WSDL_DISCOVERY, queryParams);
    assertTrue("This is a known failure that needs to be investigated and fixed by Farrukh. "
            + "Failed to find WSDL documents.", registryObjects.size() >= 1);

    //ServiceDiscoveryQuery: Find WSDL Service with $service.name matching "%regrep%"
    queryParams.clear();
    queryParams.put("$service.name", "%ebXML%");
    queryParams.put("$considerPort", "0");
    queryParams.put("$considerBinding", "0");
    queryParams.put("$considerPortType", "0");
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_SERVICE_DISCOVERY, queryParams);
    assertTrue("Failed to find WSDL Service.", registryObjects.size() >= 1);

    //PortDiscoveryQuery: Find WSDL Port with $binding.name matching "%query%"
    queryParams.clear();
    queryParams.put("$port.name", "%query%");
    queryParams.put("$considerBinding", "0");
    queryParams.put("$considerPortType", "0");
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_PORT_DISCOVERY, queryParams);
    assertTrue("Failed to find WSDL Port.", registryObjects.size() >= 1);

    //BindingDiscoveryQuery: Find WSDL Binding with $binding.name matching "%query%"
    queryParams.clear();
    queryParams.put("$binding.name", "%query%");
    queryParams.put("$considerPortType", "0");
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_BINDING_DISCOVERY, queryParams);
    assertTrue("Failed to find WSDL Binding.", registryObjects.size() >= 1);

    //PortTypeDiscoveryQuery: Find WSDL PortType with $binding.name matching "%query%"
    queryParams.clear();
    queryParams.put("$portType.name", "%query%");
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_PORTTYPE_DISCOVERY, queryParams);
    assertTrue("Failed to find WSDL PortType.", registryObjects.size() >= 1);

    //Now test more complex params
    //ServiceDiscoveryQuery: Find WSDL Service with specified binding and portType params
    queryParams.clear();
    queryParams.put("$considerPort", "1");
    queryParams.put("$considerBinding", "1");
    queryParams.put("$binding.soapStyleType",
            "/urn:oasis:names:tc:ebxml-regrep:profile:ws:classificationScheme:SOAPStyleType/Document");
    queryParams.put("$considerPortType", "1");
    queryParams.put("$portType.name", "%query%");
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_SERVICE_DISCOVERY, queryParams);
    assertTrue("Failed to find WSDL Service.", registryObjects.size() >= 1);

    //ServiceDiscoveryQuery: Find WSDL Service with specified binding (and no portType) params
    queryParams.clear();
    queryParams.put("$considerPort", "1");
    queryParams.put("$considerBinding", "1");
    queryParams.put("$binding.targetNamespace", "%binding%");
    queryParams.put("$considerPortType", "0");
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_SERVICE_DISCOVERY, queryParams);
    assertTrue("Failed to find WSDL Service.", registryObjects.size() >= 1);

    //BindingDiscoveryQuery: Find WSDL Binding with specified binding and portType params
    queryParams.clear();
    queryParams.put("$considerPortType", "1");
    queryParams.put("$portType.name", "%query%");
    queryParams.put("$portType.targetNamespace",
            "urn:oasis:names:tc:ebxml-regrep:wsdl:registry:interfaces:3.0");
    registryObjects = facade.executeQuery(CanonicalConstants.CANONICAL_QUERY_BINDING_DISCOVERY, queryParams);
    assertTrue("Failed to find WSDL Binding.", registryObjects.size() == 1);

}

From source file:org.powertac.common.repo.TariffRepo.java

/**
 * Returns the n most "recent" active tariffs from each broker
 * that can be used by a customer with the given powerType. 
 *//* ww w  .  j  ava  2  s  .c  o m*/
public synchronized List<Tariff> findRecentActiveTariffs(int n, PowerType type) {
    List<Tariff> result = new ArrayList<Tariff>();
    HashMap<PowerType, Integer> ptCounter = new HashMap<PowerType, Integer>();
    for (Long id : brokerTariffs.keySet()) {
        ptCounter.clear();
        for (Tariff tariff : brokerTariffs.get(id)) {
            PowerType pt = tariff.getPowerType();
            if (tariff.isSubscribable() && type.canUse(pt)) {
                Integer count = ptCounter.get(pt);
                if (null == count)
                    count = 0;
                if (count < n) {
                    result.add(tariff);
                    ptCounter.put(pt, count + 1);
                }
            }
        }
    }
    return result;
}

From source file:com.sxt.superqq.fragment.SettingsFragment.java

void logout() {
    final ProgressDialog pd = new ProgressDialog(getActivity());
    String st = getResources().getString(R.string.Are_logged_out);
    pd.setMessage(st);//from   w w w  .j  a v a2s  . c  o m
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    SuperQQApplication.getInstance().logout(new EMCallBack() {

        @Override
        public void onSuccess() {
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    //????
                    ArrayList<UserBean> contactList = SuperQQApplication.getInstance().getContactList();
                    contactList.clear();
                    HashMap<Integer, ContactBean> contacts = SuperQQApplication.getInstance().getContacts();
                    contacts.clear();
                    pd.dismiss();
                    // ??
                    ((MainActivity) getActivity()).finish();
                    startActivity(new Intent(getActivity(), LoginActivity.class));

                }
            });
        }

        @Override
        public void onProgress(int progress, String status) {

        }

        @Override
        public void onError(int code, String message) {

        }
    });
}