Conditional binding fails with fracture from scratch using the fluent API

I have two properties that I want to connect to a progress bar. Properties represent essentially a max value of County (the denominator) and current value of the Shire (numerator). I want to set up a connection using the fluent API that works roughly as follows:
IntegerProperty numerator = new SimpleIntegerProperty(0);
IntegerProperty denominator = new SimpleIntegerProperty(0);

progressBar.progressProperty().bind(
    Bindings.when(denominator.isEqualTo(0))
        .then(0)
        .otherwise(numerator.divide(denominator)));
The numerator and denominator properties represent two properties in my object that changes according to certain criteria in the application, and I want the progress bar to be bound by these changes. The problem is sometimes, and by default, the value of the denominator is 0. My logic tells me that the clause otherwise() does not run, because the when() condition must be true and so run the then() clause. When I run the above code, I get an ArithmeticException (/ by zero).

Question - is this the correct behavior of the code underlying link? I don't understand why the otherwise() clause is being evaluated in this case.
Can I suggest an improvement to short-circuit the logic to avoid such a situation?

My solution is to create a custom as follows DoubleBinding:
IntegerProperty numerator = new SimpleIntegerProperty(0);
IntegerProperty denominator = new SimpleIntegerProperty(0);

DoubleBinding db = new DoubleBinding() {
    { super.bind(numerator, denominator); }
 
    @Override
    protected double computeValue() {
        if(denominator.getValue() == 0) {
            return 0.0;
        }
        return numerator.doubleValue() / denominator.doubleValue();
    }
};
        
progressBar.progressProperty().bind(db);
I would much rather the fluent API (much less code to write and much more elegant), but I'm glad that the custom binding is not too difficult to write and understand.

Thanks for all comments or impressions.

I have not tested, but for a workaround, you can try

progressBar.progressProperty().bind(
    Bindings.when(denominator.isEqualTo(0))
        .then(0)
        .otherwise(numerator.divide(denominator.doubleValue())));

This will force (should) the division must be calculated using double rather than the integers (ints); x / 0,0 will assess double. NaN in java, without throwing an exception. Note that this calculation will give slightly different results in other cases, such as the division of integers you used before will still result in an int (by truncation); considering that it will give a double precision division. In most cases, the latter will actually be what you want.

Tags: Java

Similar Questions

  • use restart from scratch using the option "ALT F10" and lose everything. Help, please!

    Whenever I try to connect my laptop, a screen invites me to do a repair of launch set-up. It goes through the motions for ten minutes and the screen turns white. The only way I can get at all is to restart all from scratch using the option "ALT F10" and lose everything. Any advice I would really appreciate.

    Hello

    1. Since when are you facing this problem?
    2. You did any recent changes?
    3. What version of Windows is installed on the computer?

    I suggest that you go into recovery options and try to perform system restore and see if it helps:
    http://Windows.Microsoft.com/en-us/Windows7/what-are-the-system-recovery-options-in-Windows-7
    http://Windows.Microsoft.com/en-us/Windows-Vista/what-are-the-system-recovery-options-in-Windows-Vista

    Otherwise, I suggest you to give us more information, so that we can better help you.

    It will be useful.

  • to replace '-' with ' / ' in a string using the FrameMaker API

    How to replace "\folder1\folder2\folder3" by "Folder1/Folder2/folder3" using the framemaker API?

    Hi Asha,

    It should work as well. Note the following, however:

    -your version will be case-sensitive, always which is OK for what you wanted

    -Maybe you left a code, but what you have shown is missing some important steps of allocation/deallocation for use with F_StrCat(). You need to allocate more space before the concatenation of strings and to release all pointers unused when or before you use them again. It might work for now, but I can assure you that inadequate allocation routines are a sure path to memory leaks and crashes in the future.

    Russ

  • Is there a way to extract the data from form using the Eloqua API?

    I'm looking to export all the data stored in any of my forms to treat elsewhere. Y at - it a facility within the API that will allow me to perform this export? For what I saw on the forum, the BulkDataTransfer service used to do this, however, is not available on Eloqua 10 and the beta version does not include this feature?

    See you soon!

    This is an old question, but for those who find themselves on this page, your best bet now is to export activity data submission of form through the REST in bulk API v2.0 (Bulk API v2.0 Documentation).

  • OCIEnvCreate failed with return code-1, but the text of the error message was not available. »

    OCIEnvCreate failed with return code-1, but the text of the error message was not available. »

    I get this message (error) after update my customer Oracle 9.0 to 10.1 (used in the .net Oracle connection)

    I would like to get a resolution? If someone has experiece with her.

    THX

    Hello

    To improve assistance to this subject, you can ask your question in the MSDN Forums.

    NET Framework

    http://social.msdn.Microsoft.com/forums/en-us/category/netdevelopment

  • Error failed with error 0 x 80070424: the specified service does not exist as an installed service.

    I have DSL and a wireless printer that work well when the system starts; EXCEPT the desktop icons disappeared so I can't manage them! If I stop DSL through the system icons, I get the following error messages when I try to restart or to solve problems: do you know what are the services that I need to install/reboot?

    Diagnosis of network adapter

    Network location detection

    Info Using the Internet connection at home

    Identification of network adapter

    error Failed with error 0 x 80070424: the specified service does not exist as an installed service.

    HTTP, HTTPS, FTP Diagnostic

    HTTP, HTTPS, FTP connectivity

    warn HTTP: Error 12007 connecting to www.microsoft.com: the server name or address cannot be resolved
    warn HTTPS: Error 12007 connecting to www.microsoft.com: the server name or address cannot be resolved
    warn FTP (passive): error 12007 connecting to FTP.Microsoft.com: the server name or address cannot be resolved
    warn HTTP: Error 12007 connecting to www.hotmail.com: the server name or address cannot be resolved
    warn FTP (active): error 12007 connecting to FTP.Microsoft.com: the server name or address cannot be resolved
    warn HTTPS: Error 12007 connecting to www.passport.net: the server name or address cannot be resolved
    error Could not make an HTTP connection.
    error Could not make an HTTPS connection.
    error Could not make an FTP connection.

    Diagnosis of last run time: 16/05/12 16:09:47

    Diagnosis of network adapter

    Network location detection

    Info Using the Internet connection at home

    Identification of network adapter

    error Failed with error 0 x 80070424: the specified service does not exist as an installed service.

    HTTP, HTTPS, FTP Diagnostic

    HTTP, HTTPS, FTP connectivity

    warn HTTP: Error 12007 connecting to www.microsoft.com: the server name or address cannot be resolved
    warn HTTPS: Error 12007 connecting to www.microsoft.com: the server name or address cannot be resolved
    warn FTP (passive): error 12007 connecting to FTP.Microsoft.com: the server name or address cannot be resolved
    warn HTTP: Error 12007 connecting to www.hotmail.com: the server name or address cannot be resolved
    warn HTTPS: Error 12007 connecting to www.passport.net: the server name or address cannot be resolved
    warn FTP (active): error 12007 connecting to FTP.Microsoft.com: the server name or address cannot be resolved
    error Could not make an HTTP connection.
    error Could not make an HTTPS connection.
    error Could not make an FTP connection.

    Thanks for your attempt to solve my problem.

    Curiously he solved my problem of network while solving what has proved to be a problem with the firewall of Windows (see below): who knew?

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_xp-Security/Windows-XP-Security-Service-Center-error-1060-and/1476c2b6-8161-4ccd-a69f-93292b5152da

  • Can I get the total number of records that meet the conditions of a query using the Table API?

    Hello

    A < row > TableIterator is returned when I ask operations using the index of tables. If I want to get the total number of records, I count one by one using the returned TableIterator < row >.


    Can I get the total number of records directly meets the conditions of the query?

    I can get the total number of records directly the request of the meeting of the conditions of CLI using the command Global table - name tableName - count - index index-name-field fieldName - start startValue-end endValue.

    Can I get the same results using the Table API?

    I used MongoDB and NoSQL Oracle for about a year. According to the experience of the use of these dbs, I think mongoDB querying interface is powerful. In the contras, the query interface is relatively simple, which results is a lot of work that is usually a long time in the client side.

    Hello

    Counting records in a database is a tricky thing.  Any system that gives you an accurate count of the records will have a hotspot of concurrency on updates, namely the place where the counting is maintained.  Such a count is a problem of performance in addition to competitive access problem.   The problem is even more difficult in a system widely distributed such a NoSQL database.

    The CLI has overall command that counts, but does so by brutal force - iterate keys that correspond to the parameters of the operation.  This is how you must do this within the API.  There is not a lot of code, but you have to write.  You certainly want to use TableIterator TableAPI.tableKeysIterator (), because a key iteration is significantly faster than the iteration of lines.  Just one iteration and count.

    If you use TableAPI.multiGet () and a key with a touch of brightness full then, in fact, count the results as they are returned in a single piece (a list).

    Kind regards

    George

  • Using the REST API to delete the contact from the contacts list

    Hello world

    I am looking for some info for the creation of a request to delete a contact from a list of Contact using the REST API.   Here's what I have in Java where the contact id is 1 'and my list is 72'.     I'm open to responses in Java, c# or other languages.

    serverAddress = new URL ("https://secure.p03.eloqua.com/API/REST/1.0/assets/contact/list/72");

    establish communication stuff

    connection = null;

    Set up the initial connection

    connection = (HttpURLConnection) serverAddress.openConnection ();

    connection.setRequestMethod ("PUT");

    connection.setRequestProperty ("content-type", "json; charset=utf-8 ");"

    connection.setRequestProperty ("authorization", 'Basic BLOCKED');

    String body = '{\"membershipDeletions\":[\"1\']}";

    connection.setDoOutput (true);

    connection.getOutputStream () .write (body.getBytes ("UTF8"));

    connection.setReadTimeout (10000);

    Connection.Connect ();

    When I test with it I get a '400' HTTP response

    Thank you!

    Hi Noel,

    The following document describes the operations available for lists of contacts in the Rest API. Please note that we also have a project open source c# example illustrates the use of these endpoints.

    Repositories are all available to the public on Github. Hope this helps and please let me know if you need more information.

    Thank you

    Fred

  • Smart card reader does not correctly connect once the virtual machine is restored from sleep using the vmrum controls

    Smart card reader does not correctly connect once the virtual machine is restored from sleep using the vmrum controls

    Scenario is,

    1. smart card reader is connected to the VM with card inserted in

    2 initiate a prompt suspension of the VM toolbar

    3. now to resume the virtual machine by using vmrun command into the host machine

    WS t vmrun start xxx.vmx

    Now, the recovery of VM but the smart card reader that was previously connected does not work properly in VM that is to say, sometimes after CV chip card reader driver is uninstalling and a few other times, chip connected to the drive is not available on a virtual computer

    My requirement is after power, smart card reader can stay connected to the virtual computer with the already installed driver and the smart card.

    Kindly help with this problem.

    Host operating system: Victoire 2012 R2

    The VM OS: win 10 x 64

    Thank you!!

    Dear all,

    I had a work around for this problem. By adding "usb.autoConnect.device0 ="0xVID:0xPID"" this statement to the VMX file, solves this problem, that is, whenever the VM is wake-up by clicking on the link CV or using vmrun commands, it connects the unit in question automatically and it is charging correctly with his driver. Obtaining smart card detected after sleep\hibernate with no problems.

    VID & PID is respective ID of the device that can be seen in the properties of the Device Manager "Device Instance path".

    For more information about this, visit VMware KB: automatic connection of USB devices to the virtual machine power on

    ~ Surendra

  • Run the workflow using the SOAP API with PHP

    Hello

    I'm trying to integrate workflow from code PHP using the SOAP API to Orchestrator.

    <? PHP

    Try

    {

    $parameters = array (username = > "username", password = > "passwd");

    $client = new SoapClient ('https://vcoserver:8281 / vco/vmware-vmo-webcontrol/webservice?) WSDL "); "

    $result = $client-> getAllWorkflows ($parameters);

    foreach ($result as $item)

    {

    foreach ($item as $work)

    {

    echo $work-> name;

    echo "< br >".

    echo "id";

    echo $work-> id;

    echo "< br / > ';

    }

    }

    }

    catch (Exception $e)

    {

    echo $e;

    }

    ? >

    I do not see errors/exceptions, but don't see any output as well.

    Am I missing something?

    Could you use

    print curl_error($curl);
    

    After curl_exec to check if there are errors?

    If there is an error in SSL certificate, as ' SSL certificate problem: unable to get local issuer certificate ", you can either install certificates roots (Google it for more information how to do), or disable checking of certificates by peers in CURL with something like:"

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    
  • Lightroom starts but then I get "error reading the preview cache. LR needs to stop smoking.  Will try next time it starts. I restart from scratch and the same thing happens.  Help please!

    Lightroom starts but then I get "error reading the preview cache. LR needs to stop smoking.  Will try next time it starts. I restart from scratch and the same thing happens.  Help please!

    In the same folder that your catalog file is stored in, there is a subfolder whose name ends with Previews.LRDATA. Delete this subfolder whose name ends with Previews.LRDATA. Do not remove anything else.

  • printing with printer deskjet 2050 using the black cartridge only

    printing with printer deskjet 2050 using the black cartridge only

    all solutions? PLIs answer me. thanx

    Hi d33com,

    Follow the steps below to set the black ink only.

    1. open the printing preferences (step 1)

    2. click on the Advanced button (step 2)

    3. click on the drop down arrow next to the print in grayscale to change black ink only.

  • How to connect from Twitter (using the API of Twitter ME v 1.9)?

    Hello..

    I am doing an application with twitter and I use the API Twitter ME v1.9

    I am already able to post tweet with her... But is it possible to log on to the twitter application?

    Kind regards

    Eric

    Why not.. When you save the access token. You use any file Storetoken.java for the registration of access token. You can have a method to clear the access token...

  • I have two Adobe Id with first ID, I used the trial version. When it expired, I did the second ID and purchased Adobe Acrobat proDC version with monthly subscription. On my first ID it shows now that I have Acrobat pro DC subscription. Second ID (the one

    I have two Adobe Id with first ID, I used the trial version. When it expired, I did the second ID and purchased Adobe Acrobat proDC version with monthly subscription. On my first ID it shows now that I have Acrobat pro DC subscription. Second ID (the one I bought the subscription) shows nothing. Now, during installation by using the ID of the first, all is going well, except using the software. He always says "your trial has expired! Using the ID of the second to make same duration does not work... I can't download the right version. Free trial only. Pleasehelp me. I'm desperate.

    Hi kimmok51975897,

    I will recommend you to contact our customer service team to get this fixed number. Follow this link Contact Customer Care, sign in using your Adobe ID (under which you subscription) & check on "still need help? Contact us' button.

    Kind regards
    Nicos

  • Workflow of vCO of query using the REST API in PowerShell

    Hello

    I am interrogating a workflow vCO by name using the REST API of PowerShell based on this article:

    http://www.vcoteam.info/articles/learn-VCO/268-how-to-use-the-rest-API-to-start-a-workflow.html

    $username = "XXXXXX".

    $upassword = "XXXXXX".

    $auth = $username + ':' + $upassword

    $Encoded = [System.Text.Encoding]: UTF8. GetBytes ($auth)

    $EncodedPassword = [System.Convert]: ToBase64String ($Encoded)

    $headers = @{' authorization '=' basic $($EncodedPassword) ' ;}}

    $body = "<-xmlns = execution context" ". ' http://www.VMware.com/VCO ' > < / execution context > '

    #query for workflow named "donothing".

    Invoke-RestMethod-uri https://XXXX:8281/api/flow /? conditions = name = donothing -Headers $headers - body $body - ContentType "application/xml" - Get method

    Invoke RestMethod: failed to send a content-body with this type of verb.

    On line: 1 char: 1

    + Call-RestMethod-uri https://XXXX:8281/api/flow /? conditions = name = donoth ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo: NotSpecified: (:)) [invoking-RestMethod], ProtocolViolationException)

    + FullyQualifiedErrorId: System.Net.ProtocolViolationException, Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    The request succeeds by using the customer REMAINS on Firefox, but I can't make it work on PowerShell. (NOTE: PowerShell workflow execution works very well)

    Any help is appreciated.

    Thank you

    Juan.

    OK, I managed to do work by removing

    [System.Net.ServicePointManager]: ServerCertificateValidationCallback = {$true}

    And add this at the beginning of the script

    "Add-type @ '.

    using System.Net;

    using System.Security.Cryptography.X509Certificates;

    public class TrustAllCertsPolicy: {ICertificatePolicy

    public bool CheckValidationResult)

    ServicePoint srvPoint, X509Certificate certificate,

    WebRequest request, int certificateProblem) {}

    Returns true;

    }

    }

    "@

    [System.Net.ServicePointManager]: CertificatePolicy = New-Object TrustAllCertsPolicy

    Now I can use the GET method:

    $ret = Invoke-WebRequest - uri $URL - Headers $headers - ContentType "application/xml" - Get method

    I spent to Invoke-WebRequest so I can get the return of application Web.

    Juan.

Maybe you are looking for

  • How can I change my bookmarks list?

    How can I delete an ad on my page of bookmarks?  Thank you.

  • Equium A100 Win XP PSAABE - Sound Jittery & slow start / running

    Equium A100PSAABEWindows XP Help please. I had a recurring injury that have begun to appear immediately after a Windows update Auto + reboot.Stutters sound on the PC (on any application) and is very nervous and the PC starts and runs very slowly.Anti

  • Unable to connect to the Web format

    I have a user who cannot connect to Webview.The passwords and permissions have not changed. The user was able to connect earlier and view reports, but now it shows an error "you are not authorized to view the page. We tried the URL http://webviewserv

  • IPS 6.1 and ASA / versions ASDM

    I've upgraded to the latest version 6.1 for my IPS module, but now I can't get the IPS via the ASDM or IME config. I can however at the CLI. I have to upgrade my ASDM on the ASA, ASA, or both? I have included a copy of the IME of logs. I also have th

  • Administrator cannot access folders in Windows 7

    I have a new computer and I am the administrator. I've implemented a new guest account and he was denied access to a folder. However, the administrator can no longer access this folder at all. Even when the administrator account can access the folder