Java Code Examples for java.util.Hashtable.entrySet()

The following are Jave code examples for showing how to use entrySet() of the java.util.Hashtable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: CopyTemplatePageTask.java   View Source Code Vote up 6 votes
public String call() throws Exception {
    final StringBuilder sb = new StringBuilder();
    final Pattern p = Pattern.compile(Pattern.quote(prefix) + "\\.(\\d+)\\." + Pattern.quote(key)); //NOI18N

    final Hashtable<String,Object> props = getProject().getProperties();
    for (Map.Entry<String,Object> entry : props.entrySet()) {
        Matcher m = p.matcher(entry.getKey());
        if (m.matches()) {
            final String kv = (String) entry.getValue();
            final String valueKey = prefix + '.'+ m.group(1) +'.' + value;  //NOI18N
            final String vv = getProperty(valueKey, ""); //NOI18N
            addProperty(sb,kv,vv);
        }
    }
    for (Map.Entry<String,String> prop : additionalProps.entrySet()) {
        addProperty(sb, prop.getKey(), getProperty(prop.getValue(), "")); //NOI18N
    }
    return sb.toString();
}
 
Example 2
Project: ramus   File: MainFrame.java   View Source Code Vote up 6 votes
private void loadData() {
    data.clear();
    ArrayList<Attribute> attrs = new ArrayList<Attribute>();
    for (Attribute attribute : ATTRIBUTES)
        attrs.add(attribute);
    // We can use engine.getAttribute(Element, Attribute) method to cat all
    // attributes, but this method works match faster for a set of elements.
    Hashtable<Element, Object[]> hash = engine.getElements(engine
            .getSystemQualifier(Application.QUALIFIER1), attrs);
    for (Entry<Element, Object[]> entry : hash.entrySet()) {
        data.add(new Row(entry.getKey(), entry.getValue()));
    }
    Collections.sort(data, new Comparator<Row>() {

        @Override
        public int compare(Row o1, Row o2) {
            if (o1.element.getId() < o2.element.getId())
                return -1;
            if (o2.element.getId() < o1.element.getId())
                return 1;
            return 0;
        }
    });
}
 
Example 3
Project: ramus   File: QualifierImporterImpl.java   View Source Code Vote up 6 votes
private void setupTableElements() {
    List<Attribute> attributes = new ArrayList<Attribute>(1);
    attributes.add(StandardAttributesPlugin
            .getTableElementIdAttribute(source));
    Attribute toSet = StandardAttributesPlugin
            .getTableElementIdAttribute(engine);
    for (Qualifier q : tableSourceQualifiers) {
        Hashtable<Element, Object[]> table = source.getElements(q,
                attributes);
        for (Entry<Element, Object[]> entry : table.entrySet()) {
            Long l = (Long) entry.getValue()[0];
            if (l != null) {
                Element s = source.getElement(l);
                Element d = getDestination(s);
                if (d != null) {
                    Element dest = getDestination(entry.getKey());
                    engine.setAttribute(dest, toSet, d.getId());
                }
            }
        }
    }
}
 
Example 4
Project: ramus   File: CachedEngine.java   View Source Code Vote up 6 votes
private CachedQualifier loadQualifier(Long id) {
    CachedQualifier q = new CachedQualifier();
    q.qualifier = deligate.getQualifier(id);
    if (q.qualifier == null)
        return null;
    List<Attribute> attributes = q.buildAttributes();
    q.setAllAttributes(attributes.toArray(new Attribute[attributes.size()]));
    Hashtable<Element, Object[]> hashtable = deligate.getElements(
            q.qualifier, attributes);
    List<CachedElement> elements = q.elements;
    for (Entry<Element, Object[]> entry : hashtable.entrySet()) {
        Element key = entry.getKey();
        CachedElement e = new CachedElement(key, entry.getValue(), q);
        elements.add(e);
        this.elements.put(key.getId(), e);
    }
    return q;
}
 
Example 5
Project: ramus   File: UpdateQualifierCommand.java   View Source Code Vote up 6 votes
public UpdateQualifierCommand(JournaledEngine engine,
                              Qualifier oldQualifier, Qualifier newQualifier) {
    super(engine);
    this.oldQualifier = oldQualifier;
    this.newQualifier = newQualifier;
    initDeletedAttributes();
    for (Attribute attribute : deletedAttributes) {
        Hashtable<Element, Transaction> t = engine
                .getAttributeWhatWillBeDeleted(oldQualifier.getId(),
                        attribute.getId());
        Hashtable<Long, Transaction> put = new Hashtable<Long, Transaction>();
        hashtable.put(attribute.getId(), put);
        for (Entry<Element, Transaction> entry : t.entrySet()) {
            put.put(entry.getKey().getId(), entry.getValue());
        }
    }
}
 
Example 6
Project: ramus   File: UpdateQualifierCommand.java   View Source Code Vote up 6 votes
@Override
public void writeBody(BinaryDataOutput output) throws IOException {
    storeQualifier(output, oldQualifier);
    storeQualifier(output, newQualifier);
    for (Attribute attribute : deletedAttributes) {
        Hashtable<Long, Transaction> hash = hashtable
                .get(attribute.getId());
        output.writeInt(hash.size());
        for (Entry<Long, Transaction> entry : hash.entrySet()) {
            output.writeLong(entry.getKey());
            output.writeInt(entry.getValue().getDelete().size());
            for (Persistent p : entry.getValue().getDelete()) {
                TransactionStorageCommand
                        .storePersistent(engine, output, p);
            }
        }
    }
}
 
Example 7
Project: ramus   File: AbstractJournaledEngine.java   View Source Code Vote up 6 votes
private Hashtable<Element, Object[]> convert(
        Hashtable<Element, List<Persistent>[][]> res,
        List<Attribute> attributes) {
    AttributeConverter[] converters = new AttributeConverter[attributes
            .size()];
    for (int i = 0; i < converters.length; i++) {
        converters[i] = pluginFactory.getAttributeConverter(attributes.get(
                i).getAttributeType());
    }
    Hashtable<Element, Object[]> hashtable = new Hashtable<Element, Object[]>();
    for (Entry<Element, List<Persistent>[][]> entry : res.entrySet()) {
        Object[] objects = new Object[converters.length];
        for (int i = 0; i < objects.length; i++) {
            objects[i] = converters[i].toObject(entry.getValue()[i], entry
                    .getKey().getId(), attributes.get(i).getId(), this);
        }

        hashtable.put(entry.getKey(), objects);
    }
    return hashtable;
}
 
Example 8
Project: openjdk-jdk10   File: VetoableChangeSupport.java   View Source Code Vote up 6 votes
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new VetoableChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, VetoableChangeSupport> children = (Hashtable<String, VetoableChangeSupport>)fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("vetoableChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (VetoableChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, VetoableChangeSupport> entry : children.entrySet()) {
            for (VetoableChangeListener listener : entry.getValue().getVetoableChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 9
Project: openjdk-jdk10   File: PropertyChangeSupport.java   View Source Code Vote up 6 votes
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new PropertyChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("propertyChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (PropertyChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
            for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 10
Project: OpenJSharp   File: PropertyChangeSupport.java   View Source Code Vote up 6 votes
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new PropertyChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("propertyChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (PropertyChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
            for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 11
Project: monarch   File: DataSerializer.java   View Source Code Vote up 6 votes
/**
 * Writes a <code>Hashtable</code> to a <code>DataOutput</code>. Note that even though
 * <code>map</code> may be an instance of a subclass of <code>Hashtable</code>,
 * <code>readHashtable</code> will always return an instance of <code>Hashtable</code>, <B>not</B>
 * an instance of the subclass. To preserve the class type of <code>map</code>,
 * {@link #writeObject(Object, DataOutput)} should be used for data serialization.
 *
 * @throws IOException A problem occurs while writing to <code>out</code>
 *
 * @see #readHashtable
 * @since GemFire 5.7
 */
public static void writeHashtable(Hashtable<?, ?> map, DataOutput out) throws IOException {

  InternalDataSerializer.checkOut(out);

  int size;
  if (map == null) {
    size = -1;
  } else {
    size = map.size();
  }
  InternalDataSerializer.writeArrayLength(size, out);
  if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
    logger.trace(LogMarker.SERIALIZER, "Writing Hashtable with {} elements: {}", size, map);
  }
  if (size > 0) {
    for (Map.Entry<?, ?> entry : map.entrySet()) {
      writeObject(entry.getKey(), out);
      writeObject(entry.getValue(), out);
    }
  }
}
 
Example 12
Project: ChronoBike   File: BMSTranscoderEngine.java   View Source Code Vote up 6 votes
private void addTagForClosingHBox(Hashtable<String, PosLineCol> hashPosLineColByLanguage, Hashtable<String, CMapElement> hashMapsByLanguage)
{
	// Enum all Maps in every language and add the item into the map
	Set<Entry<String, CMapElement> > set = hashMapsByLanguage.entrySet();
	Iterator<Entry<String, CMapElement> > iter = set.iterator();
	while(iter.hasNext())
	{
		Entry<String, CMapElement> entry = iter.next();
		String csLg = entry.getKey();
		CMapElement eMap = entry.getValue();
		PosLineCol posLineCol = hashPosLineColByLanguage.get(csLg);

		CFieldElement eField = new CFieldElement("", 0);
		boolean bAdd = eField.setAsClosingHBox(posLineCol);
		if(bAdd)
			eMap.AddElement(eField);
	}
}
 
Example 13
Project: openjdk-jdk10   File: AttributeValues.java   View Source Code Vote up 6 votes
public static AttributeValues
fromSerializableHashtable(Hashtable<Object, Object> ht)
{
    AttributeValues result = new AttributeValues();
    if (ht != null && !ht.isEmpty()) {
        for (Map.Entry<Object, Object> e: ht.entrySet()) {
            Object key = e.getKey();
            Object val = e.getValue();
            if (key.equals(DEFINED_KEY)) {
                result.defineAll(((Integer)val).intValue());
            } else {
                try {
                    EAttribute ea =
                        EAttribute.forAttribute((Attribute)key);
                    if (ea != null) {
                        result.set(ea, val);
                    }
                }
                catch (ClassCastException ex) {
                }
            }
        }
    }
    return result;
}
 
Example 14
Project: weixin_api   File: SHA1.java   View Source Code Vote up 5 votes
/**
 * 用SHA1算法生成URL参数安全签名
 * 
 * @param params
 *            参数表key,value
 * @return 安全签名
 * @throws AesException
 */
public static String getSHA1(Hashtable<String, Object> params) throws AesException {
	try {
		int size = params.size();
		String[] array = new String[size];
		int pos = 0;
		for (Entry<String, Object> param : params.entrySet()) {
			array[pos] = String.format("%s=%s", param.getKey(), param.getValue());
			pos++;
		}
		StringBuffer sb = new StringBuffer(2048);
		// 字符串排序
		Arrays.sort(array);
		for (int i = 0; i < array.length; i++) {
			if (i != 0) {
				sb.append("&");
			}
			sb.append(array[i]);
		}
		String str = sb.toString();
		// SHA1签名生成
		MessageDigest md = MessageDigest.getInstance("SHA-1");
		md.update(str.getBytes());
		byte[] digest = md.digest();

		StringBuffer hexstr = new StringBuffer(64);
		String shaHex = "";
		for (int i = 0; i < digest.length; i++) {
			shaHex = Integer.toHexString(digest[i] & 0xFF);
			if (shaHex.length() < 2) {
				hexstr.append(0);
			}
			hexstr.append(shaHex);
		}
		return hexstr.toString();
	} catch (Exception e) {
		e.printStackTrace();
		throw new AesException(AesException.ComputeSignatureError);
	}
}
 
Example 15
Project: unitimes   File: ExpireReservationsAction.java   View Source Code Vote up 5 votes
@Override
public Boolean execute(OnlineSectioningServer server, OnlineSectioningHelper helper) {
	helper.beginTransaction();
	try {
		helper.info("Checking for expired reservations..."); 
		Hashtable<XOffering, List<XReservation>> reservations2expire = new Hashtable<XOffering, List<XReservation>>();
		for (org.unitime.timetable.model.Reservation expiredReservation: (List<org.unitime.timetable.model.Reservation>)helper.getHibSession().createQuery(
				"select r from Reservation r where " +
				"r.instructionalOffering.session.uniqueId = :sessionId and " +
				"r.expirationDate is not null and r.expirationDate < current_timestamp()")
				.setLong("sessionId", server.getAcademicSession().getUniqueId()).list()) {
			XOffering offering = server.getOffering(expiredReservation.getInstructionalOffering().getUniqueId());
			if (offering == null) continue;
			XReservation reservation = null;
			for (XReservation r: offering.getReservations())
				if (r.getReservationId().equals(expiredReservation.getUniqueId())) { reservation = r; break; }
			if (reservation == null || reservation.isExpired()) continue; // already expired
			List<XReservation> reservations = reservations2expire.get(offering);
			if (reservations == null) {
				reservations = new ArrayList<XReservation>();
				reservations2expire.put(offering, reservations);
			}
			reservations.add(reservation);
		}
		helper.commitTransaction();
		for (Map.Entry<XOffering, List<XReservation>> entry: reservations2expire.entrySet()) {
			expireReservation(entry.getKey(), entry.getValue(), server, helper);
		}
	} catch (Exception e) {
		helper.rollbackTransaction();
		if (e instanceof SectioningException)
			throw (SectioningException)e;
		throw new SectioningException(MSG.exceptionUnknown(e.getMessage()), e);
	}
	return true;
}
 
Example 16
Project: unitimes   File: MakeCurriculaFromLastlikeDemands.java   View Source Code Vote up 5 votes
public String getLeadingClassificationName() {
	Hashtable<String, int[]> cnt = getClassifications();
	String best = null;
	int bestValue = 0;
	for (Map.Entry<String, int[]> e: cnt.entrySet()) {
		if (e.getValue()[0] > bestValue) {
			bestValue = e.getValue()[0];
			best = e.getKey();
		}
	}
	return best;
}
 
Example 17
Project: openjdk-jdk10   File: SimpleSerialization.java   View Source Code Vote up 5 votes
public static void main(final String[] args) throws Exception {
    Hashtable<String, String> h1 = new Hashtable<>();

    System.err.println("*** BEGIN TEST ***");

    h1.put("key", "value");

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
        oos.writeObject(h1);
    }

    final byte[] data = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(data);
    final Object deserializedObject;
    try (ObjectInputStream ois = new ObjectInputStream(bais)) {
        deserializedObject = ois.readObject();
    }

    if(!h1.getClass().isInstance(deserializedObject)) {
         throw new RuntimeException("Result not assignable to type of h1");
    }

    if (false == h1.equals(deserializedObject)) {
         Hashtable<String, String> d1 = (Hashtable<String, String>) h1;
        for(Map.Entry entry: h1.entrySet()) {
            System.err.println("h1.key::" + entry.getKey() + " d1.containsKey()::" + d1.containsKey((String) entry.getKey()));
            System.err.println("h1.value::" + entry.getValue() + " d1.contains()::" + d1.contains(entry.getValue()));
            System.err.println("h1.value == d1.value " + entry.getValue().equals(d1.get((String) entry.getKey())));
        }

        throw new RuntimeException(getFailureText(h1, deserializedObject));
    }
}
 
Example 18
Project: TextStats   File: Main.java   View Source Code Vote up 5 votes
public static ArrayList<Map.Entry<String, Integer>> sortValue(Hashtable<String, Integer> t){
    ArrayList<Map.Entry<String, Integer>> l = new ArrayList( t.entrySet() );
    Collections.sort(l, new Comparator<Map.Entry<String, Integer>>(){
        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o2.getValue().compareTo(o1.getValue());
    }});

    return l;
}
 
Example 19
Project: jdk8u-jdk   File: SimpleSerialization.java   View Source Code Vote up 5 votes
public static void main(final String[] args) throws Exception {
    Hashtable<String, String> h1 = new Hashtable<>();

    System.err.println("*** BEGIN TEST ***");

    h1.put("key", "value");

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
        oos.writeObject(h1);
    }

    final byte[] data = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(data);
    final Object deserializedObject;
    try (ObjectInputStream ois = new ObjectInputStream(bais)) {
        deserializedObject = ois.readObject();
    }

    if(!h1.getClass().isInstance(deserializedObject)) {
         throw new RuntimeException("Result not assignable to type of h1");
    }

    if (false == h1.equals(deserializedObject)) {
         Hashtable<String, String> d1 = (Hashtable<String, String>) h1;
        for(Map.Entry entry: h1.entrySet()) {
            System.err.println("h1.key::" + entry.getKey() + " d1.containsKey()::" + d1.containsKey((String) entry.getKey()));
            System.err.println("h1.value::" + entry.getValue() + " d1.contains()::" + d1.contains(entry.getValue()));
            System.err.println("h1.value == d1.value " + entry.getValue().equals(d1.get((String) entry.getKey())));
        }

        throw new RuntimeException(getFailureText(h1, deserializedObject));
    }
}
 
Example 20
Project: openjdk-jdk10   File: CoreDocumentImpl.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    docType = (DocumentTypeImpl)gf.get("docType", null);
    docElement = (ElementImpl)gf.get("docElement", null);
    fFreeNLCache = (NodeListCache)gf.get("fFreeNLCache", null);
    encoding = (String)gf.get("encoding", null);
    actualEncoding = (String)gf.get("actualEncoding", null);
    version = (String)gf.get("version", null);
    standalone = gf.get("standalone", false);
    fDocumentURI = (String)gf.get("fDocumentURI", null);

    //userData is the original name. It has been changed to nodeUserData, refer to the corrsponding @serialField
    Hashtable<Node, Hashtable<String, UserDataRecord>> nud =
            (Hashtable<Node, Hashtable<String, UserDataRecord>>)gf.get("userData", null);

    Hashtable<String, Node> ids = (Hashtable<String, Node>)gf.get("identifiers", null);

    changes = gf.get("changes", 0);
    allowGrammarAccess = gf.get("allowGrammarAccess", false);
    errorChecking = gf.get("errorChecking", true);
    ancestorChecking = gf.get("ancestorChecking", true);
    xmlVersionChanged = gf.get("xmlVersionChanged", false);
    documentNumber = gf.get("documentNumber", 0);
    nodeCounter = gf.get("nodeCounter", 0);

    Hashtable<Node, Integer> nt = (Hashtable<Node, Integer>)gf.get("nodeTable", null);

    xml11Version = gf.get("xml11Version", false);

    //convert Hashtables back to HashMaps
    if (nud != null) {
        nodeUserData = new HashMap<>();
        for (Map.Entry<Node, Hashtable<String, UserDataRecord>> e : nud.entrySet()) {
            nodeUserData.put(e.getKey(), new HashMap<>(e.getValue()));
        }
    }

    if (ids != null) identifiers = new HashMap<>(ids);
    if (nt != null) nodeTable = new HashMap<>(nt);
}