⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calculator.java

📁 ajax patterns 这是关于ajax设计模式方面的原代码
💻 JAVA
字号:
/*
    Copyright 2006 Christian Gross http://www.devspace.com
    From the book Ajax Patterns and Best Practices

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package devspace.ajax.infinitedata.primenumbercalculator;
import devspace.ajax.infinitedata.*;

public class Calculator implements Task {
    private String _transactionIdentifier;
    
    public String getTransactionIdentifier() {
        return _transactionIdentifier;
    }
    public void setTransactionIdentifier( String transactionIdentifier) {
        _transactionIdentifier = transactionIdentifier;
    }
    public boolean isPrime( long number) {
        long halfvalue = number / 2 + 1;
        for( long c1 = 2; c1 <= halfvalue; c1 ++) {
            long result;
            result = number % c1;
            if( result == 0) {
                return false;
            }
        }
        return true;
    }
    public void execute( TaskManager mgr) {
        for( int c1 = 2; c1 <= _number; c1 ++) {
            if( isPrime( c1)) {
                mgr.addResult( new PrimeNumberData( c1, _transactionIdentifier));
            }
        }
        //mgr.addResult( new PrimeNumberData().assignLast());
    }
    
    private long _number;
    
    public Calculator( long number, String transactionIdentifier) {
        if( number < 1) {
            throw new IndexOutOfBoundsException( "Number must be greater than 0");
        }
        // I am limiting this! Sorry for those that like to be clever!
        if( number > 50) {
            number = 50;
        }
        _number = number;
        _transactionIdentifier = transactionIdentifier;
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -