📄 idset.java
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * . Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * . Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * . Neither the name of the "OpenWFE" nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: IdSet.java,v 1.2 2005/05/17 16:41:06 jmettraux Exp $ *///// IdSet.java//// john.mettraux@openwfe.org//// generated with // jtmpl 1.1.01 2004/05/19 (john.mettraux@openwfe.org)//package openwfe.org.xdbc.nquery;import openwfe.org.ReflectionUtils;import openwfe.org.query.sets.Set;/** * A set of Xdbc client ids. * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: IdSet.java,v 1.2 2005/05/17 16:41:06 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class IdSet implements Set{ /* private final static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(IdSet.class.getName()); */ // // CONSTANTS & co // // FIELDS private boolean negative = false; private java.util.Map content = new java.util.HashMap(); // // CONSTRUCTORS // // GETTERS and SETTERS public java.util.Map getContent () { return this.content; } public void setContent (final java.util.Map m) { this.content = m; } // // METHODS from openwfe.org.query.sets.Set public Object clone () { final IdSet result = new IdSet(); result.negative = this.negative; result.getContent().putAll(this.content); return result; } // // METHODS from java.util.Set public int size () { return this.content.size(); } public boolean contains (final Object o) { if (o instanceof Long) return this.content.keySet().contains(o); else if (o instanceof String) return this.content.entrySet().contains(o); throw new IllegalArgumentException ("contains() cannot argument of class "+o.getClass().getName()); } public Object[] toArray () { return this.content.entrySet().toArray(); } public Object[] toArray (final Object[] array) { return this.content.entrySet().toArray(array); } public boolean add (final Object o) { final Object os[] = (Object[])o; this.content.put(os[1], os[0]); return true; } public boolean remove (final Object o) { if (o instanceof Long) { return (this.content.remove(o) != null); } if ( ! (o instanceof String)) { throw new IllegalArgumentException ("remove() cannot proceed with an argument of class "+ o.getClass().getName()); } final java.util.Iterator it = this.content.entrySet().iterator(); while (it.hasNext()) { final java.util.Map.Entry e = (java.util.Map.Entry)it.next(); if (e.getValue().equals(o)) return (this.content.remove(e.getKey()) != null); } return false; } public java.util.Iterator iterator () { return this.content.keySet().iterator(); } public boolean containsAll (final java.util.Collection c) { return false; } public boolean addAll (final java.util.Collection c) { return false; } public boolean retainAll (final java.util.Collection c) { return false; } public boolean removeAll (final java.util.Collection c) { return false; } public void clear () { this.content.clear(); } public boolean isEmpty () { return this.content.isEmpty(); } // // METHODS from openwfe.org.query.sets.Set /** * Returns true if this set is negative (ie an inverted set). */ public boolean isNegative () { return this.negative; } /** * Returns true if the st is positive. */ public boolean isPositive () { return ! this.negative; } /** * Sets the positive/negative state of the set. */ public void setNegative (final boolean b) { this.negative = b; } /** * Inverts the state of the set. */ public void invert () { this.negative = ( ! this.negative); } /** * Returns a new (and positive) empty instance of this set. */ public Set newInstance () { return (Set)ReflectionUtils.newInstance(this); } // // METHODS public void add (final Long documentId, final String clientId) { this.content.put(documentId, clientId); } public void add (final long documentId, final String clientId) { this.content.put(new Long(documentId), clientId); } public String getClientId (long docId) { return getClientId(new Long(docId)); } public String getClientId (Long docId) { return (String)this.content.get(docId); } // // STATIC METHODS /** * Extracts document ids from an SQL result set. */ public static IdSet extractDocumentIds (final java.sql.ResultSet rs) throws java.sql.SQLException { final IdSet result = new IdSet(); while (rs.next()) result.add(new Long(rs.getLong(1)), rs.getString(2)); return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -