private Action raise(int amount) { if (canRaise) return ActionUtils.raise( HelperUtils.minMax(amount, raiseAction.getMin(), raiseAction.getMax())); else if (canCall) return call(); else return fold(); }
/** Test of inject method, of class ActionUtils. */ @Test public void testInject() { System.out.println("inject"); ActionTest action = new ActionTest(); JSONObject param = new JSONObject(); param.put("i", 1); param.put("jj", 2); param.put("ll", 3); ActionUtils.inject(action, param); assertEquals(1, action.i); assertEquals(2, action.j); assertEquals(null, action.k); assertEquals(3, action.l); }
public void run(final IVexWidget vexWidget) { final int indexToDup = ActionUtils.getCurrentColumnIndex(vexWidget); if (indexToDup == -1) { return; } vexWidget.doWork( new Runnable() { public void run() { final List cellsToDup = new ArrayList(); ActionUtils.iterateTableCells( vexWidget, new TableCellCallback() { public void startRow(Object row, int rowIndex) {} public void onCell(Object row, Object cell, int rowIndex, int cellIndex) { if (cellIndex == indexToDup && cell instanceof Element) { cellsToDup.add(cell); } } public void endRow(Object row, int rowIndex) {} }); int finalOffset = -1; for (Iterator it = cellsToDup.iterator(); it.hasNext(); ) { Element element = (Element) it.next(); if (finalOffset == -1) { finalOffset = element.getStartOffset() + 1; } vexWidget.moveTo(element.getEndOffset() + 1); vexWidget.insertElement((Element) element.clone()); } if (finalOffset != -1) { vexWidget.moveTo(finalOffset); } } }); }
/** Watch for new actions & changes in the actions. */ public void execute() { Iterator iter; // ********* Check for the servlet being added *********** if (servlet == null) { iter = servletSubscription.getAddedCollection().iterator(); if (iter.hasNext()) { servlet = (ActionMonitorServlet) iter.next(); logger.debug("**** Saw new ActionMonitorServlet"); } } // ********* Check for actions being added *********** iter = actionsSubscription.getAddedCollection().iterator(); while (iter.hasNext()) { Action a = (Action) iter.next(); if (servlet != null) { servlet.addAction(a); } // At least temp for testing -- next 7 lines String target = "noTargets"; Iterator it = null; Collection c = a.getTargets(); if (c != null) { it = a.getTargets().iterator(); if (it != null && it.hasNext()) { MessageAddress ma = (MessageAddress) it.next(); if (ma != null) target = ma.toString(); else target = "null msgAddr"; } else target = "noTarget"; } logger.debug( "[AgentId=" + agentId + "]**** Saw new Action[" + ActionUtils.getAssetID(a) + "], with ActionRecord = " + a.getValue() + " UID=" + a.getUID() + " src=" + a.getSource() + ",tgt=" + target); } // ********* Check for changes in our modes ************ iter = actionsSubscription.getChangedCollection().iterator(); while (iter.hasNext()) { Action a = (Action) iter.next(); if (servlet != null) { servlet.changedAction(a); } logger.debug( "[AgentId=" + agentId + "]**** Saw changed Action[" + ActionUtils.getAssetID(a) + "], with ActionRecord = " + a.getValue() + " UID=" + a.getUID()); } // Emit # of action wrappers on BB int size = actionsSubscription.getCollection().size(); logger.debug( "[AgentId=" + agentId + "]**** Total # of Action objects on BB right now = " + size); }
/** @param args */ public static void main(String[] args) { ActionUtils.zipFullDirectory("/tmp/testfolder", "/tmp/test.zip"); }
////////////// /////// BETTING ////////////// private Action bet(int amount) { if (canBet) return ActionUtils.bet(HelperUtils.minMax(amount, betAction.getMin(), betAction.getMax())); else if (canCall) return call(); else return fold(); }
private Action fold() { return ActionUtils.fold(); }
private Action check() { if (!canCheck) return fold(); else return ActionUtils.check(); }
private Action call() { if (!canCall) return putMin(); else return ActionUtils.call(); }
private Action discardCard() { return ActionUtils.discard(chosenDiscardCard); }
public void processInput(String input) { String[] tokens = input.split(" "); String word = tokens[0]; if ("NEWGAME".compareToIgnoreCase(word) == 0) { String myName = tokens[1]; String oppName = tokens[2]; int stackSize = Integer.parseInt(tokens[3]); int bb = Integer.parseInt(tokens[4]); numHands = Integer.parseInt(tokens[5]); maj = new Historian(myName, oppName, stackSize, bb); // newGame(); } else if ("KEYVALUE".compareToIgnoreCase(word) == 0) { if (tokens.length < 2) return; String[] smallTokens = tokens[1].split(":"); if (smallTokens.length < 2) return; maj.notifyValue(smallTokens[0], smallTokens[1], tokens[2]); // the key value pair } else if ("NEWHAND".compareToIgnoreCase(word) == 0) { int handNum = Integer.parseInt(tokens[1]); if (handNum == numHands / 4) cons = true; if (handNum == numHands * 2 / 4) { System.out.println("Reg earnings: " + regEarnings + " consEarnings: " + consEarnings); if (consEarnings > regEarnings) cons = true; else cons = false; } System.out.println("Using conservative brain? " + cons); Card[] hand = new Card[3]; hand[0] = CardUtils.getCardByString(tokens[3]); hand[1] = CardUtils.getCardByString(tokens[4]); hand[2] = CardUtils.getCardByString(tokens[5]); double timebank = Double.parseDouble(tokens[8]); Random rand = new Random(); boolean callRaise = false, checkRaise = false; if (rand.nextDouble() < 0.5) { callRaise = true; } if (rand.nextDouble() < 0.5) { checkRaise = true; } if (cons) brain = new ConservativeBrain(maj, hand, timebank, callRaise, checkRaise); else brain = new Brain(maj, hand, timebank, callRaise, checkRaise); brain.handId = Integer.parseInt(tokens[1]); brain.button = Boolean.parseBoolean(tokens[2]); brain.board = new Card[5]; brain.myBank = Integer.parseInt(tokens[6]); brain.oppBank = Integer.parseInt(tokens[7]); // newHand(); } else if ("GETACTION".compareToIgnoreCase(word) == 0) { brain.potSize = Integer.parseInt(tokens[1]); brain.numBoardCards = Integer.parseInt(tokens[2]); int i = 3; for (; i < brain.numBoardCards + 3; i++) brain.board[i - 3] = CardUtils.getCardByString(tokens[i]); brain.numLastActions = Integer.parseInt(tokens[i]); brain.lastActions = new PerformedAction[brain.numLastActions]; int j = i + 1; for (; j < brain.numLastActions + i + 1; j++) { brain.lastActions[j - i - 1] = ActionUtils.getPerformedActionByString(tokens[j]); } brain.numLegalActions = Integer.parseInt(tokens[j]); brain.legalActions = new LegalAction[brain.numLegalActions]; int k = j + 1; for (; k < brain.numLegalActions + j + 1; k++) brain.legalActions[k - j - 1] = ActionUtils.getLegalActionByString(tokens[k]); brain.timebank = Double.parseDouble(tokens[k]); // String res = ActionUtils.performedActionToString((PerformedAction)brain.act()); // System.out.println(res); outStream.println(ActionUtils.performedActionToString((PerformedAction) brain.act())); } else if ("HANDOVER".compareToIgnoreCase(word) == 0) { brain.myBank = Integer.parseInt(tokens[1]); brain.oppBank = Integer.parseInt(tokens[2]); if (cons) { consEarnings = brain.myBank - regEarnings; } else { regEarnings = brain.myBank; } brain.numBoardCards = Integer.parseInt(tokens[3]); int i = 4; for (; i < brain.numBoardCards + 4; i++) brain.board[i - 4] = CardUtils.getCardByString(tokens[i]); brain.numLastActions = Integer.parseInt(tokens[i]); brain.lastActions = new PerformedAction[brain.numLastActions]; int j = i + 1; for (; j < brain.numLastActions + i + 1; j++) { brain.lastActions[j - i - 1] = ActionUtils.getPerformedActionByString(tokens[j]); } maj.update(brain.lastActions); maj.numHandsPlayed++; System.out.println("\nPFR: " + maj.getPFR()); System.out.println("SDW: " + maj.getSDWRate() + "\n"); } else if ("REQUESTKEYVALUES".compareToIgnoreCase(word) == 0) { // At the end, engine will allow bot to send key/value pairs to store. // FINISH indicates no more to store. outStream.println("DELETE " + maj.oppName); outStream.println("PUT " + maj.oppName + ":PFR " + maj.getValueToSave("PFR")); outStream.println("PUT " + maj.oppName + ":SDW " + maj.getValueToSave("SDW")); outStream.println("FINISH"); } }
/* * (non-Javadoc) * * @see * cc.kune.common.client.actions.ActionListener#actionPerformed(cc.kune. * common.client.actions.ActionEvent) */ @Override public void actionPerformed(final ActionEvent event) { contentService.purgeContent(ActionUtils.getActionToken(event)); }
public boolean isEnabled(IVexWidget vexWidget) { return ActionUtils.getCurrentColumnIndex(vexWidget) != -1; }
/** * Help a developer or a user to create a CIS privacy policy by inferring a default one using * information about the CIS. The privacy policy in result will be slightly completed but still * need to be filled. E.g. if a CIS membership criteria engine requires access to geolocation * data, the inference engine will add geolocation data line to the privacy policy. * * @param globalBehaviour Global behavior of the privacy policy: private (default), members only, * public or custom * @param membershipCriteria Membership criteria of the CIS (optional) * @param configuration Other optional configuration * @return A slightly completed privacy policy */ public static RequestPolicy inferCisPrivacyPolicy( PrivacyPolicyBehaviourConstants globalBehaviour, MembershipCrit membershipCriteria, Map<String, String> configuration) throws PrivacyException { // --- Prepare common data // -- Actions: read List<Action> actions = ActionUtils.createList(ActionConstants.READ, ActionConstants.CREATE); // -- Conditions List<Condition> conditions = new ArrayList<Condition>(); // - Common conditions.add(ConditionUtils.create(ConditionConstants.STORE_IN_SECURE_STORAGE, "1")); // - Visibility // Public if (PrivacyPolicyBehaviourConstants.PUBLIC.name().equals(globalBehaviour.name())) { conditions.add(ConditionUtils.createPublic()); } // Members only else if (PrivacyPolicyBehaviourConstants.MEMBERS_ONLY.name().equals(globalBehaviour.name())) { conditions.add(ConditionUtils.createMembersOnly()); } // Private else { conditions.add(ConditionUtils.createPrivate()); } // --- Prepare request item list List<RequestItem> requestItems = new ArrayList<RequestItem>(); boolean optional = false; // - CIS Member list { Resource resource = ResourceUtils.create(DataIdentifierScheme.CIS, CisAttributeTypes.MEMBER_LIST); RequestItem requestItem = RequestItemUtils.create(resource, actions, conditions, optional); requestItems.add(requestItem); } // - Location symbolic { Resource resource = ResourceUtils.create(DataIdentifierScheme.CONTEXT, CtxAttributeTypes.LOCATION_SYMBOLIC); RequestItem requestItem = RequestItemUtils.create(resource, actions, conditions, optional); requestItems.add(requestItem); } optional = true; // - Location coordinates { Resource resource = ResourceUtils.create( DataIdentifierScheme.CONTEXT, CtxAttributeTypes.LOCATION_COORDINATES); RequestItem requestItem = RequestItemUtils.create(resource, actions, conditions, optional); requestItems.add(requestItem); } // - Interests { Resource resource = ResourceUtils.create(DataIdentifierScheme.CONTEXT, CtxAttributeTypes.INTERESTS); RequestItem requestItem = RequestItemUtils.create(resource, actions, conditions, optional); requestItems.add(requestItem); } // - Email { Resource resource = ResourceUtils.create(DataIdentifierScheme.CONTEXT, CtxAttributeTypes.EMAIL); RequestItem requestItem = RequestItemUtils.create(resource, actions, conditions, optional); requestItems.add(requestItem); } // - Occupation { Resource resource = ResourceUtils.create(DataIdentifierScheme.CONTEXT, CtxAttributeTypes.OCCUPATION); RequestItem requestItem = RequestItemUtils.create(resource, actions, conditions, optional); requestItems.add(requestItem); } // - Occupation { Resource resource = ResourceUtils.create(DataIdentifierScheme.CONTEXT, CtxAttributeTypes.WORK_POSITION); RequestItem requestItem = RequestItemUtils.create(resource, actions, conditions, optional); requestItems.add(requestItem); } // --- Prepare parameters Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("globalBehaviour", globalBehaviour); parameters.put("membershipCriteria", membershipCriteria); parameters.put("requestItems", requestItems); if (null != configuration) { parameters.putAll(configuration); } return inferPrivacyPolicy(PrivacyPolicyTypeConstants.CIS, parameters); }