Java Code Examples for java.util.HashMap

The following are top voted examples for showing how to use java.util.HashMap. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: flow-android   File: FlowAsyncClient.java View source code 10 votes vote down vote up
public static void get(HashMap<String, String> headers, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    final AsyncHttpClient specialClient = new AsyncHttpClient();

    for (String key : headers.keySet()) {
        specialClient.addHeader(key, headers.get(key));
    }
    specialClient.get(getAbsoluteUrl(url), params, responseHandler);
}
 
Example 2
Project: virgo.kernel   File: GogoClassLoadingCommand.java View source code 8 votes vote down vote up
/**
 * Lists all bundles that export a class
 * 
 */
@Descriptor("list all bundles that export a class with the specified name")
public void clexport(@Descriptor("fully qualified class name") String className) {
    String classPackage = extractPackage(className);

    if (classPackage == null) {
        System.out.println("The class name [" + className + "] contains no package");
        return;
    }

    Bundle[] bundles = bundleContext.getBundles();
    HashMap<Long, String> foundBundles = new HashMap<Long, String>();
    for (Bundle bundle : bundles) {
        if (ClassLoadingHelper.isPackageExported(bundleContext, classPackage, bundle)) {
            if (ClassLoadingHelper.tryToLoadClass(className, bundle) != null) {
                foundBundles.put(bundle.getBundleId(), bundle.getSymbolicName());
            } else {
                foundBundles.put(bundle.getBundleId(), bundle.getSymbolicName() + "     [class not found, package only]");
            }
        }
    }

    if (foundBundles.size() == 0) {
        System.out.println("No bundle exports class [" + className + "]");
        return;
    }

    System.out.println();
    System.out.println("Bundles exporting [" + className + "]:");
    for (Map.Entry<Long, String> entry : foundBundles.entrySet()) {
        System.out.println("  " + entry.getKey() + "\t" + entry.getValue());
    }
}
 
Example 3
Project: xwiki-application-mailarchive   File: JavamailMessageParser.java View source code 7 votes vote down vote up
public HashMap<String, String> fillAttachmentContentIds(ArrayList<MimeBodyPart> bodyparts)
{
    HashMap<String, String> attmap = new HashMap<String, String>();

    for (MimeBodyPart bodypart : bodyparts) {
        String fileName = null;
        String cid = null;
        try {
            fileName = bodypart.getFileName();
            cid = bodypart.getContentID();
        } catch (MessagingException e) {
            logger.warn("Failed to retrieve attachment information", e);
        }
        if (!StringUtils.isBlank(cid) && fileName != null) {
            logger.debug("fillAttachmentContentIds: Treating attachment: {} with contentid {}", fileName, cid);
            String name = getAttachmentValidName(fileName);
            int nb = 1;
            if (!name.contains(".")) {
                name += ".ext";
            }
            String newName = name;
            while (attmap.containsValue(newName)) {
                logger.debug("fillAttachmentContentIds: " + newName + " attachment already exists, renaming to "
                    + name.replaceAll("(.*)\\.([^.]*)", "$1-" + nb + ".$2"));
                newName = name.replaceAll("(.*)\\.([^.]*)", "$1-" + nb + ".$2");
                nb++;
            }
            attmap.put(cid, newName);
        } else {
            logger.debug("fillAttachmentContentIds: content ID is null, nothing to do");
        }
    }

    return attmap;
}
 
Example 4
Project: arduino-android   File: ResponseHelper.java View source code 6 votes vote down vote up
private void handlePower(HashMap<String, String> params, Template t) 
{
	// power sockets are outputs 10-13
	t.set("POWERNAME1", getSetting("POWERNAME1", "Outlet 1"));
	t.set("POWERNAME2", getSetting("POWERNAME2", "Outlet 2"));
	t.set("POWERNAME3", getSetting("POWERNAME3", "Lights 1"));
	t.set("POWERNAME4", getSetting("POWERNAME4", "Lights 2"));
	String light = params.get("l");
	String state = params.get("s");
	DigitalOutputs outputs = mActivity.outputs;
	if (light != null && state != null)
	{
		int stateInt = Integer.parseInt(state);
		if (light.equalsIgnoreCase("A"))
		{
			outputs.setOutput(0x01, stateInt);
			outputs.setOutput(0x02, stateInt);
			outputs.setOutput(0x03, stateInt);
			outputs.setOutput(0x04, stateInt);				
		}
		else
		{
			outputs.setOutput(Integer.parseInt(light), stateInt);
		}
	}
}
 
Example 5
Project: JAME   File: ResourcesProcessorRuntime.java View source code 6 votes vote down vote up
/**
 * @see net.sf.jame.devtools.processor.extension.ProcessorExtensionRuntime#process(java.io.File, net.sf.jame.devtools.ProcessorDescriptor, java.util.List, java.util.Map)
 */
@Override
public void process(File path, ProcessorParameters parameters, Map<String, String> variables) throws DevToolsException {
	try {
		ProcessorDescriptor element = parameters.getElement();
		HashMap<String, Object> map = new HashMap<String, Object>();
		Set<String> imports = new HashSet<String>();
		prepare(imports, element);
		List<String> sortedImports = new LinkedList<String>(imports);
		Collections.sort(sortedImports);
		map.putAll(variables);
		map.put("imports", sortedImports);
		map.put("resources", element);
		if (element.isResources()) {
			File packagePath = new File(path, element.getResourcesPackageName().replace('.', '/'));
			packagePath.mkdirs();
			Configuration config = new Configuration();
			config.setTemplateLoader(new ProcessorTemplateLoader());
			Template template = config.getTemplate("templates/Resources.ftl");
			template.process(map, new PrintWriter(new File(packagePath, element.getResourcesClassName() + ".java")));
		}
	}
	catch (Exception e) {
		throw new DevToolsException(e);
	}
}
 
Example 6
Project: OsmUi   File: mxGmlGraph.java View source code 6 votes vote down vote up
/**
 * Returns the data element inside the node that references to the key element
 * with name = KEY_NODE_NAME.
 * @param node Gml Node element.
 * @return The required data. null if not found.
 */
public static mxGmlData dataNodeKey(mxGmlNode node)
{
	String keyId = "";
	HashMap<String, mxGmlKey> keyMap = mxGmlKeyManager.getInstance()
			.getKeyMap();
	
	for (mxGmlKey key : keyMap.values())
	{
		if (key.getKeyName().equals(mxGmlConstants.KEY_NODE_NAME))
		{
			keyId = key.getKeyId();
		}
	}

	mxGmlData data = null;
	HashMap<String, mxGmlData> nodeDataMap = node.getNodeDataMap();
	data = nodeDataMap.get(keyId);

	return data;
}
 
Example 7
Project: bixie   File: FaultLocalizationThread.java View source code 6 votes vote down vote up
/**
 * Applies fault localization to a set of (not necessarily connected)
 * infeasible blocks.
 * 
 * @param tr
 * @param infeasibleBlocks
 */
@Loggable
private List<Map<CfgStatement, SourceLocation>> localizeFaults(
		AbstractTransitionRelation tr, Set<BasicBlock> infeasibleBlocks) {

	List<Map<CfgStatement, SourceLocation>> reports = new LinkedList<Map<CfgStatement, SourceLocation>>();
	LinkedList<HashSet<BasicBlock>> components = findConnectedComponents(infeasibleBlocks);

	ProverFactory pf = new bixie.prover.princess.PrincessProverFactory();
	for (HashSet<BasicBlock> cmp : components) {
		try {
			this.prover = pf.spawn();
			this.prover.setConstructProofs(true);
			HashMap<CfgStatement, SourceLocation> res = localizeFault(tr,
					cmp, this.prover);
			if (res != null && !res.isEmpty()) {
				reports.add(res);
			}
		} catch (Throwable e) {
			e.printStackTrace();
			// throw e;
		} finally {
			shutDownProver();
		}
	}
	return reports;
}
 
Example 8
Project: aipo   File: BaseSecurityEntry.java View source code 6 votes vote down vote up
private void buildAccessMap()
{
    Map actionMap = null;
    SecurityAccess accessElement = null;

    synchronized (accessMapSync)
    {
        if (accessMap == null)
        {
            accessMap = new HashMap();
        }

        accessMap.clear();
    }
    // Build allow map
    for (Iterator accessIterator = getAccesses().iterator(); accessIterator.hasNext();)
    {
        accessElement = (SecurityAccess) accessIterator.next();

        // Get action map of the action.  Create one if none exists
        String action = accessElement.getAction();

        if (action == null)
        {
            action = ALL_ACTIONS;
        }

        actionMap = (Map) accessMap.get(action);
        if (actionMap == null)
        {
            actionMap = new HashMap();
            accessMap.put(action, actionMap);
        }
        addAllows(actionMap, accessElement);
    }
}
 
Example 9
Project: richfaces   File: JsonTest.java View source code 6 votes vote down vote up
public void testMapAddiition() throws Exception {
    JSONMap map = new JSONMap();
    Set set = map.entrySet();

    set.add(new JsonTestMockMapEntry("boolean", new Boolean(true)));
    set.add(new JsonTestMockMapEntry("double", new Double(23.45)));
    set.add(new JsonTestMockMapEntry("integer", new Integer(56)));
    set.add(new JsonTestMockMapEntry("long", new Long(89)));
    set.add(new JsonTestMockMapEntry("string", "testString"));

    HashSet hashSet = new HashSet();

    hashSet.add("15");
    hashSet.add(new Double(45.01));

    HashSet etalonSet = (HashSet) hashSet.clone();
    HashMap hashMap = new HashMap();

    hashMap.put("16", new Boolean(false));
    hashMap.put("key", new Double(145.01));

    HashMap etalonMap = (HashMap) hashMap.clone();

    set.add(new JsonTestMockMapEntry("collection", hashSet));
    set.add(new JsonTestMockMapEntry("map", hashMap));
    assertEquals(Boolean.TRUE, map.get("boolean"));
    assertEquals(new Double(23.45), map.get("double"));
    assertEquals(new Integer(56), map.get("integer"));
    assertEquals(new Long(89), map.get("long"));
    assertEquals("testString", map.get("string"));

    Collection collection = (Collection) map.get("collection");

    assertTrue(etalonSet.containsAll(collection));
    etalonSet.removeAll(collection);
    assertTrue(etalonSet.isEmpty());
    assertEquals(etalonMap, map.get("map"));
}
 
Example 10
Project: AppCompat-Extension-Library   File: FloatingActionMenuAnimatorEclair.java View source code 6 votes vote down vote up
@Override
public void startExpandAnimation(boolean animate) {
    mDimmingTransitionDrawable.startTransition(ANIMATION_DURATION);
    mRotationTransitionDrawable.setRotation(mRotationTransitionDrawable.getMaxRotation());
    for (HashMap.Entry<View, Animation> entry : mExpandAnimation.entrySet()) {
        View view = entry.getKey();
        Animation animation = entry.getValue();
        animation.setDuration(animate ? ANIMATION_DURATION : 0);
        view.clearAnimation();
        view.startAnimation(animation);
    }
}
 
Example 11
Project: cloudtm-data-platform   File: MaskedProperty.java View source code 6 votes vote down vote up
@Override
public synchronized String toString() {
	HashMap fake = new HashMap();
	Enumeration<?> names = propertyNames();
	while ( names.hasMoreElements() ) {
		Object nextElement = names.nextElement();
		fake.put( nextElement, this.getProperty( nextElement.toString() ) );
	}
	return fake.toString();
}
 
Example 12
Project: platform-packages-apps-Gallery3D   File: Gallery.java View source code 6 votes vote down vote up
void updatePicasaAccountStatus() {
    // We check to see if the authenticated accounts have
    // changed, if so, reload the datasource.

    // TODO: This should be done in PicasaDataFeed
    if (mGridLayer != null) {
        HashMap<String, Boolean> accountsEnabled = PicasaDataSource.getAccountStatus(this);
        if (!accountsEnabled.equals(mAccountsEnabled)) {
            mGridLayer.setDataSource(mGridLayer.getDataSource());
            mAccountsEnabled = accountsEnabled;
        }
    }
}
 
Example 13
Project: wisdom   File: WisdomTestTest.java View source code 6 votes vote down vote up
@Test
public void testJson() throws Exception {
    // Regular Json node
    final String json = "{\"a\":\"1\",\"property\":\"default value\"," +
            "\"bundle\":\"org.acme.demo.solution\"}";
    ObjectNode node = WisdomTest.MAPPER.readValue(json, ObjectNode.class);
    Action.ActionResult result = new Action.ActionResult(Results.ok(node), null);
    assertThat(test.json(result).toString()).isEqualTo(json);

    Map.Entry<String, Integer> entry = new HashMap.SimpleEntry<>("key", 1);
    result = new Action.ActionResult(Results.ok(entry).json(), null);
    assertThat(test.json(result).get("key").asInt()).isEqualTo(1);

    try {
        result = new Action.ActionResult(Results.ok("<h1>Hello</h1>"), null);
        test.json(result);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
        assertThat(e.getCause()).isInstanceOf(ClassCastException.class);
    }
}
 
Example 14
Project: google-web-toolkit-svnmirror   File: HashMapTest.java View source code 6 votes vote down vote up
public void testHashCode() {
  HashMap hashMap = new HashMap();
  checkEmptyHashMapAssumptions(hashMap);

  // Check that hashCode changes
  int hashCode1 = hashMap.hashCode();
  hashMap.put(KEY_KEY, VALUE_VAL);
  int hashCode2 = hashMap.hashCode();

  assertTrue(hashCode1 != hashCode2);
}
 
Example 15
Project: eGov   File: AgencyWiseCollectionService.java View source code 6 votes vote down vote up
/**
 * Grouping all the agency wise collection details to temporary demand.
 * Default adding status as history for this demand.
 * 
 * @param agencyWiseCollectionDetails
 * @param totalAmount
 * @param agencyWiseCollection
 * @param installment
 */
private void buildAgencyWiseDemand(final Set<AgencyWiseCollectionDetail> agencyWiseCollectionDetails,
        final BigDecimal totalAmount, final AgencyWiseCollection agencyWiseCollection, final Installment installment) {
    final EgDemand agencyWiseDemand = new EgDemand();

    final HashMap<EgDemandReason, BigDecimal> demandReasonWiseList = getAmountGroupingDemandReason(agencyWiseCollectionDetails);

    if (demandReasonWiseList.size() > 0)
        demandReasonWiseList.forEach((key, value) -> {
            agencyWiseDemand.addEgDemandDetails(EgDemandDetails.fromReasonAndAmounts(value, key, BigDecimal.ZERO));
        });

    agencyWiseDemand.setEgInstallmentMaster(installment);
    agencyWiseDemand.setIsHistory("Y");
    agencyWiseDemand.setCreateDate(new Date());
    agencyWiseDemand.setBaseDemand(totalAmount);
    agencyWiseDemand.setModifiedDate(new Date());
    agencyWiseCollection.setAgencyWiseDemand(agencyWiseDemand);
}
 
Example 16
Project: arduino-android   File: WebServer.java View source code 5 votes vote down vote up
private HashMap<String, String> parseParams(String paramsString)
{
 HashMap<String, String> map = new HashMap<String, String>();
 //arg1=fred&arg2=smith
 if (paramsString == null)
 {
  return map;
 }
 final int READING_NAME = 0;
 final int READING_VALUE = 1;
 String name = "";
 String value = "";
 int state = READING_NAME;
 int i = 0;
 char ch;
 int n = paramsString.length();
 while (i < n)
 {
  ch = paramsString.charAt(i);
  i++;
  if (state == READING_NAME)
  {
	  if (ch == '=')
	  {
		  state = READING_VALUE;
	  }
	  else
	  {
		  name = name + ch;
	  }
	  continue;
  }
  if (state == READING_VALUE)
  {
	  if (ch == '&' || i == n)
	  {
		  if (i == n)
		  {
			  value = value + ch;
		  }
		  map.put(name, value);
		  name = "";
		  value = "";
		  state = READING_NAME;
	  }
	  else
	  {
		  value = value + ch;
	  }
  }
 }
 return map;
}
 
Example 17
Project: jentrata-msh   File: EbxmlMessage.java View source code 5 votes vote down vote up
/**
 * initialize the object using SOAP message.
 * 
 * @param soapMessage
 *            Description of the Parameter
 * @throws SOAPException
 *             Description of the Exception
 */
private void init(SOAPMessage soapMessage) throws SOAPException {
    this.soapMessage = soapMessage;

    // set default SOAP XML declaration and encoding
    this.soapMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, 
    		Boolean.toString(EbxmlMessage.WRITE_XML_DECLARATION));
    this.soapMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, 
    		EbxmlMessage.CHARACTER_SET_ENCODING);

    this.soapEnvelope = this.soapMessage.getSOAPPart().getEnvelope();
    headerContainer = new HeaderContainer(soapMessage.getSOAPPart());
    payloadContainers = new ArrayList();

    /*
     * this.soapMessage = soapMessage; this.soapEnvelope =
     * soapMessage.getSOAPPart().getEnvelope(); final SOAPHeader soapHeader =
     * soapEnvelope.getHeader(); final SOAPBody soapBody =
     * soapEnvelope.getBody(); headerContainer = new
     * HeaderContainer(soapMessage.getSOAPPart()); payloadContainers = new
     * ArrayList();
     */
    Manifest manifest = headerContainer.getManifest();
    if (manifest != null) {
        Iterator it = manifest.getReferences();
        HashMap cidMap = new HashMap();
        while (it.hasNext()) {
            Reference reference = (Reference) it.next();
            String cid = reference.getHref();
            if (cid.startsWith(Reference.HREF_PREFIX)) {
                cid = cid.substring(Reference.HREF_PREFIX.length());
                cidMap.put(cid, reference);
            }
        }

        for (Iterator attachments = soapMessage.getAttachments(); attachments
                .hasNext();) {
            final AttachmentPart attachment = (AttachmentPart) attachments
                    .next();
            String contentId = attachment.getContentId();
            if (contentId.startsWith("<") && needPatch) {
                contentId = contentId.substring(1);
                if (contentId.endsWith(">")) {
                    contentId = contentId.substring(0,
                            contentId.length() - 1);
                }
            }
            contentId = contentId.trim();
            if (cidMap.containsKey(contentId)) {
                payloadContainers.add(new PayloadContainer(attachment
                        .getDataHandler(), contentId, (Reference) cidMap
                        .get(contentId)));
            }
        }
    }
    String[] soapAction = this.soapMessage.getMimeHeaders().getHeader(
            SOAP_ACTION);
    if (headerContainer.getMessageHeader() == null || soapAction == null
            || !soapAction[0].equals(SOAP_ACTION_VALUE)) {
        this.soapMessage.getMimeHeaders().setHeader(SOAP_ACTION,
                SOAP_ACTION_VALUE);
    }
    
    String soapPartContentId = this.soapMessage.getSOAPPart()
            .getContentId();
    if (soapPartContentId == null || soapPartContentId.equals("")) {
        soapPartContentId = (
                               needPatch ? " <" + SOAP_PART_CONTENT_ID +
                               ">" :
                              
        SOAP_PART_CONTENT_ID);
        this.soapMessage.getSOAPPart().setContentId(soapPartContentId);
    }

    /*
     * String[] soapAction =
     * soapMessage.getMimeHeaders().getHeader(SOAP_ACTION); if
     * (headerContainer.getMessageHeader() == null || soapAction == null ||
     * !soapAction[0].equals(SOAP_ACTION_VALUE)) {
     * soapMessage.getMimeHeaders(). setHeader(SOAP_ACTION,
     * SOAP_ACTION_VALUE); } String soapPartContentId =
     * soapMessage.getSOAPPart().getContentId(); if (soapPartContentId ==
     * null || soapPartContentId.equals("")) { soapPartContentId =
     * (needPatch ? " <" + SOAP_PART_CONTENT_ID + ">" :
     * SOAP_PART_CONTENT_ID);
     * soapMessage.getSOAPPart().setContentId(soapPartContentId); }
     */
    filename = null;
    messageOrder = null;
}
 
Example 18
Project: UnicentaPOS_AD   File: TaxesLogic.java View source code 5 votes vote down vote up
public TaxesLogic(List<TaxInfo> taxlist) {
        this.taxlist = taxlist;
      
// JG June 2013 use diamond inference
        taxtrees = new HashMap<>();
                
        // Order the taxlist by Application Order...
        // JG June 2013 use diamond inference        
        List<TaxInfo> taxlistordered = new ArrayList<>();
        taxlistordered.addAll(taxlist);
        Collections.sort(taxlistordered, new Comparator<TaxInfo>() {
            @Override
            public int compare(TaxInfo o1, TaxInfo o2) {
                if (o1.getApplicationOrder() < o2.getApplicationOrder()) {
                    return -1;
                } else if (o1.getApplicationOrder() == o2.getApplicationOrder()) {
                    return 0;
                } else {
                    return 1;
                }
            }
        });
        
        // Generate the taxtrees
        // JG June 2013 use diamond inference        
        HashMap<String, TaxesLogicElement> taxorphans = new HashMap<>();
        
        for (TaxInfo t : taxlistordered) {
                       
            TaxesLogicElement te = new TaxesLogicElement(t);
            
            // get the parent
            TaxesLogicElement teparent = taxtrees.get(t.getParentID());
            if (teparent == null) {
                // orphan node
                teparent = taxorphans.get(t.getParentID());
                if (teparent == null) {
                    teparent = new TaxesLogicElement(null);
                    taxorphans.put(t.getParentID(), teparent);
                } 
            } 
            
            teparent.getSons().add(te);

            // Does it have orphans ?
            teparent = taxorphans.get(t.getId());
            if (teparent != null) {
                // get all the sons
                te.getSons().addAll(teparent.getSons());
                // remove the orphans
                taxorphans.remove(t.getId());
            }          
            
            // Add it to the tree...
            taxtrees.put(t.getId(), te);
        }
    }