/** * Returns a map with variable bindings. * * @param opts main options * @return bindings */ public static HashMap<String, String> bindings(final MainOptions opts) { final HashMap<String, String> bindings = new HashMap<>(); final String bind = opts.get(MainOptions.BINDINGS).trim(); final StringBuilder key = new StringBuilder(); final StringBuilder val = new StringBuilder(); boolean first = true; final int sl = bind.length(); for (int s = 0; s < sl; s++) { final char ch = bind.charAt(s); if (first) { if (ch == '=') { first = false; } else { key.append(ch); } } else { if (ch == ',') { if (s + 1 == sl || bind.charAt(s + 1) != ',') { bindings.put(key.toString().trim(), val.toString()); key.setLength(0); val.setLength(0); first = true; continue; } // literal commas are escaped by a second comma s++; } val.append(ch); } } if (key.length() != 0) bindings.put(key.toString().trim(), val.toString()); return bindings; }
public Monster getMostAggroInPanel(Point p) { Monster monster = null; Monster mostAggroMonster = null; double mostAggro = 0; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { if (monster.getIsInPanel()) { double distance = p.distance(monster.getCenterPoint()); if (monster.getPlayerDamage() > mostAggro) { mostAggroMonster = monster; mostAggro = monster.getPlayerDamage(); } } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return mostAggroMonster; }
public static String getResTxtContent(ClassLoader cl, String p) throws IOException { String s = res2txt_cont.get(p); if (s != null) return s; InputStream is = null; try { is = cl.getResourceAsStream(p); // is = this.getClass().getResourceAsStream(p); if (is == null) return null; byte[] buf = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len; while ((len = is.read(buf)) >= 0) { baos.write(buf, 0, len); } byte[] cont = baos.toByteArray(); s = new String(cont, "UTF-8"); res2txt_cont.put(p, s); return s; } finally { if (is != null) is.close(); } }
/** * Sets an application attribute. * * @param name the name of the attribute * @param value the value of the attribute */ public void setAttribute(String name, Object value) { Object oldValue; synchronized (_attributes) { if (value != null) oldValue = _attributes.put(name, value); else oldValue = _attributes.remove(name); } // Call any listeners if (_applicationAttributeListeners != null) { ServletContextAttributeEvent event; if (oldValue != null) event = new ServletContextAttributeEvent(this, name, oldValue); else event = new ServletContextAttributeEvent(this, name, value); for (int i = 0; i < _applicationAttributeListeners.size(); i++) { ServletContextAttributeListener listener; Object objListener = _applicationAttributeListeners.get(i); listener = (ServletContextAttributeListener) objListener; try { if (oldValue != null) listener.attributeReplaced(event); else listener.attributeAdded(event); } catch (Exception e) { log.log(Level.FINE, e.toString(), e); } } } }
/** * Returns an icon for the specified file. * * @param file file reference * @return icon */ public static Icon file(final IOFile file) { if (file == null) return UNKNOWN; // fallback code for displaying icons final String path = file.path(); final MediaType type = MediaType.get(path); if (type.isXML()) return XML; if (type.isXQuery()) return XQUERY; if (path.contains(IO.BASEXSUFFIX)) return BASEX; // only works with standard dpi (https://bugs.openjdk.java.net/browse/JDK-6817929) if (Prop.WIN && !GUIConstants.large()) { // retrieve system icons (only supported on Windows) final int p = path.lastIndexOf(path, '.'); final String suffix = p == -1 ? null : path.substring(p + 1); Icon icon = null; if (suffix != null) icon = FILES.get(suffix); if (icon == null) { icon = FS.getSystemIcon(file.file()); if (suffix != null) FILES.put(suffix, icon); } return icon; } // default icon chooser return type.isText() ? TEXT : UNKNOWN; }
public void setButtonDefs() { // Preconditions: words is initialized, preloaded is initialized. // Postconditions: definitions of words are added onto the radio buttons. // Sets the buttons to be set to random definitions from the preloaded list. // Making sure to not load the same definitions. Random rnd = new Random(); HashMap duplicates = new HashMap(5); String[] defs = new String[4]; // Mastery Factor: Implementing an ADT // Uses a Hash Map to check for duplicates amongst the options. duplicates.add(words[current].getDefinition()); for (int i = 0; i < 4; i++) { String def = preload[rnd.nextInt(PRELOADEDWORDS)].getDefinition(); while (duplicates.contains(def)) { def = preload[rnd.nextInt(PRELOADEDWORDS)].getDefinition(); } duplicates.add(def); defs[i] = def; } aRadBtn.setText(defs[0]); bRadBtn.setText(defs[1]); cRadBtn.setText(defs[2]); dRadBtn.setText(defs[3]); }
@Override public void reduce(Text key, Iterable<HMapStIW> values, Context context) throws IOException, InterruptedException { Iterator<HMapStIW> iter = values.iterator(); HMapStIW map = new HMapStIW(); while (iter.hasNext()) { map.plus(iter.next()); } HMapStFW writeMap = new HMapStFW(); double pmi = 0.0; for (MapKI.Entry<String> entry : map.entrySet()) { String k = entry.getKey(); if (map.get(k) >= 10) { if (wordCounts.containsKey(key.toString()) && wordCounts.containsKey(k)) { int px = wordCounts.get(key.toString()); int py = wordCounts.get(k); pmi = Math.log10(((double) (map.get(k)) / (px * py)) * wordCounts.get("numLines*")); writeMap.put(k, (float) pmi); } } } if (writeMap.size() > 0) { context.write(key, writeMap); } }
/** * Compares this LTS to another for debugging purposes. * * @param other the other LTS to compare to * @return <code>true</code> if these are equivalent */ public boolean compare(LetterToSound other) { // compare letter index table // for (Iterator i = letterIndex.keySet().iterator(); i.hasNext(); ) { String key = (String) i.next(); Integer thisIndex = (Integer) letterIndex.get(key); Integer otherIndex = (Integer) other.letterIndex.get(key); if (!thisIndex.equals(otherIndex)) { if (RiTa.PRINT_LTS_INFO) System.err.println("[WARN] LTSengine -> Bad index: " + key); return false; } } // compare states // for (int i = 0; i < stateMachine.length; i++) { State state = getState(i); State otherState = other.getState(i); if (!state.compare(otherState)) { if (RiTa.PRINT_LTS_INFO) System.err.println("[WARN] LTSengine -> Bad state: " + i); return false; } } return true; }
/* Retorna um Map com os utilizadores existentes no sistema */ public HashMap<String, User> getUsers() { HashMap<String, User> r = new HashMap<>(); for (Map.Entry<String, User> entry : users.entrySet()) { r.put(entry.getKey(), entry.getValue()); } return r; }
/** * Construct the <code>BufferedImage</code> from the given file. The file can be given as an URL, * or a reference to local image file. If this image has been loaded already, use the saved * version. * * @param filename the file name for the desired image */ public ImageMaker(String filename) { /** now we set up the image file for the user to process */ try { this.inputfile = new File(filename); String abs = inputfile.getCanonicalPath(); if (loadedImages.containsKey(abs)) { this.image = loadedImages.get(abs); this.width = this.image.getWidth(); this.height = this.image.getHeight(); } else { this.imageSource = ImageIO.read(this.inputfile); this.width = this.imageSource.getWidth(); this.height = this.imageSource.getHeight(); this.cmodel = this.imageSource.getColorModel(); this.image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB); this.colorOp = new ColorConvertOp( this.cmodel.getColorSpace(), image.getColorModel().getColorSpace(), null); this.colorOp.filter(this.imageSource, this.image); loadedImages.put(abs, this.image); } } catch (IOException e) { System.out.println("Could not open the file"); } }
public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int[] marbles; HashMap<Integer, Integer> positions; int n, m; StringTokenizer r; int cases = 1; StringBuilder output = new StringBuilder(); while (true) { r = new StringTokenizer(in.readLine()); n = Integer.parseInt(r.nextToken()); m = Integer.parseInt(r.nextToken()); if (n == 0 && m == 0) break; marbles = new int[n]; positions = new HashMap<Integer, Integer>(); for (int i = 0; i < n; i++) marbles[i] = Integer.parseInt(in.readLine()); Arrays.sort(marbles); for (int i = n - 1; i >= 0; i--) positions.put(marbles[i], i + 1); output.append("CASE# ").append(cases++).append(":").append("\n"); for (int i = 0; i < m; i++) { n = Integer.parseInt(in.readLine()); if (positions.containsKey(n)) output.append(n).append(" found at ").append(positions.get(n)).append("\n"); else output.append(n).append(" not found").append("\n"); } } System.out.print(output); in.close(); System.exit(0); }
public void removeAllMonsters() { Monster monster = null; ArrayList deadMonsters = new ArrayList(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { deadMonsters.add(key); if (gameController.multiplayerMode == gameController.multiplayerMode.SERVER && registry.getNetworkThread() != null) { if (registry.getNetworkThread().readyForUpdates()) { UpdateMonster um = new UpdateMonster(monster.getId()); um.mapX = monster.getMapX(); um.mapY = monster.getMapY(); um.action = "Die"; registry.getNetworkThread().sendData(um); } } } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
private void removeMonster(String monsterType) { Monster monster = null; ArrayList deadMonsters = new ArrayList(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster.getName().equals(monsterType)) { deadMonsters.add(key); break; } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
@Override public void update() { if (!transmitting) { super.update(); ArrayList deadMonsters = new ArrayList(); Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster != null) { monster.update(); if (monster.getIsDead()) { deadMonsters.add(key); } } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } } }
public boolean handleClick(Player p, Point clickPoint) { Point mousePos = new Point(this.panelToMapX(clickPoint.x), this.panelToMapY(clickPoint.y)); Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster != null) { if (monster.isInside(mousePos) && !monster.getIsHiding()) { if (selectedMob != monster) { SoundClip cl = new SoundClip("Misc/Click"); selectedMob = monster; } return true; } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return false; }
public static ArrayList<TaggedWord> StopWordRemoval(ArrayList<TaggedWord> taggedWords) { ArrayList<TaggedWord> newList = new ArrayList<TaggedWord>(); try { String path = "data/nltk_stoplist.txt"; File textFile = new File(path); BufferedReader br = new BufferedReader(new FileReader(textFile)); String stopwordsLine = br.readLine(); br.close(); String[] stopwords = stopwordsLine.split(","); HashMap<String, String> stopwordsDict = new HashMap<String, String>(); for (int i = 0; i < stopwords.length; i++) { stopwordsDict.put(stopwords[i], stopwords[i]); } for (int i = 0; i < taggedWords.size(); i++) { String word = taggedWords.get(i).word(); String posTag = taggedWords.get(i).tag(); if (!stopwordsDict.containsKey(word.toLowerCase())) { String newWord, newPosTag; newWord = word; newPosTag = posTag; newList.add(new TaggedWord(newWord, newPosTag)); } } } catch (Exception ex) { ex.printStackTrace(); } return newList; }
@Override public void sendMessage(final FriendMessage message) { HashMap<String, Friend> friends = AccountManager.getInstance().getFriends(); Friend friend = friends.get(message.getTo()); Screenname buddy = new Screenname(friend.getUserName()); Conversation c = (Conversation) friend.getUserInfo(); if (c == null) { c = connection.getIcbmService().getImConversation(buddy); friend.setUserInfo(c); } Message oscarMessage = new Message() { public boolean isAutoResponse() { return false; } public String getMessageBody() { return message.getMessage(); } }; c.sendMessage(oscarMessage); Friend recipient = friends.get(message.getTo()); accountListener.didReceiveMessageForFriend(message, recipient); }
private static void getTopDocuments(int num, HashMap<String, Float> scoremap, String filename) throws FileNotFoundException { PrintWriter out = new PrintWriter(filename); Iterator<String> itr = scoremap.keySet().iterator(); ArrayList<String> urls = new ArrayList<String>(); ArrayList<Float> scores = new ArrayList<Float>(); while (itr.hasNext()) { String key = itr.next(); if (scores.size() < num) { scores.add(scoremap.get(key)); urls.add(key); } else { int index = scores.indexOf(Collections.min(scores)); if (scores.get(index) < scoremap.get(key)) { scores.set(index, scoremap.get(key)); urls.set(index, key); } } } while (scores.size() > 0) { int index = scores.indexOf(Collections.max(scores)); out.println(urls.get(index) + "\t" + scores.get(index)); urls.remove(index); scores.remove(index); } out.close(); }
public void composition_tokenizer(String comp_line) { comp_line = remove_for_agg(comp_line); String c_name = get_first(comp_line, "COMPOSITION"); String comp_name = get_latter(comp_line, "COMPOSITION"); StringBuilder construct_param = new StringBuilder(); construct_param.append(comp_name); construct_param.append("_"); construct_param.append(Integer.toString(param_count)); String param = construct_param.toString(); param_count++; if (output.get(c_name) != null) { comp_name = get_latter(comp_line, "COMPOSITION"); output.get(c_name).add_parameters(param); output.get(c_name).add_comp(param); } else { comp_name = get_first(comp_line, "COMPOSITION"); output.put(c_name, classes[object_count]); output.get(c_name).set_weird_name(c_name); current_class = c_name; object_count++; output.get(c_name).add_parameters(param); output.get(c_name).add_comp(param); } }
private static void convertToInlinkMap( HashMap<String, Set<String>> outlinkmapping, HashMap<String, JSONArray> inlinkmapping) throws Exception, FileNotFoundException { Iterator<String> keys = outlinkmapping.keySet().iterator(); System.out.println("outlink map count " + outlinkmapping.size()); while (keys.hasNext()) { String key = (String) keys.next(); Set<String> s = outlinkmapping.get(key); ArrayList<String> a = new ArrayList<String>(s); // System.out.println("Started for "+count++ + + outlinkmapping.size() +a.size()); for (int i = 0; i < a.size(); i++) { String inlink = a.get(i); if (outlinkmapping.containsKey(inlink)) { Object inlinks = inlinkmapping.containsKey(inlink) ? inlinkmapping.get(inlink) : new JSONArray(); ((JSONArray) inlinks).add(key); inlinkmapping.put(inlink, (JSONArray) inlinks); } } // System.out.println("Endded for "+count++ + " " + outlinkmapping.size() +" "+a.size()); } System.out.println("inlink map count " + inlinkmapping.size()); System.out.println("Done"); }
/** * Constructor * * @param name name of bot * @param path root path of Program AB * @param action Program AB action */ public Bot(String name, String path, String action) { int cnt = 0; int elementCnt = 0; this.name = name; setAllPaths(path, name); this.brain = new Graphmaster(this); this.learnfGraph = new Graphmaster(this, "learnf"); this.learnGraph = new Graphmaster(this, "learn"); // this.unfinishedGraph = new Graphmaster(this); // this.categories = new ArrayList<Category>(); preProcessor = new PreProcessor(this); addProperties(); cnt = addAIMLSets(); if (MagicBooleans.trace_mode) System.out.println("Loaded " + cnt + " set elements."); cnt = addAIMLMaps(); if (MagicBooleans.trace_mode) System.out.println("Loaded " + cnt + " map elements"); this.pronounSet = getPronouns(); AIMLSet number = new AIMLSet(MagicStrings.natural_number_set_name, this); setMap.put(MagicStrings.natural_number_set_name, number); AIMLMap successor = new AIMLMap(MagicStrings.map_successor, this); mapMap.put(MagicStrings.map_successor, successor); AIMLMap predecessor = new AIMLMap(MagicStrings.map_predecessor, this); mapMap.put(MagicStrings.map_predecessor, predecessor); AIMLMap singular = new AIMLMap(MagicStrings.map_singular, this); mapMap.put(MagicStrings.map_singular, singular); AIMLMap plural = new AIMLMap(MagicStrings.map_plural, this); mapMap.put(MagicStrings.map_plural, plural); // System.out.println("setMap = "+setMap); Date aimlDate = new Date(new File(aiml_path).lastModified()); Date aimlIFDate = new Date(new File(aimlif_path).lastModified()); if (MagicBooleans.trace_mode) System.out.println("AIML modified " + aimlDate + " AIMLIF modified " + aimlIFDate); // readUnfinishedIFCategories(); MagicStrings.pannous_api_key = Utilities.getPannousAPIKey(this); MagicStrings.pannous_login = Utilities.getPannousLogin(this); if (action.equals("aiml2csv")) addCategoriesFromAIML(); else if (action.equals("csv2aiml")) addCategoriesFromAIMLIF(); else if (action.equals("chat-app")) { if (MagicBooleans.trace_mode) System.out.println("Loading only AIMLIF files"); cnt = addCategoriesFromAIMLIF(); } else if (aimlDate.after(aimlIFDate)) { if (MagicBooleans.trace_mode) System.out.println("AIML modified after AIMLIF"); cnt = addCategoriesFromAIML(); writeAIMLIFFiles(); } else { addCategoriesFromAIMLIF(); if (brain.getCategories().size() == 0) { System.out.println("No AIMLIF Files found. Looking for AIML"); cnt = addCategoriesFromAIML(); } } Category b = new Category( 0, "PROGRAM VERSION", "*", "*", MagicStrings.program_name_version, "update.aiml"); brain.addCategory(b); brain.nodeStats(); learnfGraph.nodeStats(); }
private static HashMap<String, Boolean> fetchTopDocumentsFromFile( String location, String fileext, String query) throws FileNotFoundException, IOException { HashMap<String, Boolean> validurls = new HashMap<String, Boolean>(); int count = 0; File[] files = new File(location).listFiles(); for (int i = 0; i < files.length; i++) { if (!files[i].isFile() || !files[i].getName().endsWith(".json")) continue; System.out.println(files[i]); JSONParser parser = new JSONParser(); Object obj = null; try { obj = parser.parse(new FileReader(files[i])); // System.out.println(obj); } catch (ParseException e1) { System.out.println("Could not parse the file " + files[i] + " as json"); } JSONObject json = null; try { json = (JSONObject) obj; JSONArray arr = (JSONArray) ((JSONObject) json.get("hits")).get("hits"); for (int j = 0; j < arr.size(); j++) { if (count == 1000) break; JSONObject o = (JSONObject) arr.get(j); validurls.put((String) o.get("_id"), true); count++; } } catch (Exception e) { System.out.println("json object could not be created " + e.toString()); } if (count == 1000) break; } return validurls; }
// keyboard discovery code private void _mapKey(char charCode, int keyindex, boolean shift, boolean altgraph) { log("_mapKey: " + charCode); // if character is not in map, add it if (!charMap.containsKey(new Integer(charCode))) { log("Notified: " + (char) charCode); KeyEvent event = new KeyEvent( applet(), 0, 0, (shift ? KeyEvent.SHIFT_MASK : 0) + (altgraph ? KeyEvent.ALT_GRAPH_MASK : 0), ((Integer) vkKeys.get(keyindex)).intValue(), (char) charCode); charMap.put(new Integer(charCode), event); log("Mapped char " + (char) charCode + " to KeyEvent " + event); if (((char) charCode) >= 'a' && ((char) charCode) <= 'z') { // put shifted version of a-z in automatically int uppercharCode = (int) Character.toUpperCase((char) charCode); event = new KeyEvent( applet(), 0, 0, KeyEvent.SHIFT_MASK + (altgraph ? KeyEvent.ALT_GRAPH_MASK : 0), ((Integer) vkKeys.get(keyindex)).intValue(), (char) uppercharCode); charMap.put(new Integer(uppercharCode), event); log("Mapped char " + (char) uppercharCode + " to KeyEvent " + event); } } }
public void addToTreeSet(String word, int docId, String wordType) { int index = 0; index = defineTypeIndex(wordType); HashMap<Integer, dataType> docList = wordTree.get(word); if (docList == null) { docList = new HashMap<Integer, dataType>(); } dataType currentWordType = docList.get(docId); if (currentWordType == null) { currentWordType = new dataType(); } currentWordType.count++; currentWordType.type[index] = true; docList.put(docId, currentWordType); // docList.add(docId); wordTree.put(word, docList); }
/** * Returns the specified image as icon. * * @param name name of icon * @return icon */ public static ImageIcon icon(final String name) { ImageIcon ii = ICONS.get(name); if (ii != null) return ii; Image img; if (GUIConstants.scale > 1) { // choose large image or none final URL url = GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null; if (url == null) { // resize low-res image if no hi-res image exists img = get(url(name)); final int w = (int) (img.getWidth(null) * GUIConstants.scale); final int h = (int) (img.getHeight(null) * GUIConstants.scale); final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, 0, 0, w, h, null); g2.dispose(); img = tmp; } else { img = get(url); } } else { img = get(name); } ii = new ImageIcon(img); ICONS.put(name, ii); return ii; }
/** * Determines and retrieves data related to the first confluence node (defined as a node with two * or more incoming transitions) of a _transition path corresponding to a given String from a * given node. * * @param originNode the MDAGNode from which the _transition path corresponding to str starts from * @param str a String corresponding to a _transition path in the MDAG * @return a HashMap of Strings to Objects containing: - an int denoting the length of the path to * the first confluence node in the _transition path of interest - the MDAGNode which is the * first confluence node in the _transition path of interest (or null if one does not exist) */ private HashMap<String, Object> getTransitionPathFirstConfluenceNodeData( MDAGNode originNode, String str) { int currentIndex = 0; int charCount = str.length(); MDAGNode currentNode = originNode; // Loop thorugh the characters in str, sequentially using them to _transition through the MDAG // in search of // (and breaking upon reaching) the first node that is the target of two or more transitions. // The loop is // also broken from if the currently processing node doesn't have a _transition labeled with the // currently processing char. for (; currentIndex < charCount; currentIndex++) { char currentChar = str.charAt(currentIndex); currentNode = (currentNode.hasOutgoingTransition(currentChar) ? currentNode.transition(currentChar) : null); if (currentNode == null || currentNode.isConfluenceNode()) break; } ///// boolean noConfluenceNode = (currentNode == originNode || currentIndex == charCount); // Create a HashMap containing the index of the last char in the substring corresponding // to the transitoin path to the confluence node, as well as the actual confluence node HashMap<String, Object> confluenceNodeDataHashMap = new HashMap<String, Object>(2); confluenceNodeDataHashMap.put( "toConfluenceNodeTransitionCharIndex", (noConfluenceNode ? null : currentIndex)); confluenceNodeDataHashMap.put("confluenceNode", noConfluenceNode ? null : currentNode); ///// return confluenceNodeDataHashMap; }
private int distancia_aux( Map<String, Ligacao> ligacoes, DijElem elemAct, HashMap<String, DijElem> elementos, int greycount) { Collection<Ligacao> coll = ligacoes.values(); int grey = greycount; for (Ligacao lig : coll) { DijElem target = elementos.get(lig.get_Localidaded()); if (target != null && (target.get_Vis() != _VIS_BLACK) && (target.get_Nrlocalidades() > (elemAct.get_Nrlocalidades() + 1))) { target.set_Nrlocalidades(elemAct.get_Nrlocalidades() + 1); target.set_Pai(elemAct.get_Nome()); } else if (target == null) { target = new DijElem( lig.get_Localidaded(), elemAct.get_Nrlocalidades() + 1, elemAct.get_Nome(), _VIS_GREY); grey++; elementos.put(lig.get_Localidaded(), target.clone()); } } return grey; }
public static ArrayList<ArrayList<TaggedWord>> getPhrasesNaive( String sentence, LexicalizedParser lp, AbstractSequenceClassifier<CoreLabel> classifier) { ArrayList<ArrayList<TaggedWord>> newList = new ArrayList<ArrayList<TaggedWord>>(); ArrayList<TaggedWord> taggedWords = StanfordNER.parse(sentence, lp, classifier); HashMap<String, String> phraseBoundaries = new HashMap<String, String>(); phraseBoundaries.put(",", ","); phraseBoundaries.put("\"", "\""); phraseBoundaries.put("''", "''"); phraseBoundaries.put("``", "``"); phraseBoundaries.put("--", "--"); // List<Tree> leaves = parse.getLeaves(); ArrayList<TaggedWord> temp = new ArrayList<TaggedWord>(); int index = 0; while (index < taggedWords.size()) { if ((phraseBoundaries.containsKey(taggedWords.get(index).word()))) { if (temp.size() > 0) { // System.out.println(temp); ArrayList<TaggedWord> tempCopy = new ArrayList<TaggedWord>(temp); newList.add(Preprocess(tempCopy)); } temp.clear(); } else { // System.out.println(taggedWords.get(index).toString()); temp.add(taggedWords.get(index)); } index += 1; } if (temp.size() > 0) { ArrayList<TaggedWord> tempCopy = new ArrayList<TaggedWord>(temp); newList.add(Preprocess(tempCopy)); } // System.out.println(newList); return newList; }
public String hasSameContent(JarFile2 file, JarEntry entry) throws IOException { String thisName = null; Long crcL = new Long(entry.getCrc()); // check if this jar contains files with the passed in entry's crc if (_crcToEntryMap.containsKey(crcL)) { // get the Linked List with files with the crc LinkedList ll = (LinkedList) _crcToEntryMap.get(crcL); // go through the list and check for content match ListIterator li = ll.listIterator(0); if (li != null) { while (li.hasNext()) { JarEntry thisEntry = (JarEntry) li.next(); // check for content match InputStream oldIS = getJarFile().getInputStream(thisEntry); InputStream newIS = file.getJarFile().getInputStream(entry); if (!differs(oldIS, newIS)) { thisName = thisEntry.getName(); return thisName; } } } } return thisName; }
public Monster getClosestWithinMax(Point p, int r) { Monster monster = null; Monster closestMonster = null; double closestDistance = 0; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { if (monster.getIsInPanel()) { double distance = p.distance(monster.getCenterPoint()); if ((distance < closestDistance || closestDistance == 0) && distance <= r) { closestMonster = monster; closestDistance = distance; } } } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } return closestMonster; }