⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wipool.java

📁 与postgresql数据库结合的数据库水印软件包
💻 JAVA
字号:
/* *  * Copyright 2003,2004 The Watermill Team * * This file is part of Watermill. * *    Watermill is free software; you can redistribute it and/or modify *    it under the terms of the GNU General Public License as published by *    the Free Software Foundation; either version 2 of the License, or *    (at your option) any later version. * *    Watermill is distributed in the hope that it will be useful, *    but WITHOUT ANY WARRANTY; without even the implied warranty of *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *    GNU General Public License for more details. * *    You should have received a copy of the GNU General Public License *    along with Watermill; if not, write to the Free Software *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * */package Watermill.kernel;import java.io.*;import java.util.*;public class WIPool extends Pool implements Serializable {    /** A Precompiled pool for weight independent queries **/    public Identifiers identifiers;    public DependencyMatrix depMatrix;    public HashMap classes=new HashMap();    public Pairs pairs=new Pairs();    public WIPool(String ipn,Document id,WSchema iws){	super(ipn,id,iws);	identifiers=id.getModifiableValuesIdentifiers(wschema.getLocalConstraints());	Msg.verbose("Identifiers:"+identifiers.toString());			depMatrix=id.getDependency(wschema.getGlobalConstraints());	Msg.verbose("DepMatrix:"+depMatrix.toString());	reductMatrix(1,2);	Msg.debug("Warning : constant maxlocal=1 and minglobal=2 in reductmatrix");	computeMap();	Msg.verbose("Classes:"+classes.toString());	computePairs();	Msg.verbose("Pairs:"+pairs.toString());    }    public void reductMatrix(int maxLocal,int minGlobal){	if (depMatrix.size()<=1) return; // nothing to do	DependencyMatrix dep=(DependencyMatrix)depMatrix.clone();	int currentPos=-1;	int targetPos;	do {	    currentPos++;	    targetPos=currentPos;	    	    Identifiers current=(Identifiers)dep.get(currentPos);	    Identifiers target;	    do {		targetPos++;		Msg.verbose("positions:"+currentPos+","+targetPos);		target=(Identifiers)dep.get(targetPos);				if (delta(current,target)*maxLocal<=minGlobal){		    Msg.verbose("Dependency "+currentPos+":"+current+"  and "+targetPos+":"+target+" are similar");		    Msg.verbose("Removing "+targetPos);		    dep.remove(targetPos);		}	    }while((targetPos+1<dep.size()));	}while(currentPos+2<dep.size());	depMatrix=dep;    }    public int delta(Identifiers a,Identifiers b){	int res=0;	for(Enumeration e=a.elements();e.hasMoreElements();){	    Identifier i=(Identifier)e.nextElement();	    if (!(b.contains(i)))		res++;	}	for(Enumeration e=b.elements();e.hasMoreElements();){	    Identifier i=(Identifier)e.nextElement();	    if (!(a.contains(i)))		res++;	}	return res;    }    public boolean anyInclusion(Set a,Set b){	return ((a.containsAll(b))||(b.containsAll(a)));    }    public void computePairs(){	Identifiers ids=(Identifiers)identifiers.clone();	Msg.verbose("computePairs : "+ids.toString());	while(ids.size()>1) {	    Msg.verbose("Current size "+ids.size());	    int currentPos=0,targetPos=0;	    Identifier current=(Identifier)ids.get(currentPos);	    Identifier target;	    do {		targetPos++;		Msg.verbose("positions:"+currentPos+","+targetPos);		target=(Identifier)ids.get(targetPos);	    }while((targetPos+1<ids.size())&&!(classes.get(current).equals(classes.get(target))));	    	    if (targetPos+1<ids.size()){		pairs.add(new Pair(current,target));		Msg.verbose("adding "+currentPos+","+targetPos);		Msg.verbose("Removing "+targetPos);		ids.remove(targetPos);	    }	    Msg.verbose("Removing "+currentPos);	    ids.remove(currentPos);	    	}    }    public void computeMap(){	for(Enumeration e=identifiers.elements();e.hasMoreElements();){	    Identifier id=(Identifier)e.nextElement();	    Msg.verbose("Looking queries depending on "+id.toString());	    int i=0;	    for(Enumeration e2=depMatrix.elements();e2.hasMoreElements();i++){		Identifiers dep=(Identifiers)e2.nextElement();		int pos=dep.indexOf(id);		if(pos==-1)		    Msg.verbose("no match !");		if (pos!=-1){		    HashSet s=(HashSet)classes.get(id);		    if (s==null){			s=new HashSet();			s.add(new Integer(i));			classes.put(id,s);		    }		    else {			s.add(new Integer(i));			classes.put(id,s);		    }		}	    }	}    }    public Watermark watermark(Document doc,int seed){	Random r=new Random(seed);	Watermark res=new Watermark();	Msg.verbose("Watermark");	Msg.verbose("Pairs : "+pairs.toString());	for(Enumeration e=pairs.elements();e.hasMoreElements();){	    Pair p=(Pair)e.nextElement();	    Msg.verbose("watermarking in pair "+p.toString());	    boolean b=r.nextBoolean();	    int d=p.first.maxDistortion;	    if (p.second.maxDistortion<d)		d=p.second.maxDistortion;	    if (b) 		d=-d;	    res.put(p.first,new Value(d));	    res.put(p.second,new Value(-d));	    doc.addValue(p.first,new Value(d));	    doc.addValue(p.second,new Value(-d));	}	return res;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -