fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. @ThreadSafe
  8. public class CachedFactorizer implements Servlet {
  9. @GuardedBy("this") private BigInteger lastNumber;
  10. @GuardedBy("this") private BigInteger[] lastFactors;
  11. @GuardedBy("this") private long hits;
  12. @GuardedBy("this") private long cacheHits;
  13.  
  14. public synchronized long getHits() { return hits; }
  15. public synchronized double getCacheHitRatio() {
  16. return (double) cacheHits / (double) hits;
  17. }
  18.  
  19. public void service(ServletRequest req, ServletResponse resp) {
  20. BigInteger i = extractFromRequest(req);
  21. BigInteger[] factors = null;
  22. synchronized (this) {
  23. ++hits;
  24. if (i.equals(lastNumber)) {
  25. ++cacheHits;
  26. factors = lastFactors.clone();
  27. }
  28. }
  29. if (factors == null) {
  30. factors = factor(i);
  31. synchronized (this) {
  32. lastNumber = i;
  33. lastFactors = factors.clone();
  34. }
  35. }
  36. encodeIntoResponse(resp, factors);
  37. }
  38. }
  39.  
  40.  
  41.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:8: error: class CachedFactorizer is public, should be declared in a file named CachedFactorizer.java
public class CachedFactorizer implements Servlet {
       ^
Main.java:8: error: cannot find symbol
public class CachedFactorizer implements Servlet {
                                         ^
  symbol: class Servlet
Main.java:7: error: cannot find symbol
@ThreadSafe
 ^
  symbol: class ThreadSafe
Main.java:9: error: cannot find symbol
    @GuardedBy("this") private BigInteger lastNumber;
                               ^
  symbol:   class BigInteger
  location: class CachedFactorizer
Main.java:10: error: cannot find symbol
    @GuardedBy("this") private BigInteger[] lastFactors;
                               ^
  symbol:   class BigInteger
  location: class CachedFactorizer
Main.java:19: error: cannot find symbol
    public void service(ServletRequest req, ServletResponse resp) {
                        ^
  symbol:   class ServletRequest
  location: class CachedFactorizer
Main.java:19: error: cannot find symbol
    public void service(ServletRequest req, ServletResponse resp) {
                                            ^
  symbol:   class ServletResponse
  location: class CachedFactorizer
Main.java:9: error: cannot find symbol
    @GuardedBy("this") private BigInteger lastNumber;
     ^
  symbol:   class GuardedBy
  location: class CachedFactorizer
Main.java:10: error: cannot find symbol
    @GuardedBy("this") private BigInteger[] lastFactors;
     ^
  symbol:   class GuardedBy
  location: class CachedFactorizer
Main.java:11: error: cannot find symbol
    @GuardedBy("this") private long hits;
     ^
  symbol:   class GuardedBy
  location: class CachedFactorizer
Main.java:12: error: cannot find symbol
    @GuardedBy("this") private long cacheHits;
     ^
  symbol:   class GuardedBy
  location: class CachedFactorizer
Main.java:20: error: cannot find symbol
        BigInteger i = extractFromRequest(req);
        ^
  symbol:   class BigInteger
  location: class CachedFactorizer
Main.java:21: error: cannot find symbol
        BigInteger[] factors = null;
        ^
  symbol:   class BigInteger
  location: class CachedFactorizer
13 errors
stdout
Standard output is empty