📄 utilities.java
字号:
package org.osu.ogsa.stream.util;import java.util.*;import java.lang.*;import org.osu.ogsa.stream.util.xmlconfig.*;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import javax.swing.tree.DefaultMutableTreeNode;public class Utilities { private static Log log = LogFactory.getLog(Utilities.class.getName()); public static String getIPAddress(String GSH) { String [] strArray = GSH.split(":"); if(strArray.length < 3) return null; //I.E. GSH = "http://localhost:8080/ogsa/services/Stream/StreamService" //strArray[1] = "//localhost" return strArray[1].substring(2); } public static int Biased_Coin(Random rand, double probability) { return Biased_Coin(rand, probability, 100); } public static int High_Precsion_Biased_Coin(Random rand, double probability) { double random1 = rand.nextDouble(); Double dRandom1 = new Double(random1); Double dRandom_Prob = new Double(probability); log.warn(random1 + "v.s." + probability); if(random1 < probability) return DefConstants.HEAD; else return DefConstants.TAIL; } public static int Biased_Coin(Random rand, double probability, int factor) { int rand_int = 1 + (Math.abs(rand.nextInt()) % factor ); log.debug("rand_int :"+ rand_int); if(rand_int <= (int)(probability* (double)factor)) return DefConstants.HEAD; else return DefConstants.TAIL; } public static int randnum(Random rand, int factor) { int rand_int = 1 + (Math.abs(rand.nextInt()) % factor ); return rand_int; } public static int randnum(Random rand, int factor1, int factor2) { int min, max; if(factor1 > factor2) { min = factor2; max = factor1; } else { min = factor1; max = factor2; } int interval = max - min + 1; int rand_int = 1 + (Math.abs(rand.nextInt()) % interval); rand_int += min; return rand_int; } public static void constructTree(Hashtable hashTree) { String places[] = null; String strNextConnection = null;; int nSourcePlacements = ((Integer)XMLConfigurator.getParameter("stages|stage1|numPlacements")).intValue(); int nstage, nplacement; DefaultMutableTreeNode treenode, parent, root; int numStages = ((Integer)XMLConfigurator.getParameter("numStages")).intValue(); String strFinalStagePlacement = "stage" + numStages + ":placement1"; nstage = 1; nplacement = 1; treenode = parent = root = null; for(int i = 1; i <= nSourcePlacements; i ++) { nplacement = i; nstage = 1; treenode = new DefaultMutableTreeNode(new Integer(1)); hashTree.put("stage1:placement"+i, treenode); do{ log.debug("stage"+nstage+":placement"+nplacement); //Get the next stage's placement strNextConnection = (String)XMLConfigurator.getParameter("stages|stage" + nstage +"|connection" + nplacement); log.debug(strNextConnection); if(hashTree.containsKey(strNextConnection)) { parent = (DefaultMutableTreeNode)hashTree.get(strNextConnection); parent.add(treenode); treenode.setUserObject(new Integer(parent.getChildCount())); break; } else { parent = new DefaultMutableTreeNode(new Integer(1)); parent.add(treenode); hashTree.put(strNextConnection, parent); treenode = parent; //change nstage and nplacement places = strNextConnection.split(":"); nstage = Integer.parseInt(places[0].substring(5)); //the length of "placement" is 9 nplacement = Integer.parseInt(places[1].substring(9)); //the length of "placement" is 9 } //log.debug(treenode); //log.debug(parent); }while(!strNextConnection.equals(strFinalStagePlacement)); if(strNextConnection.equals(strFinalStagePlacement)) root = parent; } //Debug DefaultMutableTreeNode node; for (Enumeration e = root.breadthFirstEnumeration() ; e.hasMoreElements() ;) { node = (DefaultMutableTreeNode)e.nextElement();// System.out.println(((Integer)(node.getUserObject())).intValue()); log.debug(" " + ((Integer)(node.getUserObject())).intValue()); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -