static { REWARD_POINTS.put(1, new int[] {25290, 8489, 1378}); // Daimon The White-Eyed REWARD_POINTS.put( 2, new int[] {25293, 8490, 1378}); // Hestia, Guardian Deity Of The Hot Springs REWARD_POINTS.put(3, new int[] {25523, 8491, 1070}); // Plague Golem REWARD_POINTS.put(4, new int[] {25322, 8492, 782}); // Demon's Agent Falston }
private void matchClients() { final TIntArrayList ids = new TIntArrayList(clients.size()); clients.forEachEntry( new TIntObjectProcedure<ClientInfo>() { @Override public boolean execute(int id, ClientInfo client) { if (client.readyForGame()) ids.add(id); return true; } }); if (ids.size() < 2) return; ids.sort(); for (int i = 0; i < ids.size(); i += 2) { int idOne = ids.get(i); int idTwo = ids.get(i + 1); ClientInfo clientOne = clients.remove(idOne); ClientInfo clientTwo = clients.remove(idTwo); if (clientOne.getAddress().equals(clientTwo.getAddress()) && clientOne.getPort() == clientTwo.getPort()) { if (clientOne.getLastPingTime() > clientTwo.getLastPingTime()) { clients.put(idOne, clientOne); } else { clients.put(idTwo, clientTwo); } continue; } boolean isHost = isHost(clientOne, clientTwo); NetworkGameInfo networkGameInfo; if (isHost) { networkGameInfo = new NetworkGameInfo( idOne, clientOne, clientTwo, clientOne.getRequestedBoard(), clientOne.getRequestedSpeed()); } else { networkGameInfo = new NetworkGameInfo( idTwo, clientTwo, clientOne, clientTwo.getRequestedBoard(), clientTwo.getRequestedSpeed()); } games.put(idOne, networkGameInfo); games.put(idTwo, networkGameInfo); System.out.println("Made game for " + idOne + " and " + idTwo + " " + networkGameInfo); } }
/** * The URLs are a bit ugly and so we need to find out which area name a certain lat,lon coordinate * has. */ private SRTMProvider init() { try { String strs[] = { "Africa", "Australia", "Eurasia", "Islands", "North_America", "South_America" }; for (String str : strs) { InputStream is = getClass().getResourceAsStream(str + "_names.txt.zip"); ZipInputStream zis = new ZipInputStream(is); zis.getNextEntry(); for (String line : Helper.readFile(new InputStreamReader(zis, "UTF-8"))) { int lat = Integer.parseInt(line.substring(1, 3)); if (line.substring(0, 1).charAt(0) == 'S') lat = -lat; int lon = Integer.parseInt(line.substring(4, 7)); if (line.substring(3, 4).charAt(0) == 'W') lon = -lon; int intKey = calcIntKey(lat, lon); String key = areas.put(intKey, str); if (key != null) throw new IllegalStateException( "do not overwrite existing! key " + intKey + " " + key + " vs. " + str); } } return this; } catch (Exception ex) { throw new IllegalStateException("Cannot load area names from classpath", ex); } }
void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { for (SkillPanel panel : templates) { skillPanels.put(panel.getPanelId(), panel); } templates.clear(); templates = null; }
/** * Records the current solution of the solver clears all previous recordings * * @param solver a solver */ public void record(Solver solver) { if (empty) { Variable[] _dvars = solver.getStrategy().getVariables(); for (int i = 0; i < _dvars.length; i++) { dvars.add(_dvars[i].getId()); } empty = false; } boolean warn = false; intmap.clear(); realmap.clear(); setmap.clear(); Variable[] vars = solver.getVars(); for (int i = 0; i < vars.length; i++) { if ((vars[i].getTypeAndKind() & Variable.TYPE) != Variable.CSTE) { int kind = vars[i].getTypeAndKind() & Variable.KIND; if (!vars[i].isInstantiated()) { if (dvars.contains(vars[i].getId())) { throw new SolverException(vars[i] + " is not instantiated when recording a solution."); } else { warn = true; } } else { switch (kind) { case Variable.INT: case Variable.BOOL: IntVar v = (IntVar) vars[i]; intmap.put(v.getId(), v.getValue()); break; case Variable.REAL: RealVar r = (RealVar) vars[i]; realmap.put(r.getId(), new double[] {r.getLB(), r.getUB()}); break; case Variable.SET: SetVar s = (SetVar) vars[i]; setmap.put(s.getId(), s.getValues()); break; } } } } if (warn && solver.getSettings().warnUser()) { Chatterbox.err.printf( "Some non decision variables are not instantiated in the current solution."); } }
/** * Generates a matrix out of a vector list. it treats the entries as rows and the vector itself * contains the values of the columns. * * @param vectorArray the list of vectors. */ public SparseDoubleRowMatrix(List<DoubleVector> vec) { this(vec.size(), vec.get(0).getDimension()); int key = 0; for (DoubleVector value : vec) { matrix.put(key++, new SparseDoubleVector(value)); } }
public BoraToUnvConvert(String unvFile, BSubMesh submesh) { this.unvWriter = new UNVGenericWriter(unvFile); for (Constraint cons : submesh.getConstraints()) { BCADGraphCell cell = cons.getGraphCell(); BDiscretization d = cell.getDiscretizationSubMesh(submesh); mapDiscretizations.put(d.getId(), d); } }
public void loadBorderPoints() throws IOException { Iterator<Entry<RouteRegion, BinaryMapIndexReader>> it = reverseMap.entrySet().iterator(); int sleft = Math.min(startX, targetX); int sright = Math.max(startX, targetX); int stop = Math.min(startY, targetY); int sbottom = Math.max(startY, targetY); // one tile of 12th zoom around (?) int zoomAround = 10; int distAround = 1 << (31 - zoomAround); leftBorderBoundary = sleft - distAround; rightBorderBoundary = sright + distAround; SearchRequest<RouteDataBorderLinePoint> req = BinaryMapIndexReader.buildSearchRouteBorderRequest(sleft, sright, stop, sbottom); while (it.hasNext()) { Entry<RouteRegion, BinaryMapIndexReader> entry = it.next(); entry.getValue().searchBorderPoints(req, entry.getKey()); } TIntObjectHashMap<RouteDataBorderLine> lines = new TIntObjectHashMap<RoutingContext.RouteDataBorderLine>(); for (RouteDataBorderLinePoint p : req.getSearchResults()) { if (config.router.acceptLine(p) && p.x > leftBorderBoundary && p.x < rightBorderBoundary) { if (!lines.containsKey(p.y)) { RouteDataBorderLine line = new RouteDataBorderLine(p.y); lines.put(p.y, line); RouteDataBorderLinePoint lft = new RouteDataBorderLinePoint(p.region); lft.y = p.y; lft.id = Long.MIN_VALUE; lft.x = leftBorderBoundary; line.borderPoints.add(lft); RouteDataBorderLinePoint rht = new RouteDataBorderLinePoint(p.region); rht.y = p.y; rht.id = Long.MIN_VALUE; rht.x = rightBorderBoundary; line.borderPoints.add(rht); } lines.get(p.y).borderPoints.add(p); } } borderLines = lines.values(new RouteDataBorderLine[lines.size()]); Arrays.sort(borderLines); borderLineCoordinates = new int[borderLines.length]; for (int i = 0; i < borderLineCoordinates.length; i++) { borderLineCoordinates[i] = borderLines[i].borderLine; // FIXME borders approach // not less then 14th zoom if (i > 0 && borderLineCoordinates[i - 1] >> 17 == borderLineCoordinates[i] >> 17) { throw new IllegalStateException(); } System.out.println( "Line " + (borderLineCoordinates[i] >> 17) + " points " + borderLines[i].borderPoints.size() /* + " " +borderLines[i].borderPoints*/); } updateDistanceForBorderPoints(startX, startY, true); updateDistanceForBorderPoints(targetX, targetY, false); }
@Override public DoubleVector getRowVector(int row) { SparseDoubleVector v = matrix.get(row); if (v == null) { v = new SparseDoubleVector(getColumnCount()); matrix.put(row, v); } return v; }
public static TIntObjectHashMap<String> getAllWordIds() { TObjectIntHashMap<String> wordIds = DataAccess.getAllWordIds(); TIntObjectHashMap<String> idWords = new TIntObjectHashMap<String>(wordIds.size()); for (TObjectIntIterator<String> itr = wordIds.iterator(); itr.hasNext(); ) { itr.advance(); idWords.put(itr.value(), itr.key()); } return idWords; }
public void addToIndex(TIntIntHashMap newIndexEntries) { for (int word : newIndexEntries.keys()) { int offset = newIndexEntries.get(word); TIntLinkedList positions; positions = indexIncludingStopWords.get(word); if (positions == null) { positions = new TIntLinkedList(); indexIncludingStopWords.put(word, positions); } positions.add(offset); positions = indexWithoutStopWords.get(word); if (positions == null) { positions = new TIntLinkedList(); indexWithoutStopWords.put(word, positions); } positions.add(offset); } }
@Override public void set(int row, int col, double value) { if (value != 0.0d) { SparseDoubleVector sparseDoubleVector = matrix.get(row); if (sparseDoubleVector == null) { sparseDoubleVector = new SparseDoubleVector(getColumnCount()); matrix.put(row, sparseDoubleVector); } sparseDoubleVector.set(col, value); } }
public void setTitle(LivingEntity entity, String title) { if (entity instanceof SpoutPlayer) { ((SpoutPlayer) entity).setTitle(title); } titles.put(entity.getEntityId(), title); ArrayList<LivingEntity> entities = new ArrayList<LivingEntity>(1); entities.add(entity); for (SpoutPlayer player : getOnlinePlayers()) { player.updateEntitySkins(entities); } }
public int prepareGame(ClientInfo clientInfo) { System.out.println("prepareGame: " + clientInfo); int id = currentID.incrementAndGet(); clientInfo.resetPing(); writeLock.lock(); clients.put(id, clientInfo); notifyMatcher(); writeLock.unlock(); return id; }
public void loadAllSkills(final TIntObjectHashMap<L2Skill> allSkills) { int count = 0; for (File file : _skillFiles) { List<L2Skill> s = loadSkills(file); if (s == null) continue; for (L2Skill skill : s) { allSkills.put(SkillTable.getSkillHashCode(skill), skill); count++; } } _log.info("SkillsEngine: Loaded " + count + " skill templates from XML files."); }
/** Creates a deep copy of a TIntObjectHashMap<TIntHashSet>. */ public static TIntObjectHashMap<TIntHashSet> deepClone(TIntObjectHashMap<TIntHashSet> map) { TIntObjectHashMap<TIntHashSet> clone = new TIntObjectHashMap<TIntHashSet>(); for (TIntIterator keyit = map.keySet().iterator(); keyit.hasNext(); ) { int key = keyit.next(); clone.put(key, new TIntHashSet(map.get(key).capacity())); clone.get(key).addAll(map.get(key)); } return clone; }
private Facility binFacility(final Facility fromFacility) { final int cellX = (int) (fromFacility.getCoord().getX() / cellSize_m); final int cellY = (int) (fromFacility.getCoord().getY() / cellSize_m); TIntObjectHashMap<Facility> atX; synchronized (binnedFacilities) { atX = binnedFacilities.get(cellX); if (atX == null) { atX = new TIntObjectHashMap<>(); binnedFacilities.put(cellX, atX); } } Facility f; synchronized (atX) { f = atX.get(cellY); if (f == null) { f = new Facility() { private Coord coord = new Coord( cellX * cellSize_m + cellSize_m / 2, cellY * cellSize_m + cellSize_m / 2); private Id<Link> linkId = NetworkUtils.getNearestLinkExactly(network, coord).getId(); @Override public Id<Link> getLinkId() { return linkId; } @Override public Coord getCoord() { return coord; } @Override public Map<String, Object> getCustomAttributes() { throw new UnsupportedOperationException(); } @Override public Id getId() { throw new UnsupportedOperationException(); } }; atX.put(cellY, f); } } return f; }
public ByteBuffer transcode(List<ByteBuffer> data, ByteBuffer _out) { for (ByteBuffer nalUnit : data) { NIOUtils.skip(nalUnit, 4); NALUnit marker = NALUnit.read(nalUnit); _out.putInt(1); marker.write(_out); if (marker.type == NALUnitType.NON_IDR_SLICE || marker.type == NALUnitType.IDR_SLICE) { transcodeSlice(nalUnit, marker); } else { if (marker.type == NALUnitType.SPS) { SeqParameterSet _sps = SeqParameterSet.read(nalUnit.duplicate()); sps.put(_sps.seq_parameter_set_id, _sps); } else if (marker.type == NALUnitType.PPS) { PictureParameterSet _pps = PictureParameterSet.read(nalUnit.duplicate()); pps.put(_pps.pic_parameter_set_id, _pps); } NIOUtils.write(_out, nalUnit); } } _out.flip(); return _out; }
public InputTextInvertedIndex(int[] tokens, boolean isRemoveStopWords) { indexIncludingStopWords = new TIntObjectHashMap<TIntLinkedList>(); indexWithoutStopWords = new TIntObjectHashMap<TIntLinkedList>(); int noStopwordsPosition = 0; for (int position = 0; position < tokens.length; ++position) { int token = tokens[position]; TIntLinkedList positions = indexIncludingStopWords.get(token); if (positions == null) { positions = new TIntLinkedList(); indexIncludingStopWords.put(token, positions); } positions.add(position); if (!isRemoveStopWords || !StopWord.isStopwordOrSymbol(token)) { positions = indexWithoutStopWords.get(token); if (positions == null) { positions = new TIntLinkedList(); indexWithoutStopWords.put(token, positions); } positions.add(noStopwordsPosition); noStopwordsPosition++; } } }
/* * (non-Javadoc) * * @see org.jmangos.commons.dataholder.DataLoadService#load() */ @Override public TIntObjectHashMap<QuestPrototype> load() { final List<QuestPrototype> questPrototypeList = this.questPrototypeService.readQuestPrototypes(); // Quest map by id final TIntObjectHashMap<QuestPrototype> map = new TIntObjectHashMap<QuestPrototype>(); for (final QuestPrototype quest : questPrototypeList) { map.put(quest.getEntry(), quest); } this.questMap = map; return this.questMap; }
/* * (non-Javadoc) * * @see org.jmangos.commons.dataholder.DataLoadService#reload() */ @Override public void reload() { // Don't replace directly becouse the players can't query quest while // it's loading! logger.info("Loading quest templates to temoary store."); final List<QuestPrototype> questPrototypeList = this.questPrototypeService.readQuestPrototypes(); TIntObjectHashMap<QuestPrototype> tempQuestMap = new TIntObjectHashMap<QuestPrototype>(); for (final QuestPrototype quest : questPrototypeList) { tempQuestMap.put(quest.getEntry(), quest); } logger.info("Loaded " + tempQuestMap.size() + " quests. Replacing new old Quests with newer"); this.questMap = tempQuestMap; tempQuestMap = null; }
/** * Add the table returning its index or -1 if rejected * * @param table * @param logger * @return */ public int addTable(T table) { if (TableUtils.findTableIndex(this, table.getName(), true) != -1) { throw new RuntimeException("Table already exists: " + table.getName()); } if (table.getImmutableId() == -1) { throw new RuntimeException("Invalid table immutable id in table: " + table.getName()); } // we throw an exception if the id is already used because this will // be caused by a code error rather than a user error if (tablesById.get(table.getImmutableId()) != null) { throw new RuntimeException("Duplicate table id"); } tablesByIndx.add(table); tablesById.put(table.getImmutableId(), table); return tablesByIndx.size() - 1; }
protected DomOverWDeg(Solver solver, long seed) { this.solver = solver; rand = new Random(seed); counter = new FailPerPropagator(solver.getCstrs(), solver); vid2dsize = new TIntIntHashMap(); vid2degree = new TIntIntHashMap(); vid2weig = new TIntIntHashMap(); pid2ari = new TIntObjectHashMap<IStateInt>(); pid2arity = new TIntIntHashMap(10, 0.5F, -1, -1); Variable[] vars = solver.getVars(); for (int i = 0; i < vars.length; i++) { vars[i].addMonitor(this); } Constraint[] cstrs = solver.getCstrs(); for (int i = 0; i < cstrs.length; i++) { Propagator[] props = cstrs[i].getPropagators(); for (int j = 0; j < props.length; j++) { pid2ari.put(props[j].getId(), solver.getEnvironment().makeInt(props[j].arity())); } } }
@Override public void setDictionary(Locale locale, LanguageDictionary dictionary) { languageDictionaries.put(locale.hashCode(), dictionary); }
@Override public void setRowVector(int rowIndex, DoubleVector row) { matrix.put(rowIndex, new SparseDoubleVector(row)); }
@Override public double getEle(double lat, double lon) { lat = (int) (lat * precision) / precision; lon = (int) (lon * precision) / precision; int intKey = calcIntKey(lat, lon); HeightTile demProvider = cacheData.get(intKey); if (demProvider == null) { if (!cacheDir.exists()) cacheDir.mkdirs(); String fileDetails = getFileString(lat, lon); if (fileDetails == null) return 0; int minLat = down(lat); int minLon = down(lon); demProvider = new HeightTile(minLat, minLon, WIDTH, precision); cacheData.put(intKey, demProvider); try { String zippedURL = baseUrl + "/" + fileDetails + "hgt.zip"; File file = new File(cacheDir, new File(zippedURL).getName()); InputStream is; // get zip file if not already in cacheDir - unzip later and in-memory only! if (!file.exists()) { for (int i = 0; i < 2; i++) { try { downloader.downloadFile(zippedURL, file.getAbsolutePath()); break; } catch (FileNotFoundException ex) { // now try with point if mirror is used zippedURL = baseUrl + "/" + fileDetails + ".hgt.zip"; continue; } } } is = new FileInputStream(file); ZipInputStream zis = new ZipInputStream(is); zis.getNextEntry(); BufferedInputStream buff = new BufferedInputStream(zis); byte[] bytes = new byte[2 * WIDTH * WIDTH]; DataAccess heights = getDirectory().find("dem" + intKey); heights.create(bytes.length); demProvider.setHeights(heights); int len; while ((len = buff.read(bytes)) > 0) { for (int bytePos = 0; bytePos < len; bytePos += 2) { short val = BIT_UTIL.toShort(bytes, bytePos); if (val < -1000 || val > 10000) { // TODO fill unassigned gaps with neighbor values -> flood fill algorithm ! // -> calculate mean with an associated weight of how long the distance to the // neighbor is // throw new IllegalStateException("Invalid height value " // + val // + ", y:" + bytePos / WIDTH + ", x:" + (WIDTH - // bytePos % WIDTH)); val = Short.MIN_VALUE; } heights.setShort(bytePos, val); } } // demProvider.toImage(file.getName() + ".png"); } catch (Exception ex) { throw new RuntimeException(ex); } } short val = demProvider.getHeight(lat, lon); if (val == Short.MIN_VALUE) return Double.NaN; return val; }
/** Method load. */ private void load() { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); File file = new File(Config.DATAPACK_ROOT, "data/xml/other/cursed_weapons.xml"); if (!file.exists()) { return; } Document doc = factory.newDocumentBuilder().parse(file); for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) { if ("list".equals(n.getNodeName())) { for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) { if ("item".equals(d.getNodeName())) { NamedNodeMap attrs = d.getAttributes(); int id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue()); int skillId = Integer.parseInt(attrs.getNamedItem("skillId").getNodeValue()); String name = "Unknown cursed weapon"; if (attrs.getNamedItem("name") != null) { name = attrs.getNamedItem("name").getNodeValue(); } else if (ItemHolder.getInstance().getTemplate(id) != null) { name = ItemHolder.getInstance().getTemplate(id).getName(); } if (id == 0) { continue; } CursedWeapon cw = new CursedWeapon(id, skillId, name); for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling()) { if ("dropRate".equals(cd.getNodeName())) { cw.setDropRate( Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("duration".equals(cd.getNodeName())) { attrs = cd.getAttributes(); cw.setDurationMin(Integer.parseInt(attrs.getNamedItem("min").getNodeValue())); cw.setDurationMax(Integer.parseInt(attrs.getNamedItem("max").getNodeValue())); } else if ("durationLost".equals(cd.getNodeName())) { cw.setDurationLost( Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("disapearChance".equals(cd.getNodeName())) { cw.setDisapearChance( Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("stageKills".equals(cd.getNodeName())) { cw.setStageKills( Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("transformationId".equals(cd.getNodeName())) { cw.setTransformationId( Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("transformationTemplateId".equals(cd.getNodeName())) { cw.setTransformationTemplateId( Integer.parseInt(cd.getAttributes().getNamedItem("val").getNodeValue())); } else if ("transformationName".equals(cd.getNodeName())) { cw.setTransformationName(cd.getAttributes().getNamedItem("val").getNodeValue()); } } _cursedWeaponsMap.put(id, cw); } } } } _cursedWeapons = _cursedWeaponsMap.values(new CursedWeapon[_cursedWeaponsMap.size()]); } catch (Exception e) { _log.error("CursedWeaponsManager: Error parsing cursed_weapons file. " + e); } }
public void addFloor(ShuttleWayEvent floor) { _floors.put((floor.getId() % 100), floor); }
void afterUnmarshal(Unmarshaller u, Object parent) { for (BindPointTemplate bind : bplist) { bindplistData.put(bind.getNpcId(), bind); } }
public L2Transformation registerTransformation(L2Transformation transformation) { return _transformations.put(transformation.getId(), transformation); }