// returns the most recent val Object lock(Ref ref) { // can't upgrade readLock, so release it releaseIfEnsured(ref); boolean unlocked = true; try { tryWriteLock(ref); unlocked = false; if (ref.tvals != null && ref.tvals.point > readPoint) throw retryex; Info refinfo = ref.tinfo; // write lock conflict if (refinfo != null && refinfo != info && refinfo.running()) { if (!barge(refinfo)) { ref.lock.writeLock().unlock(); unlocked = true; return blockAndBail(refinfo); } } ref.tinfo = info; return ref.tvals == null ? null : ref.tvals.val; } finally { if (!unlocked) ref.lock.writeLock().unlock(); } }
public boolean checkForExist(Info info) { boolean b = false; cursor = musicBase.query("mytable", null, null, null, null, null, null); initColumns(); if (cursor.moveToFirst()) { do { Info addedInfo = new Info( cursor.getString(nameCollumIndex), cursor.getInt(durationCollumIndex), new User(cursor.getString(authorCollumIndex)), cursor.getInt(likesCountCollumIndex), cursor.getString(streamUrlCollumIndex), cursor.getString(pathToFileCollumIndex), cursor.getString(artworkUrlCollumIndex)); if (addedInfo.getStream_url().equals(info.getStream_url())) { b = true; break; } } while (cursor.moveToNext()); } return b; }
@Test public void testPOSTRequestNoContent() throws Exception { ByteBuffer header = BufferUtil.allocate(2048); HttpGenerator gen = new HttpGenerator(); HttpGenerator.Result result = gen.generateRequest(null, null, null, null, true); Assert.assertEquals(HttpGenerator.Result.NEED_INFO, result); Assert.assertEquals(HttpGenerator.State.START, gen.getState()); Info info = new Info("POST", "/index.html"); info.getFields().add("Host", "something"); info.getFields().add("User-Agent", "test"); Assert.assertTrue(!gen.isChunking()); result = gen.generateRequest(info, null, null, null, true); Assert.assertEquals(HttpGenerator.Result.NEED_HEADER, result); Assert.assertEquals(HttpGenerator.State.START, gen.getState()); result = gen.generateRequest(info, header, null, null, true); Assert.assertEquals(HttpGenerator.Result.FLUSH, result); Assert.assertEquals(HttpGenerator.State.COMPLETING, gen.getState()); Assert.assertTrue(!gen.isChunking()); String out = BufferUtil.toString(header); BufferUtil.clear(header); result = gen.generateResponse(null, null, null, null, false); Assert.assertEquals(HttpGenerator.Result.DONE, result); Assert.assertEquals(HttpGenerator.State.END, gen.getState()); Assert.assertTrue(!gen.isChunking()); Assert.assertEquals(0, gen.getContentPrepared()); Assert.assertThat(out, Matchers.containsString("POST /index.html HTTP/1.1")); Assert.assertThat(out, Matchers.containsString("Content-Length: 0")); }
public ArrayList<Info> getInfo() { cursor = musicBase.query("mytable", null, null, null, null, null, null); initColumns(); ArrayList<Info> list = new ArrayList<>(); if (cursor.moveToFirst()) { do { Info addedInfo = new Info( cursor.getString(nameCollumIndex), cursor.getInt(durationCollumIndex), new User(cursor.getString(authorCollumIndex)), cursor.getInt(likesCountCollumIndex), cursor.getString(streamUrlCollumIndex), cursor.getString(pathToFileCollumIndex), cursor.getString(artworkUrlCollumIndex)); list.add(addedInfo); Log.i("list", addedInfo.toString()); Log.i("list", "----------------------------------------------"); } while (cursor.moveToNext()); } return list; }
@Override public void createPartControl(Composite parent) { this.parent = parent; Model m = new Model(); parent.setLayout(new GridLayout(2, false)); Func func = new Func(m, parent, this); func.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 2)); Show view = new Show(m, parent); view.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); Info text = new Info(m, parent); text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); m.addObserver(view); m.addObserver(func); m.addObserver(text); m.setNotified(); parent.layout(); PlatformUI.getWorkbench() .getHelpSystem() .setHelp(parent, ACOPlugin.PLUGIN_ID + ".view"); // $NON-NLS-1$ }
private Info Draw(Node r, int x, int y, Graphics g) { Info rootInfo = new Info(); rootInfo.xfinal = x; if (r == null) return rootInfo; Info leftInfo, rightInfo; leftInfo = Draw(r.left, x, y + 40, g); x = leftInfo.xfinal; g.drawOval(x, y, 30, 30); g.drawString("" + r.data, x + 10, y + 20); rootInfo.xroot = x; rightInfo = Draw(r.right, x + 30, y + 40, g); rootInfo.xfinal = rightInfo.xfinal; if (r.left != null) { g.drawLine(rootInfo.xroot + 5, y + 25, leftInfo.xroot + 15, y + 40); } if (r.right != null) { g.drawLine(rootInfo.xroot + 25, y + 25, rightInfo.xroot + 15, y + 40); } return rootInfo; }
/* Evaluate an offer deciding how * useful it is for other players * How you evaluate an offer is by * using the ranking based on * preferences of each player * You square the absolute value * of each color even if is negative * and they are assigned values * between -1 and 1 */ public double marketEvaluation(int[] toTake, int[] toGive) { /* The first one is 1.0 the last one is -1.0 * For 5 colors this array would be * [1, 0.5, 0, -0.5, -1] */ double[] value = new double[info.colors]; for (int i = 0; i != info.colors; ++i) value[i] = 1.0 - (i / (double) (info.colors - 1)) * 2.0; /* Go through every player */ double res = 0.0; for (int player = 0; player != info.players; ++player) { /* Skip yourself */ if (player == info.myId) continue; /* Check the guy has the stuff */ if (!info.canTrade(toTake, player)) continue; /* Get ranking of colors for that player */ int[] rank = Info.rank(info.preferences(player)); for (int color = 0; color != info.colors; ++color) { double val = value[rank[color]]; /* If the color is beneficial to the player */ if (val > 0.0) /* Taking it from him hurts him * Giving it to him helps him */ res += (toGive[color] - toTake[color]) * val * val; /* If the color is useless to the player */ else /* Taking it from him helps him * Giving it to him hurts him */ res += (toTake[color] - toGive[color]) * val * val; } } // System.out.println("Market value: " + res); return res; }
private void waitForBatches( DataLoadTimeSummary dataLoadTimeSummary, Scenario scenario, long start, List<Future> writeBatches) throws InterruptedException, java.util.concurrent.ExecutionException { int sumRows = 0, sumDuration = 0; // Wait for all the batch threads to complete for (Future<Info> write : writeBatches) { Info writeInfo = write.get(); sumRows += writeInfo.getRowCount(); sumDuration += writeInfo.getDuration(); logger.info( "Executor (" + this.hashCode() + ") writes complete with row count (" + writeInfo.getRowCount() + ") in Ms (" + writeInfo.getDuration() + ")"); } logger.info( "Writes completed with total row count (" + sumRows + ") with total time of(" + sumDuration + ") Ms"); dataLoadTimeSummary.add( scenario.getTableName(), sumRows, (int) (System.currentTimeMillis() - start)); }
@Path("/create/{ObjID}/{ObjInsId}") @POST @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public Response sendCreate( @PathParam("ObjID") String objectId, @PathParam("ObjInsId") String objectInstanceId, @QueryParam("ep") String endPoint, String value) throws InterruptedException { String string = objectId + "/" + objectInstanceId; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("operation", "create"); jsonObject.addProperty("directory", string); jsonObject.addProperty("value", value); Info.setInfo(endPoint, jsonObject.toString()); CountDownLatch signal = Info.getCountDown(endPoint); if (signal == null) { return Response.status(200).entity("Devices not registered yet").build(); } signal.countDown(); CountDownLatch signalRead = new CountDownLatch(1); Info.setCountDownLatchMessageMap(endPoint, signalRead); signalRead.await(); return Response.status(200).entity("creation success").build(); }
@Override public void write() { level++; String tag = this.tag == null ? "object" : this.tag; print("<" + tag); Info info = objectToInfo.get(value); if (info.count > 1) { if (info.id == UNDEFINED) { writeAttribute(Utilities.ID_ATTRIBUTE_NAME, info.id = nextId(value.getClass())); } else { writeAttribute(Utilities.IDREF_ATTRIBUTE_NAME, info.id); } } for (Attribute attribute : attributes) { attribute.write(); } if (!elements.isEmpty()) { out.println(">"); for (Element element : elements) { element.write(); } println("</" + tag + ">"); } else { out.println("/>"); } level--; }
/** * Prepares the MemoryIndex for querying in a non-lazy way. * * <p>After calling this you can query the MemoryIndex from multiple threads, but you cannot * subsequently add new data. */ public void freeze() { this.frozen = true; for (Info info : fields.values()) { info.sortTerms(); info.getNormDocValues(); // lazily computed } }
@Path("/observe/{ObjID}/{ObjInsId}/{resourceId}") @GET public Response sendObserve( @PathParam("ObjID") String objectId, @PathParam("ObjInsId") String objectInstanceId, @PathParam("resourceId") String resourceID, @QueryParam("ep") String endPoint) { String directory = "{\"operation\":\"observe\"" + "," + "\"" + "directory\":" + "\"" + objectId + "/" + objectInstanceId + "/" + resourceID + "\"}"; Info.setInfo(endPoint, directory); CountDownLatch signal = Info.getCountDown(endPoint); if (signal == null) { return Response.status(200).entity("Devices not registerd yet").build(); } signal.countDown(); return Response.status(200).entity("observe success").build(); }
@Override public NumericDocValues getNormValues(String field) { Info info = fields.get(field); if (info == null) { return null; } return info.getNormDocValues(); }
private void aoe(Info info) { String msg = COLOR + Colors.BOLD; if (info.getMessage().length() > 4) { msg += info.getMessage().substring(5) + " "; } msg += "AOE in! Call out periodic status of how many hostiles are left."; info.sendMessage(msg); }
public void deleteInfo(Info info) { cursor = musicBase.query("mytable", null, null, null, null, null, null); getWritableDatabase() .delete("mytable", "streamUrl = ?", new String[] {String.valueOf(info.getStream_url())}); File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); File myFile = new File(dir, info.getTitle() + ".mp3"); Log.i("delete", myFile.delete() + ""); }
/* Happiness gained if consumed * the whole hand at once */ public double happiness(int[] hand) { double res = 0.0; for (int i = 0; i != info.colors; ++i) if (info.tasted(i)) if (info.taste(i) > 0.0) res += info.taste(i) * hand[i] * hand[i]; else res -= info.taste(i) * hand[i]; return res; }
@Test public void testRequestWithKnownContent() throws Exception { String out; ByteBuffer header = BufferUtil.allocate(4096); ByteBuffer chunk = BufferUtil.allocate(HttpGenerator.CHUNK_SIZE); ByteBuffer content0 = BufferUtil.toBuffer("Hello World. "); ByteBuffer content1 = BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog."); HttpGenerator gen = new HttpGenerator(); HttpGenerator.Result result = gen.generateRequest(null, null, null, content0, false); Assert.assertEquals(HttpGenerator.Result.NEED_INFO, result); Assert.assertEquals(HttpGenerator.State.START, gen.getState()); Info info = new Info("POST", "/index.html", 58); info.getFields().add("Host", "something"); info.getFields().add("User-Agent", "test"); result = gen.generateRequest(info, null, null, content0, false); Assert.assertEquals(HttpGenerator.Result.NEED_HEADER, result); Assert.assertEquals(HttpGenerator.State.START, gen.getState()); result = gen.generateRequest(info, header, null, content0, false); Assert.assertEquals(HttpGenerator.Result.FLUSH, result); Assert.assertEquals(HttpGenerator.State.COMMITTED, gen.getState()); Assert.assertTrue(!gen.isChunking()); out = BufferUtil.toString(header); BufferUtil.clear(header); out += BufferUtil.toString(content0); BufferUtil.clear(content0); result = gen.generateRequest(null, null, null, content1, false); Assert.assertEquals(HttpGenerator.Result.FLUSH, result); Assert.assertEquals(HttpGenerator.State.COMMITTED, gen.getState()); Assert.assertTrue(!gen.isChunking()); out += BufferUtil.toString(content1); BufferUtil.clear(content1); result = gen.generateResponse(null, null, null, null, true); Assert.assertEquals(HttpGenerator.Result.CONTINUE, result); Assert.assertEquals(HttpGenerator.State.COMPLETING, gen.getState()); Assert.assertTrue(!gen.isChunking()); result = gen.generateResponse(null, null, null, null, true); Assert.assertEquals(HttpGenerator.Result.DONE, result); Assert.assertEquals(HttpGenerator.State.END, gen.getState()); out += BufferUtil.toString(chunk); BufferUtil.clear(chunk); Assert.assertThat(out, Matchers.containsString("POST /index.html HTTP/1.1")); Assert.assertThat(out, Matchers.containsString("Host: something")); Assert.assertThat(out, Matchers.containsString("Content-Length: 58")); Assert.assertThat( out, Matchers.containsString( "\r\n\r\nHello World. The quick brown fox jumped over the lazy dog.")); Assert.assertEquals(58, gen.getContentPrepared()); }
public Integer occurences(String word) { for (Info i : lista) { if (i.equals(word)) { i.incrementCount(); } return (int) i.getCount(); } return null; }
private void target(Info info) { if (raidTarget.containsKey(info.getChannel())) { info.sendMessage( COLOR + "The raid target is " + raidTarget.get(info.getChannel()) + " located at " + raidLocation.get(info.getChannel())); } else info.sendMessage("No target is set."); }
/** Set the Similarity to be used for calculating field norms */ public void setSimilarity(Similarity similarity) { if (frozen) throw new IllegalArgumentException("Cannot set Similarity when MemoryIndex is frozen"); if (this.normSimilarity == similarity) return; this.normSimilarity = similarity; // invalidate any cached norms that may exist for (Info info : fields.values()) { info.norms = null; } }
@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub index = position; ViewHolder holder = null; Info info = (Info) mList.get(position).get(INFO); if (convertView == null) { convertView = mInflater.inflate(R.layout.join_info_listview_item, null); holder = new ViewHolder(); holder.name = (TextView) convertView.findViewById(R.id.join_info_item_text_name); holder.starNum = (LinearLayout) convertView.findViewById(R.id.join_info_item_linear_star); holder.progress = (TextView) convertView.findViewById(R.id.join_info_item_text_progress); holder.allAtm = (TextView) convertView.findViewById(R.id.join_info_item_text_all_amt); holder.atm = (TextView) convertView.findViewById(R.id.join_info_item_text_amt); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.name.setText("发起人:" + info.getName()); holder.progress.setText(info.getProgress()); holder.allAtm.setText("¥" + info.getAllAtm()); holder.atm.setText("¥" + info.getAtm()); PublicMethod.createStar( holder.starNum, info.getCrown(), info.getCup(), info.getDiamond(), info.getStarNum(), JoinInfoActivity.this); return convertView; }
@Path("/writeAttribute/{ObjID}/{ObjInsId}/{resourceId}") @PUT @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public Response sendWriteAttribute( @PathParam("ObjID") String objectId, @PathParam("ObjInsId") String objectInstanceId, @PathParam("resourceId") String resourceID, @QueryParam("ep") String endPoint, @QueryParam("pmin") String pmin, @QueryParam("pmax") String pmax, @QueryParam("gt") String gt, @QueryParam("lt") String lt, @QueryParam("st") String st) throws InterruptedException { String string = objectId + "/" + objectInstanceId + "/" + resourceID; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("operation", "writeAttribute"); jsonObject.addProperty("directory", string); JsonObject value = new JsonObject(); if (pmin != null) { value.addProperty("pmin", pmin); } if (pmax != null) { value.addProperty("pmax", pmax); } if (gt != null) { value.addProperty("gt", gt); } if (lt != null) { value.addProperty("lt", lt); } if (st != null) { value.addProperty("st", st); } jsonObject.addProperty("value", value.toString()); // String directory = // "{\"operation\":\"discover\""+","+"\""+"directory\":"+"\""+objectId+"/"+objectInstanceId+"/"+resourceID+"\"}"; Info.setInfo(endPoint, jsonObject.toString()); CountDownLatch signal = Info.getCountDown(endPoint); if (signal == null) { return Response.status(200).entity("Devices not registered yet").build(); } signal.countDown(); CountDownLatch signalRead = new CountDownLatch(1); Info.setCountDownLatchMessageMap(endPoint, signalRead); signalRead.await(); return Response.status(200).entity("writeAttribute success").build(); }
private void setTarget(Info info) { String factionInfo = info.getMessage().substring(11); String[] splitInfo = factionInfo.split("/"); if (splitInfo.length != 2) { info.sendMessage("usage for !setTarget is !setTarget <faction>/<location>"); } else { raidTarget.put(info.getChannel(), splitInfo[0]); raidLocation.put(info.getChannel(), splitInfo[1]); target(info); } }
private void CreateMainWindow() { this.setTitle(Info.getTitle() + " " + Info.getVersion()); this.setIconImage(new ImageIcon(imgPath + "/shipicon.png").getImage()); this.jpMainContainer = new JPanel(new GridBagLayout()); this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); statusBar = new StatusBar(); this.getContentPane().add(statusBar, BorderLayout.SOUTH); statusBar.setMessage("Pronto! Seja bem-vindo."); }
private Item appendGetInfo(Operation operation) { Item item = new Item(); String operationCode = operation.getCode(); for (Info info : Info.values()) { if (operationCode != null && operationCode.equals(info.name())) { Target target = new Target(); target.setLocURI(info.getCode()); item.setTarget(target); } } return item; }
/** * Returns a String representation of the index data for debugging purposes. * * @return the string representation */ @Override public String toString() { StringBuilder result = new StringBuilder(256); int sumPositions = 0; int sumTerms = 0; final BytesRef spare = new BytesRef(); for (Map.Entry<String, Info> entry : fields.entrySet()) { String fieldName = entry.getKey(); Info info = entry.getValue(); info.sortTerms(); result.append(fieldName + ":\n"); SliceByteStartArray sliceArray = info.sliceArray; int numPositions = 0; SliceReader postingsReader = new SliceReader(intBlockPool); for (int j = 0; j < info.terms.size(); j++) { int ord = info.sortedTerms[j]; info.terms.get(ord, spare); int freq = sliceArray.freq[ord]; result.append("\t'" + spare + "':" + freq + ":"); postingsReader.reset(sliceArray.start[ord], sliceArray.end[ord]); result.append(" ["); final int iters = storeOffsets ? 3 : 1; while (!postingsReader.endOfSlice()) { result.append("("); for (int k = 0; k < iters; k++) { result.append(postingsReader.readInt()); if (k < iters - 1) { result.append(", "); } } result.append(")"); if (!postingsReader.endOfSlice()) { result.append(","); } } result.append("]"); result.append("\n"); numPositions += freq; } result.append("\tterms=" + info.terms.size()); result.append(", positions=" + numPositions); result.append("\n"); sumPositions += numPositions; sumTerms += info.terms.size(); } result.append("\nfields=" + fields.size()); result.append(", terms=" + sumTerms); result.append(", positions=" + sumPositions); return result.toString(); }
private void go(Info info) { String msg = COLOR + Colors.BOLD + "MOVE OUT!"; if (raidTarget.get(info.getChannel()) != null) { msg += Colors.NORMAL + COLOR + " Target is " + raidTarget.get(info.getChannel()) + " " + raidLocation.get(info.getChannel()); } info.sendMessage(msg); }
private void setTick(Info info, String time) { int addon = 0; try { addon = Integer.parseInt(time); } catch (NumberFormatException e) { info.sendMessage( "Format exception. Command should be !setTick # where # is the number of minutes till the next tick."); } tickSetter = info.getSender(); tickTime = System.currentTimeMillis(); OFFSET = (Utils.getRealMinutes(info) + addon) % 15; info.sendMessage("Tick set to " + OFFSET + " minutes off."); }
private Info checkIfNeighbor(int r, int c) { Info info = new Info(0, false, false); if (r >= 0 && r < lastGeneration.length && c >= 0 && c < lastGeneration[0].length) { if (lastGeneration[r][c].getStatus() > 0) { if (lastGeneration[r][c].isCured()) { info.cured = true; } else if (lastGeneration[r][c].isDiseased()) { info.diseased = true; } info.neighbors++; } } return info; }
/** To support iteratives - #foreach() */ public Iterator getIterator(Object obj, Info i) throws Exception { if (obj.getClass().isArray()) { return new ArrayIterator(obj); } else if (obj instanceof Collection) { return ((Collection) obj).iterator(); } else if (obj instanceof Map) { return ((Map) obj).values().iterator(); } else if (obj instanceof Iterator) { rlog.warn( "Warning! The iterative " + " is an Iterator in the #foreach() loop at [" + i.getLine() + "," + i.getColumn() + "]" + " in template " + i.getTemplateName() + ". Because it's not resetable," + " if used in more than once, this may lead to" + " unexpected results."); return ((Iterator) obj); } else if (obj instanceof Enumeration) { rlog.warn( "Warning! The iterative " + " is an Enumeration in the #foreach() loop at [" + i.getLine() + "," + i.getColumn() + "]" + " in template " + i.getTemplateName() + ". Because it's not resetable," + " if used in more than once, this may lead to" + " unexpected results."); return new EnumerationIterator((Enumeration) obj); } /* we have no clue what this is */ rlog.warn( "Could not determine type of iterator in " + "#foreach loop " + " at [" + i.getLine() + "," + i.getColumn() + "]" + " in template " + i.getTemplateName()); return null; }