/** * Adds a <CODE>PdfObject</CODE> and its key to the <CODE>PdfDictionary</CODE>. * If the value is null the key is deleted. * * @param key key of the entry (a <CODE>PdfName</CODE>) * @param value value of the entry (a <CODE>PdfObject</CODE>) * @return the previous </CODE>PdfObject</CODE> corresponding with the <VAR>key</VAR> */ public PdfObject putDel(PdfName key, PdfObject value) { PdfObject retVal = null; if (value == null) { retVal = (PdfObject)hashMap[key]; hashMap.Remove(key); return(retVal); } hashMap.Add(key, value); return(value); }
public void Remove(string key) { try { _keys.Remove(key); } catch (Exception) { throw; } }
public void TestHashmapForInts() { var map = new Hashmap <int, int>(numValues); for (int i = 0; i < numValues; i++) { map.Add(i, i); } for (int i = 0; i < numValues; i++) { Assert.AreEqual(i, map.Get(i)); } for (int i = 0; i < numValues; i++) { map.Remove(i); } Assert.AreEqual(0, map.Count); }
public void TestHashmapForStrings() { var map = new Hashmap <string, string>(numValues); for (int i = 0; i < numValues; i++) { var tmp = i + string.Empty; map.Add(tmp, tmp); } for (int i = 0; i < numValues; i++) { var tmp = i + string.Empty; Assert.AreEqual(tmp, map.Get(tmp)); } for (int i = 0; i < numValues; i++) { var tmp = i + string.Empty; map.Remove(tmp); } Assert.AreEqual(0, map.Count); }
/** * Truncates this <CODE>PdfChunk</CODE> if it's too long for the given width. * <P> * Returns <VAR>null</VAR> if the <CODE>PdfChunk</CODE> wasn't truncated. * * @param width a given width * @return the <CODE>PdfChunk</CODE> that doesn't fit into the width. */ internal PdfChunk truncate(float width) { if (image != null) { if (image.ScaledWidth > width) { PdfChunk pc = new PdfChunk("", this); value = ""; attributes.Remove(Chunk.IMAGE); image = null; font = new PdfFont(PdfFont.HELVETICA, 12); return(pc); } else { return(null); } } int currentPosition = 0; float currentWidth = 0; // it's no use trying to split if there isn't even enough place for a space if (width < font.Width) { string returnValue = value.Substring(1); value = value.Substring(0, 1); PdfChunk pc = new PdfChunk(returnValue, this); return(pc); } // loop over all the characters of a string // or until the totalWidth is reached int length = value.Length; char character; while (currentPosition < length) { // the width of every character is added to the currentWidth character = value[currentPosition]; currentWidth += font.width(character); if (currentWidth > width) { break; } currentPosition++; } // if all the characters fit in the total width, null is returned (there is no overflow) if (currentPosition == length) { return(null); } // otherwise, the string has to be truncated //currentPosition -= 2; // we have to chop off minimum 1 character from the chunk if (currentPosition == 0) { currentPosition = 1; } string retVal = value.Substring(currentPosition); value = value.Substring(0, currentPosition); PdfChunk tmp = new PdfChunk(retVal, this); return(tmp); }