return new Pair<>(username.getText(), password.getText().toCharArray());
public void clear() { meshAndMaterialToRender.set(new Pair<>(null, null)); }
/** * Instantiate a new service simulator compatible to the given config pair. * * @return the simulator * @throws InstantiationException is thrown if any error occurs during the instantiation. * @throws InterruptedException is thrown if the current thread was externally interrupted. */ public AbstractServiceSimulator newInstance(final UnitController unitController, final ServiceType serviceType) throws InstantiationException, InterruptedException { return newInstance(new Pair<>(unitController, serviceType)); }
@Override public void run() { PlanarRegionsListMessage newMessage = planarRegionsListMessage.getAndSet(null); // Reset both clears by using only one pipe if (clearOcTree.getAndSet(false) | clear.getAndSet(false)) { meshAndMaterialToRender.set(new Pair<>(null, null)); return; } if (!enable.get()) return; uiMessager.submitStateRequestToModule(REAModuleAPI.RequestPlanarRegions); if (newMessage == null) return; meshAndMaterialToRender.set(generateMeshAndMaterial(newMessage)); }
public Map<String, javafx.util.Pair<Type, RoleType>> getVarTypeRoleMap() { Map<String, javafx.util.Pair<Type, RoleType>> roleVarTypeMap = new HashMap<>(); if (getParentQuery() == null) return roleVarTypeMap; Set<String> vars = getVarNames(); Map<String, Type> varTypeMap = getParentQuery().getVarTypeMap(); vars.forEach(var -> { Type type = varTypeMap.get(var); roleVarTypeMap.put(var, new Pair<>(type, null)); }); return roleVarTypeMap; }
public <R> Builder<T> addRule(SerializableConsumer<? extends R> rule, SerializableSupplier<T, R> supplier) { Object test = rule.captured()[0]; if (test instanceof ColumnName) { ((ColumnName) test).setName(supplier.method().getName() + " "); } ruleList.add(new Pair(rule, supplier)); return this; }
@VisibleForTesting Pair<ICity, IWare> findClosestCityProducingTradableWare(IAIPlayer player, INavigableVessel vessel) { TreeMap<Double, Pair<ICity, IWare>> distances = new TreeMap<>(); Point2D location = vessel.getLocation(); for (IWare ware : tradableWares) { ICity city = findCitySupplyingWare(player, ware, vessel, new HashSet<>()); double distance = location.distance(city.getCoordinates()); Pair<ICity, IWare> pair = new Pair<>(city, ware); distances.put(distance, pair); } return distances.pollFirstEntry().getValue(); }
@Override public Map<RoleType, Pair<String, Type>> getRoleVarTypeMap() { if (roleVarTypeMap == null) { if (varTypeRoleMap != null) { roleVarTypeMap = new HashMap<>(); varTypeRoleMap.forEach((var, tpair) -> { RoleType rt = tpair.getValue(); if (rt != null) roleVarTypeMap.put(rt, new Pair<>(var, tpair.getKey())); }); } else roleVarTypeMap = computeRoleVarTypeMap(); } return roleVarTypeMap; } }
public synchronized void enqueue(Message msg, Consumer<Message> callback) { queue.add(new Pair<>(msg, callback)); if (runner == null || !runner.isAlive()) { runner = new Runner(this); runner.start(); } }
public <R> BuilderWrapper<T> addRule(SerializableConsumer<? extends R> rule, Function<T, R> supplier) { Object test = rule.captured()[0]; if (test instanceof ColumnName) { Method accessorMethod = methodFromLambda((Class<T>) monitoredWrapped.eventClass(), supplier); ((ColumnName) test).setName(accessorMethod.getName() + " "); } ruleList.add(new Pair(rule, supplier)); return this; }
public <R> BuilderRowProcessor<T> addRule(SerializableConsumer<? extends R> rule, Function<T, R> supplier) { Object test = rule.captured()[0]; if (test instanceof ColumnName) { Method accessorMethod = methodFromLambda((Class<T>) monitoredWrapped.eventClass(), supplier); ((ColumnName) test).setName(accessorMethod.getName() + " "); } ruleList.add(new Pair(rule, supplier)); return this; }
/** * Calculate how much can be bought due to monetary restrictions. To be on the save side, if the amount is larger than * 10 items, one is deduced. * @param cash available cash * @param desiredAmount amount that is desired to be bought * @param availableAmountCity amount of the ware available in the city * @param maxAvgPrice limit of the maximal avg price to be payed per item. * @return Pair containing the affordable amount and the average price. */ @VisibleForTesting Pair<Integer, Integer> calculateAffordableAmountToBuy(IWare ware, long cash, int desiredAmount, int availableAmountCity, int maxAvgPrice) { int buyAmount = computablePrice.calculateBuyAmount(ware, availableAmountCity, maxAvgPrice, desiredAmount, cash); if (buyAmount > 10) { buyAmount--; } if (buyAmount == 0) { return new Pair<>(0, 0); } int price = computablePrice.buyPrice(ware, new SimpleIntegerProperty(availableAmountCity), new ConstantIntegerBinding(buyAmount)); return new Pair<>(buyAmount, price); }
@Override public void run() { LineSegment3DMessage[] newMessage = intersectionsMessage.getAndSet(null); // Reset both clears by using only one pipe if (clearOcTree.getAndSet(false) | clear.getAndSet(false)) { meshAndMaterialToRender.set(new Pair<>(null, null)); return; } if (!enable.get()) return; uiMessager.submitStateRequestToModule(REAModuleAPI.RequestPlanarRegionsIntersections); if (newMessage == null) return; meshBuilder.clear(); for (LineSegment3DMessage intersection : newMessage) { Point3D32 start = intersection.getStart(); Point3D32 end = intersection.getEnd(); float lineWidth = 0.01f; meshBuilder.addLine(start, end, lineWidth); } meshAndMaterialToRender.set(new Pair<Mesh, Material>(meshBuilder.generateMesh(), material)); }
/** * Figure out the ware that are most needed in the city. The need is calculated upon the knowledge * of the production, consumption and sotred amount. If a ware is not consumed at all it is not needed at * all, compared to wares that have more consumption than stored + produced. * @param knowledge base knowledge * @return sorted list Pair of wares and their importants. The lower the number the more important. */ public List<Pair<IWare, Number>> getMostNeededWares(ICityProductionConsumptionKnowledge knowledge) { Preconditions.checkNotNull(knowledge, "The city production knowledge may not be null"); List<Pair<IWare, Number>> need = new ArrayList<>(); for (IWare ware : EWare.values()) { int stored = knowledge.getStoredAmount(ware); int produced = knowledge.getProductionAmount(ware); int consumed = knowledge.getConsumptionAmount(ware); int value; if (consumed == 0) { value = Integer.MAX_VALUE; } else { value = stored + produced - consumed; } need.add(new Pair<>(ware, value)); } return need.stream().sorted(new WareNeedComparator()).collect(Collectors.toList()); }
/** * Figure out the ware that are most needed in the city. The need is calculated upon the knowledge * of the production, consumption and sotred amount. If a ware is not consumed at all it is not needed at * all, compared to wares that have more consumption than stored + produced. Also consider the amount of that ware * that is loaded on the <code>vessel</code>. That ware is treated the same way as if it stored in the city, with the * effect that on the first call the most needed ware might be BEER, but once an amount is bought the most needed ware might * change. * @param knowledge base knowledge * @param vessel on which the wares are loaded. * @return sorted list Pair of wares and their importants. The lower the number the more important. */ public List<Pair<IWare, Number>> getMostNeededWares(ICityProductionConsumptionKnowledge knowledge, INavigableVessel vessel) { List<Pair<IWare, Number>> sortedNeeds = getMostNeededWares(knowledge); for (ListIterator<Pair<IWare, Number>> iterator = sortedNeeds.listIterator(); iterator.hasNext(); ) { Pair<IWare, Number> need = iterator.next(); if (vessel.getWare(need.getKey()).getAmount() > 0) { int value = need.getValue().intValue() + vessel.getWare(need.getKey()).getAmount(); iterator.remove(); iterator.add(new Pair<>(need.getKey(), value)); } } return sortedNeeds.stream().sorted(new WareNeedComparator()).collect(Collectors.toList()); }
public static String totalRelationSvg(List<TableDefinition> tables) { final Map<String, Node> nodeMap = tables.stream().collect(Collectors.toMap(Definition::getName, table -> createReferNode(table.getName()))); final Graph g = graph("totalRelationSvg").directed() .general().attr(RankDir.LEFT_TO_RIGHT); final List<Pair<String, String>> linkedList = new ArrayList<>(); tables.forEach(table -> table.getColumns().forEach(column -> column.getForeignKeys().forEach(fkey -> { if (linkedList.contains(new Pair<>(table.getName(), fkey.getReferencedTable().getName()))) return; final Node linked = nodeMap.get(fkey.getReferencedTable().getName()); nodeMap.put(table.getName(), nodeMap.get(table.getName()).link(linked)); linkedList.add(new Pair<>(table.getName(), fkey.getReferencedTable().getName())); }))); nodeMap.forEach((name, node) -> g.node(node)); return Graphviz.fromGraph(g).createSvg(); }
/** * CReate a pair object with interface+implementation. * * @param rl the interface definition * @param re the implementation definition * * @return the pair object * * @throws ClassNotFoundException if one of the class cannot be loaded */ private static Pair<Class<?>, Class<?>> createPair(final Registration rl, final RegistrationEntry re) throws ClassNotFoundException { return new Pair<Class<?>, Class<?>>(getClassObject(rl.getClazz()), getClassObject(re.getClazz())); }
private Pair<Integer, Integer> buyWareFromCity(IPlayer player, ICity city, int availableAmountCity, IWare ware, long cash, int amountToBuy, int maxAvgPrice) { Pair<Integer, Integer> affordable = calculateAffordableAmountToBuy(ware, cash, amountToBuy, availableAmountCity, maxAvgPrice); amountToBuy = affordable.getKey(); int avgPriceCompleteAmount = affordable.getValue(); if (amountToBuy == 0) { return new Pair<>(0, 0); } int movedAmount = city.move(ware, -amountToBuy, player); if (amountToBuy != -movedAmount) { avgPriceCompleteAmount = computablePrice.buyPrice(ware, new SimpleIntegerProperty(city.getWare(ware).getAmount() + movedAmount), new ConstantIntegerBinding(movedAmount)); amountToBuy = -movedAmount; } return new Pair<>(amountToBuy, avgPriceCompleteAmount); }
private void processOccupancyMapMessage(FootstepPlannerOccupancyMapMessage message) { palette.clearPalette(); JavaFXMultiColorMeshBuilder meshBuilder = new JavaFXMultiColorMeshBuilder(palette); Object<FootstepPlannerCellMessage> occupiedCells = message.getOccupiedCells(); for (int i = 0; i < occupiedCells.size(); i++) { FootstepPlannerCellMessage cell = occupiedCells.get(i); double x = cell.getXIndex() * FootstepNode.gridSizeXY; double y = cell.getYIndex() * FootstepNode.gridSizeXY; double z = getHeightAtPoint(x, y) + nodeOffsetZ; RigidBodyTransform transform = new RigidBodyTransform(); transform.setTranslation(x, y, z); if (cell.getNodeIsValid()) meshBuilder.addPolygon(transform, cellPolygon, validCellColor); else meshBuilder.addPolygon(transform, cellPolygon, rejectedCellColor); } footstepGraphToRender.set(new Pair<>(meshBuilder.generateMesh(), meshBuilder.generateMaterial())); }
private Pair<Mesh, Material> generateMeshAndMaterial(PlanarRegionsListMessage newMessage) { meshBuilder.clear(); double lineWidth = 0.01; RigidBodyTransform transformToWorld = new RigidBodyTransform(); PlanarRegionsList planarRegionsList = PlanarRegionMessageConverter.convertToPlanarRegionsList(newMessage); for (int regionIndex = 0; regionIndex < planarRegionsList.getNumberOfPlanarRegions(); regionIndex++) { PlanarRegion planarRegion = planarRegionsList.getPlanarRegion(regionIndex); int regionId = planarRegion.getRegionId(); Color regionColor = getRegionColor(regionId); planarRegion.getTransformToWorld(transformToWorld); meshBuilder.addMultiLine(transformToWorld, planarRegion.getConcaveHull(), lineWidth, regionColor, true); for (int polygonIndex = 0; polygonIndex < planarRegion.getNumberOfConvexPolygons(); polygonIndex++) { ConvexPolygon2D convexPolygon2d = planarRegion.getConvexPolygon(polygonIndex); regionColor = Color.hsb(regionColor.getHue(), 0.9, 0.5 + 0.5 * ((double) polygonIndex / (double) planarRegion.getNumberOfConvexPolygons())); meshBuilder.addPolygon(transformToWorld, convexPolygon2d, regionColor); } } Material material = meshBuilder.generateMaterial(); Mesh mesh = meshBuilder.generateMesh(); return new Pair<>(mesh, material); }