Java Code Examples for java.util.Hashtable#put()

The following examples show how to use java.util.Hashtable#put() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testConnectionFactoryBindingWithInvalidFactorySpecificProperty() throws Exception {
    String factoryName = "myNewFactory";
    String uri = "amqp://example.com:1234";

    String propertyPrefix = JmsInitialContextFactory.CONNECTION_FACTORY_PROPERTY_KEY_PREFIX;

    Hashtable<Object, Object> env = new Hashtable<Object, Object>();
    env.put(JmsInitialContextFactory.CONNECTION_FACTORY_KEY_PREFIX + factoryName, uri);
    env.put(propertyPrefix + factoryName + "." + "invalidProperty", "value");

    try {
        createInitialContext(env);
        fail("Should have thrown exception");
    } catch (NamingException ne) {
        // Expected
        assertTrue("Should have had a cause", ne.getCause() != null);
    }
}
 
Example 2
/**
 * Loads an image from resources and returns it.
 * 
 * Caches all loaded images in hopes of saving some memory.
 *
 * @param imagePath
 * @return loaded image
 * @throws IOException
 */
public final Image loadImage(final String imagePath, final Hashtable cache)
    throws IOException {
    Image image = null;
    if (cache != null) {
        image = (Image) cache.get(imagePath);
    }
    if (image == null) {
        InputStream in = this.getClass().getResourceAsStream(imagePath);
        if (in == null) {
            throw new IOException("Image not found.");
        }
        image = Image.createImage(in);
        if (cache != null) {
            cache.put(imagePath, image);
        }
    }
    return image;
}
 
Example 3
Source Project: DanDanPlayForAndroid   File: TimedTextObject.java    License: MIT License 6 votes vote down vote up
/**
 * This method simply checks the style list and eliminate any style not referenced by any caption
 * This might come useful when default styles get created and cover too much.
 * It require a unique iteration through all captions.
 * 
 */
protected void cleanUnusedStyles(){
	//here all used styles will be stored
	Hashtable<String, Style> usedStyles = new Hashtable<>();
	//we iterate over the captions
	Iterator<Caption> itrC = captions.values().iterator();
	while(itrC.hasNext()){
		//new caption
    	Caption current = itrC.next();
    	//if it has a style
    	if(current.style != null){
    		String iD = current.style.iD;
    		//if we haven't saved it yet
    		if(!usedStyles.containsKey(iD))
    			usedStyles.put(iD, current.style);
    	}
	}
	//we saved the used styles
	this.styling = usedStyles;
}
 
Example 4
Source Project: zql   File: PreparedDemo.java    License: GNU General Public License v3.0 6 votes vote down vote up
static void handleUpdate(ZUpdate upd) throws Exception {
  System.out.println("UPDATE Statement:");

  String tab = upd.getTable();
  Hashtable set = upd.getSet();
  Enumeration k = set.keys();
  while(k.hasMoreElements()) {
    String col = (String)k.nextElement();
    ZExp e = (ZExp)set.get(col);
    if(isPreparedColumn(e)) {
      System.out.println("[" + tab + "," + col + "]");
    }
  }

  ZExpression w = (ZExpression)upd.getWhere();
  if(w != null) {
    Hashtable meta = new Hashtable(1);
    meta.put(tab, tab);
    handleWhere(w, meta);
  }

}
 
Example 5
/**
 * 获取所有当前元素节点的全部属性。如果当前节点没有属性,返回 null。
 * @param ns
 *            需声明的名空间,键为地址,必须与 XML 文件中声明的地址一致。值为前缀,可与XML文件实际前缀不同。
 * @exception XPathEvalException
 *                ,XPathParseException,NavException
 */
public Hashtable<String, String> getCurrentElementAttributs(Hashtable<String, String> ns)
		throws XPathParseException, XPathEvalException, NavException {
	Hashtable<String, String> attributes = new Hashtable<String, String>();
	AutoPilot apAttributes = new AutoPilot(vn);
	if (ns != null) {
		Iterator<String> nsIt = ns.keySet().iterator();
		while (nsIt.hasNext()) {
			String nsUrl = nsIt.next();
			String nsPrefix = ns.get(nsUrl);
			apAttributes.declareXPathNameSpace(nsPrefix, nsUrl);
		}
	}

	apAttributes.selectXPath("@*");

	int inx = -1;
	while ((inx = apAttributes.evalXPath()) != -1) {
		String name = vn.toString(inx);
		inx = vn.getAttrVal(name);
		String value = inx != -1 ? vn.toString(inx) : "";
		attributes.put(name, value);
	}
	apAttributes.resetXPath();

	if (attributes.isEmpty()) {
		attributes = null;
	}
	return attributes;
}
 
Example 6
public static Hashtable<String, Object> copy ( final Dictionary<String, ?> properties )
{
    final Hashtable<String, Object> newProps = new Hashtable<> ( properties.size () );
    final Enumeration<String> en = properties.keys ();
    while ( en.hasMoreElements () )
    {
        final String key = en.nextElement ();
        newProps.put ( key, properties.get ( key ) );
    }
    return newProps;
}
 
Example 7
@Test
public void testXACF() throws NamingException, JMSException {
   Hashtable<String, String> props = new Hashtable<>();
   props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
   props.put("connectionFactory.myConnectionFactory", "vm://0?type=XA_CF");
   Context ctx = new InitialContext(props);

   ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");

   Assert.assertEquals(JMSFactoryType.XA_CF.intValue(), connectionFactory.getFactoryType());
}
 
Example 8
@Override
public Hashtable<String, Object> getDump() {
    Hashtable<String, Object> result = super.getDump();
    if (((Label) getSource()).getText() != null) {
        result.put(TEXT_DPROP, ((Label) getSource()).getText());
    } else {
        result.put(TEXT_DPROP, "null");
    }
    return result;
}
 
Example 9
/**
 * The method to use when all the dependencies are resolved.
 * <p>
 * It means iPojo guarantees that both the manager and the HTTP
 * service are not null.
 * </p>
 *
 * @throws Exception
 */
public void start() throws Exception {

	// Is the DM part of the distribution?
	boolean found = false;
	for( Bundle b : this.bundleContext.getBundles()) {
		if( "net.roboconf.dm".equals( b.getSymbolicName())) {
			found = true;
			break;
		}
	}

	// If we are on an agent, we have nothing to do.
	// Otherwise, we must register a servlet.
	if( found ) {
		this.logger.fine( "iPojo registers a servlet for HTTP messaging." );

		Hashtable<String,String> initParams = new Hashtable<String,String> ();
		initParams.put( "servlet-name", "Roboconf DM (HTTP messaging)" );

		DmWebSocketServlet messagingServlet = new DmWebSocketServlet( this );
		this.httpService.registerServlet( HttpConstants.DM_SOCKET_PATH, messagingServlet, initParams, null );

	} else {
		this.logger.warning( "Roboconf's DM bundle was not found. No servlet will be registered." );
	}
}
 
Example 10
private void createAttributes() {	
  Priority prio[] = Priority.getAllPossiblePriorities();
  
  attributes = new Hashtable();
  for (int i=0; i<prio.length;i++) {
    MutableAttributeSet att = new SimpleAttributeSet();
    attributes.put(prio[i], att);
    StyleConstants.setFontSize(att,14);
  }
  StyleConstants.setForeground((MutableAttributeSet)attributes.get(Priority.ERROR),Color.red);
  StyleConstants.setForeground((MutableAttributeSet)attributes.get(Priority.WARN),Color.orange);
  StyleConstants.setForeground((MutableAttributeSet)attributes.get(Priority.INFO),Color.gray);
  StyleConstants.setForeground((MutableAttributeSet)attributes.get(Priority.DEBUG),Color.black);
}
 
Example 11
Source Project: oodt   File: XmlRpcStructFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> getXmlRpcQueryResult(QueryResult queryResult) {
  Hashtable<String, Object> queryResultHash = new Hashtable<String, Object>();
  if (queryResult.getToStringFormat() != null) {
    queryResultHash.put("toStringFormat", queryResult.getToStringFormat());
  }
  queryResultHash.put("product", getXmlRpcProduct(queryResult.getProduct()));
  queryResultHash.put("metadata", queryResult.getMetadata().getHashTable());
  return queryResultHash;
}
 
Example 12
@Test
public void testTopicBindingWithMulupleSlashesInLookupName() throws Exception {
    String lookupName = "my/Lookup/Name";
    String actualName = "myTopicName";

    Hashtable<Object, Object> env = new Hashtable<Object, Object>();
    env.put(JmsInitialContextFactory.TOPIC_KEY_PREFIX + lookupName, actualName);

    Context ctx = createInitialContext(env);
    Object o = ctx.lookup(lookupName);

    assertNotNull("No object returned", o);
    assertEquals("Unexpected class type for returned object", JmsTopic.class, o.getClass());
    assertEquals("Unexpected name for returned object", actualName, ((JmsTopic) o).getTopicName());
}
 
Example 13
private void grow() {
    Object[] array = (Object[])table;
    Hashtable<Object, Object> tmp = new Hashtable<Object, Object>(array.length/2);
    for (int i = 0; i<array.length; i+=2) {
        tmp.put(array[i], array[i+1]);
    }
    table = tmp;
}
 
Example 14
/**
 * 根据节点的纯文本获取对应的术语 robert 2011-12-22
 * @param srcPureText
 *            源节点的纯文本
 * @param srcLang
 *            源语言
 * @param tarLang
 *            目标语言
 * @return
 * @throws SQLException
 */
public Vector<Hashtable<String, String>> findAllTermsByText(String srcPureText, String srcLang, String tarLang)
		throws SQLException {
	Vector<Hashtable<String, String>> terms = new Vector<Hashtable<String, String>>();
	// 构建SQL
	String getTermSql = dbConfig.getOperateDbSQL("getTerm");
	PreparedStatement stmt = conn.prepareStatement(getTermSql);

	stmt.setString(1, tarLang);
	stmt.setString(2, srcLang + "," + tarLang);
	stmt.setString(3, tarLang + "," + srcLang);
	stmt.setString(4, srcLang);
	stmt.setString(5, srcPureText.toLowerCase());

	ResultSet rs = stmt.executeQuery();
	while (rs.next()) {
		String tuid = rs.getString(1);
		String srcWord = rs.getString(2);
		String tgtWord = rs.getString(3);
		String property = rs.getString(4);
		Hashtable<String, String> tu = new Hashtable<String, String>();
		tu.put("tuid", tuid);
		tu.put("srcLang", srcLang);
		tu.put("srcWord", srcWord);
		tu.put("tgtLang", tarLang);
		tu.put("tgtWord", tgtWord);
		tu.put("property", property == null ? "" : property);
		terms.add(tu);
	}
	rs.close();
	stmt.close();
	return terms;
}
 
Example 15
/**
 * Examine and consume command line arguments.
 * @param argv The command line arguments. Ignore null
 * and unknown arguments. Set each consumed argument to null.
 * @param error Report any errors using the main.error() methods.
 * @return true if no errors, false otherwise.
 */
public boolean parseArgs(String argv[], Main main) {
    Object marker = new Object() ;

    // Reset any cached options...

    reverseIDs = false;
    localStubs = true;
    useHash = true;
    stubBaseClass = DEFAULT_STUB_CLASS;
    //       tieBaseClass = DEFAULT_TIE_CLASS;
    transactionalObjects = new Hashtable() ;

    // Parse options...

    boolean result = super.parseArgs(argv,main);
    if (result) {
        for (int i = 0; i < argv.length; i++) {
            if (argv[i] != null) {
                String arg = argv[i].toLowerCase();
                if (arg.equals("-iiop")) {
                    argv[i] = null;
                } else if (arg.equals("-xreverseids")) {
                    reverseIDs = true;
                    argv[i] = null;
                } else if (arg.equals("-nolocalstubs")) {
                    localStubs = false;
                    argv[i] = null;
                } else if (arg.equals("-xnohash")) {
                    useHash = false;
                    argv[i] = null;
                } else if (argv[i].equals("-standardPackage")) {
                    standardPackage = true;
                    argv[i] = null;
                } else if (argv[i].equals("-emitPermissionCheck")) {
                    emitPermissionCheck = true;
                    argv[i] = null;
                } else if (arg.equals("-xstubbase")) {
                    argv[i] = null;
                    if (++i < argv.length && argv[i] != null && !argv[i].startsWith("-")) {
                        stubBaseClass = argv[i];
                        argv[i] = null;
                    } else {
                        main.error("rmic.option.requires.argument", "-Xstubbase");
                        result = false;
                    }
                } else if (arg.equals("-xtiebase")) {
                    argv[i] = null;
                    if (++i < argv.length && argv[i] != null && !argv[i].startsWith("-")) {
                        tieBaseClass = argv[i];
                        argv[i] = null;
                    } else {
                        main.error("rmic.option.requires.argument", "-Xtiebase");
                        result = false;
                    }
                } else if (arg.equals("-transactional" )) {
                    // Scan for the next non-flag argument.
                    // Assume that it is a class name and add it
                    // to the list of transactional classes.
                    for ( int ctr=i+1; ctr<argv.length; ctr++ ) {
                        if (argv[ctr].charAt(1) != '-') {
                            transactionalObjects.put( argv[ctr], marker ) ;
                            break ;
                        }
                    }
                    argv[i] = null;
                } else if (arg.equals( "-poa" )) {
                    POATie = true ;
                    argv[i] = null;
                }
            }
        }
    }
    if(POATie){
        tieBaseClass = DEFAULT_POA_TIE_CLASS;
    } else {
        tieBaseClass = DEFAULT_TIE_CLASS;
    }
    return result;
}
 
Example 16
/**
  * returns a hashtable with the association 
  * "file extension &lt;-&gt; converter classname" for the list of converter 
  * classnames.
  * 
  * @param classnames	list of converter classnames
  * @param intf	interfaces the converters have to implement
  * @return		hashtable with ExtensionFileFilters
  */
 protected static Hashtable<String,String> getFileConverters(Vector classnames, String[] intf) {
   Hashtable<String,String>	result;
   String 			classname;
   Class 			cls;
   String[] 			ext;
   FileSourcedConverter 	converter;
   int 			i;
   int				n;
   
   result = new Hashtable<String,String>();
   
   for (i = 0; i < classnames.size(); i++) {
     classname = (String) classnames.get(i);

     // all necessary interfaces implemented?
     for (n = 0; n < intf.length; n++) {
if (!ClassDiscovery.hasInterface(intf[n], classname))
  continue;
     }
     
     // get data from converter
     try {
cls       = Class.forName(classname);
converter = (FileSourcedConverter) cls.newInstance();
ext       = converter.getFileExtensions();
     }
     catch (Exception e) {
cls       = null;
converter = null;
ext       = new String[0];
     }
     
     if (converter == null)
continue;

     for (n = 0; n < ext.length; n++)
result.put(ext[n], classname);
   }
   
   return result;
 }
 
Example 17
/**
 * Construct parameters from SiriusIonAnnotation Amount of params differ, either it is identified
 * by SiriusIdentificationMethod, or also by FingerIdWebMethod
 * 
 * @param annotation
 * @return constructed Hashtable
 */
private static Hashtable<String, String> loadProps(final SiriusIonAnnotation annotation) {
  String formula = MolecularFormulaManipulator.getString(annotation.getFormula());
  String siriusScore = String.format("%.4f", annotation.getSiriusScore());
  String name = null;

  /* Put default properties */
  Hashtable<String, String> props = new Hashtable<>(10);
  props.put(PROPERTY_METHOD, "Sirius");
  props.put(PROPERTY_FORMULA, formula);
  props.put("Sirius score", siriusScore);

  /* Check that annotation is processed by FingerIdWebMethod */
  if (annotation.getFingerIdScore() != null) {
    name = annotation.getDescription();
    String inchi = annotation.getInchiKey();
    String smiles = annotation.getSMILES();

    props.put("SMILES", smiles);
    props.put("Inchi", inchi);
    String fingerScore = String.format("%.4f", annotation.getFingerIdScore());
    props.put("FingerId score", fingerScore);

    DBLink[] links = annotation.getDBLinks();
    Set<String> dbnames = new HashSet<>();

    /*
     * DBLinks may contain several links to Pubchem (for example)
     */
    for (DBLink link : links) {
      dbnames.add(link.name);
    }

    String[] dbs = new String[dbnames.size()];
    dbs = dbnames.toArray(dbs);
    for (String db : dbs)
      props.put(db, "FOUND");
  }

  // Load name param with formula, if FingerId did not identify it
  if (name == null)
    name = formula;
  props.put(PROPERTY_NAME, name);

  return props;
}
 
Example 18
private boolean checkTuCurrentMatch(VTDUtils vu, Vector<Hashtable<String, String>> tmMatch)
		throws XPathParseException, XPathEvalException, NavException {
	if (tmMatch.size() == 0) {
		return false;
	}
	Vector<Hashtable<String, String>> currentMatch = new Vector<Hashtable<String, String>>();
	vu.getVTDNav().push();
	AutoPilot ap = new AutoPilot(vu.getVTDNav());
	ap.selectXPath("./alt-trans[@tool-id='" + Constants.TM_TOOLID + "']");
	int existMatchCount = 0;
	while (ap.evalXPath() != -1) {
		Hashtable<String, String> altTrans = new Hashtable<String, String>();
		String quality = vu.getCurrentElementAttribut("match-quality", "0");
		String srcText = vu.getElementContent("./source");
		String tgtText = vu.getElementContent("./target");
		if (srcText != null && tgtText != null) {
			altTrans.put("srcText", srcText);
			altTrans.put("tgtText", tgtText);
		} else {
			continue;
		}

		if (!isDuplicated(tmMatch, altTrans)) {
			String content = vu.getElementFragment();
			altTrans.put("content", content);
			if (quality.endsWith("%")) {
				quality = quality.substring(0, quality.length() - 1);
			}
			altTrans.put("similarity", quality);
			altTrans.put("flag", "exist");
			currentMatch.add(altTrans);
		} else {
			existMatchCount++;
		}
	}
	vu.getVTDNav().pop();
	if (existMatchCount == tmMatch.size()) { // 库中查询的内容和文件中的内容是一样的
		return false;
	} else {
		tmMatch.addAll(currentMatch);
		Collections.sort(tmMatch, new FindMatchComparator());
		checkMaxMatchSize(tmMatch);
		return true;
	}
}
 
Example 19
public ReachableObjects(JavaHeapObject root,
                        final ReachableExcludes excludes) {
    this.root = root;

    final Hashtable<JavaHeapObject, JavaHeapObject> bag = new Hashtable<JavaHeapObject, JavaHeapObject>();
    final Hashtable<String, String> fieldsExcluded = new Hashtable<String, String>();  //Bag<String>
    final Hashtable<String, String> fieldsUsed = new Hashtable<String, String>();   // Bag<String>
    JavaHeapObjectVisitor visitor = new AbstractJavaHeapObjectVisitor() {
        public void visit(JavaHeapObject t) {
            // Size is zero for things like integer fields
            if (t != null && t.getSize() > 0 && bag.get(t) == null) {
                bag.put(t, t);
                t.visitReferencedObjects(this);
            }
        }

        public boolean mightExclude() {
            return excludes != null;
        }

        public boolean exclude(JavaClass clazz, JavaField f) {
            if (excludes == null) {
                return false;
            }
            String nm = clazz.getName() + "." + f.getName();
            if (excludes.isExcluded(nm)) {
                fieldsExcluded.put(nm, nm);
                return true;
            } else {
                fieldsUsed.put(nm, nm);
                return false;
            }
        }
    };
    // Put the closure of root and all objects reachable from root into
    // bag (depth first), but don't include root:
    visitor.visit(root);
    bag.remove(root);

    // Now grab the elements into a vector, and sort it in decreasing size
    JavaThing[] things = new JavaThing[bag.size()];
    int i = 0;
    for (Enumeration<JavaHeapObject> e = bag.elements(); e.hasMoreElements(); ) {
        things[i++] = (JavaThing) e.nextElement();
    }
    ArraySorter.sort(things, new Comparer() {
        public int compare(Object lhs, Object rhs) {
            JavaThing left = (JavaThing) lhs;
            JavaThing right = (JavaThing) rhs;
            long diff = right.getSize() - left.getSize();
            if (diff != 0) {
                return Long.signum(diff);
            }
            return left.compareTo(right);
        }
    });
    this.reachables = things;

    this.totalSize = root.getSize();
    for (i = 0; i < things.length; i++) {
        this.totalSize += things[i].getSize();
    }

    excludedFields = getElements(fieldsExcluded);
    usedFields = getElements(fieldsUsed);
}
 
Example 20
Source Project: lams   File: JmxUtils.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Append an additional key/value pair to an existing {@link ObjectName} with the key being
 * the static value {@code identity} and the value being the identity hash code of the
 * managed resource being exposed on the supplied {@link ObjectName}. This can be used to
 * provide a unique {@link ObjectName} for each distinct instance of a particular bean or
 * class. Useful when generating {@link ObjectName ObjectNames} at runtime for a set of
 * managed resources based on the template value supplied by a
 * {@link org.springframework.jmx.export.naming.ObjectNamingStrategy}.
 * @param objectName the original JMX ObjectName
 * @param managedResource the MBean instance
 * @return an ObjectName with the MBean identity added
 * @throws MalformedObjectNameException in case of an invalid object name specification
 * @see org.springframework.util.ObjectUtils#getIdentityHexString(Object)
 */
public static ObjectName appendIdentityToObjectName(ObjectName objectName, Object managedResource)
		throws MalformedObjectNameException {

	Hashtable<String, String> keyProperties = objectName.getKeyPropertyList();
	keyProperties.put(IDENTITY_OBJECT_NAME_KEY, ObjectUtils.getIdentityHexString(managedResource));
	return ObjectNameManager.getInstance(objectName.getDomain(), keyProperties);
}