Example #1
0
  @Test(timeout = 700)
  public void alterOutput() throws Exception {

    C c = new C();
    c.addListener(
        new Listener() {

          @Override
          public void notice(Type T, EventObject E) {
            if (T == Type.OUT) {
              DataflowEvent ce = (DataflowEvent) E;
              if (ce.getValue() instanceof Double) {
                assertEquals(1.2, ce.getValue());
                ce.setValue(new Double(3.2));
              }
              // System.out.println(" ---- " + ce.getValue() + " " +
              // ce.getValue().getClass());
            }
          }
        });
    c.in = "1";
    c.execute();
    // System.out.println(c.get(c.op2, "cmdOut"));
    assertEquals("CMD2(3.2)", c.out);
  }
 /**
  * Applies a {@link SecurityConfigurerAdapter} to this {@link SecurityBuilder} and invokes {@link
  * SecurityConfigurerAdapter#setBuilder(SecurityBuilder)}.
  *
  * @param configurer
  * @return
  * @throws Exception
  */
 @SuppressWarnings("unchecked")
 public <C extends SecurityConfigurerAdapter<O, B>> C apply(C configurer) throws Exception {
   configurer.addObjectPostProcessor(objectPostProcessor);
   configurer.setBuilder((B) this);
   add(configurer);
   return configurer;
 }
Example #3
0
  @Test
  public void testNumberFormatException() {
    config.put("section.string", "notanumber");

    exception.expect(IllegalArgumentException.class);
    config.get("section.string", Integer.class);
  }
  /**
   * Swap in a new Cursor, returning the old Cursor. Unlike {@link #changeCursor(AbstractCursor)},
   * the returned old Cursor is <em>not</em> closed.
   *
   * @param newCursor The new cursor to be used.
   * @return Returns the previously set Cursor, or null if there wasa not one. If the given new
   *     Cursor is the same instance is the previously set Cursor, null is also returned.
   */
  public C swapCursor(C newCursor) {
    if (newCursor == mCursor) {
      return null;
    }

    C oldCursor = mCursor;
    if (oldCursor != null) {
      if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver);
      if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver);
    }

    mCursor = newCursor;
    if (newCursor != null) {
      if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver);
      if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver);
      mDataValid = true;
      // notify the observers about the new cursor
      onContentChanged();
    } else {
      mDataValid = false;
      // notify the observers about the lack of a data set
      onContentChanged();
    }

    return oldCursor;
  }
  /**
   * Processes a new connection making it idle or active depending on whether requests are waiting
   * to be sent.
   *
   * <p>A new connection is created when a request needs to be executed; it is possible that the
   * request that triggered the request creation is executed by another connection that was just
   * released, so the new connection may become idle.
   *
   * <p>If a request is waiting to be executed, it will be dequeued and executed by the new
   * connection.
   *
   * @param connection the new connection
   */
  public void process(final C connection) {
    HttpClient client = getHttpClient();
    final HttpExchange exchange = getHttpExchanges().poll();
    if (LOG.isDebugEnabled())
      LOG.debug("Processing exchange {} on {} of {}", exchange, connection, this);
    if (exchange == null) {
      if (!connectionPool.release(connection)) connection.close();

      if (!client.isRunning()) {
        if (LOG.isDebugEnabled()) LOG.debug("{} is stopping", client);
        connection.close();
      }
    } else {
      final Request request = exchange.getRequest();
      Throwable cause = request.getAbortCause();
      if (cause != null) {
        if (LOG.isDebugEnabled()) LOG.debug("Aborted before processing {}: {}", exchange, cause);
        // It may happen that the request is aborted before the exchange
        // is created. Aborting the exchange a second time will result in
        // a no-operation, so we just abort here to cover that edge case.
        exchange.abort(cause);
      } else {
        send(connection, exchange);
      }
    }
  }
Example #6
0
  private Action<?> walk(AmObject cobj) {

    Action<?> action = visitor.preorderVisit(cobj, context);
    if (action == null) action = Action.next();

    final AmObject walkObj = extractWalkObject(cobj, action);
    if (walkObj != null) {
      // walk children
      UpdatingIterator it = getChildrenOf(walkObj);
      context.getAmParents().addLast(walkObj);
      while (it.hasNext()) {
        AmObject child = it.next();
        Action<?> childAction = walk(child);
        processAction(childAction, it);
      }
      context.getAmParents().removeLast();
    }

    Action<?> postAction =
        visitor.postorderVisit(walkObj != null ? walkObj : cobj, context, action);
    if (postAction == null) postAction = Action.next;

    action = action.mergeWith(postAction);
    return action;
  }
 /** @return the sum of the values of all the counters for e. */
 public final long sum(final E e) {
   long sum = 0;
   for (C c : counts.values()) {
     sum += c.get(e);
   }
   return sum;
 }
Example #8
0
 public RangePred(C low, C high) {
   if (low.doubleValue() > high.doubleValue()) {
     throw new IllegalArgumentException("low can not be higher than high");
   }
   this.low = low;
   this.high = high;
 }
Example #9
0
  @Test
  public void testNullValue() {
    config.put("section.null", null);

    Optional<String> str = config.get("section.null");
    assertFalse(str.isPresent());
  }
Example #10
0
 /**
  * @param id
  * @return
  */
 public String getListenersAsHtmlFragment(I id) {
   String ret = "";
   C ci = commInfo.get(id);
   MessageListener<Mi, M> lastListenerForCom = ci.getLastListener();
   if (ci != null) {
     boolean first = true;
     for (MessageListener<Mi, M> lst : ci.getListeners()) {
       if (!first) ret += "<br>";
       else first = false;
       ret += lst.getClass().getName() + " [" + Integer.toHexString(lst.hashCode()) + "]";
       // ret += lst.getClass().getSimpleName() + " [" + Integer.toHexString(lst.hashCode()) + "]";
       if (useListenersQueues) {
         try {
           ret += " {" + ci.getListenersQueueProvider().get(lst).getMessageCount() + " msgs}";
         } catch (Exception e) {
           NeptusLog.pub().warn(this.getClass().getSimpleName(), e);
         }
       }
       if (lastListenerForCom == lst) {
         ret += " working";
       }
     }
   }
   return ret;
 }
Example #11
0
 /**
  * Refine interval.
  *
  * @param iv root isolating interval with f(left) * f(right) &lt; 0.
  * @param f univariate polynomial, non-zero.
  * @param eps requested interval length.
  * @return a new interval v such that |v| &lt; eps.
  */
 public Interval<C> refineInterval(Interval<C> iv, GenPolynomial<C> f, C eps) {
   if (f == null || f.isZERO() || f.isConstant() || eps == null) {
     return iv;
   }
   if (iv.length().compareTo(eps) < 0) {
     return iv;
   }
   RingFactory<C> cfac = f.ring.coFac;
   C two = cfac.fromInteger(2);
   Interval<C> v = iv;
   while (v.length().compareTo(eps) >= 0) {
     C c = v.left.sum(v.right);
     c = c.divide(two);
     // System.out.println("c = " + c);
     // c = RootUtil.<C>bisectionPoint(v,f);
     if (PolyUtil.<C>evaluateMain(cfac, f, c).isZERO()) {
       v = new Interval<C>(c, c);
       break;
     }
     Interval<C> iv1 = new Interval<C>(v.left, c);
     if (signChange(iv1, f)) {
       v = iv1;
     } else {
       v = new Interval<C>(c, v.right);
     }
   }
   return v;
 }
Example #12
0
 /**
  * @param parameter
  * @param type
  * @return convert-value
  */
 private Object numberToPrimitive(final Number parameter, final Class<?> type) {
   final C c = map.get(type);
   if (c != null) {
     return c.convert(parameter);
   }
   return parameter;
 }
Example #13
0
 /**
  * Called by the base class to add attributes to the meta data.
  *
  * @param metaData the meta data instance receiving the attributes.
  * @param ebXML the ebXML instance containing the attributes.
  */
 protected void addAttributesFromEbXML(C metaData, E ebXML) {
   metaData.setComments(ebXML.getDescription());
   metaData.setTitle(ebXML.getName());
   metaData.setEntryUuid(ebXML.getId());
   metaData.setLogicalUuid(ebXML.getLid());
   metaData.setVersion(ebXML.getVersionInfo());
 }
Example #14
0
  public static final <T, C extends Collection<T>> C set(
      final C collection, @SuppressWarnings("unchecked") final T... elements) {
    collection.clear();
    collection.addAll(Arrays.asList(elements));

    return collection;
  }
Example #15
0
 public void testProperties() {
   // Config.TABLES.add(User.class);
   float density = Tools.getDensity(getContext());
   int width = (int) (220 * density);
   int height = (int) (120 * density);
   XLog.e(TAG, "density: " + density);
   XLog.e(TAG, "width: " + width);
   XLog.e(TAG, "height: " + height);
   System.out.println("density: " + density);
   System.out.println("width: " + width + "," + Tools.dip2px(getContext(), 220));
   System.out.println("height: " + height + "," + Tools.dip2px(getContext(), 120));
   List<String> list = new ArrayList<String>();
   list.add("A");
   list.add("B");
   list.add("我爱中国");
   C c = new C();
   c.id = 222;
   c.name = "zs";
   c.list = list;
   Gson gson = new Gson();
   String jsonStr = gson.toJson(c);
   System.out.println(jsonStr);
   C cc = gson.fromJson(jsonStr, C.class);
   System.out.println(cc);
   try {
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #16
0
 /**
  * Real root bound. With f(M) * f(-M) != 0.
  *
  * @param f univariate polynomial.
  * @return M such that -M &lt; root(f) &lt; M.
  */
 public C realRootBound(GenPolynomial<C> f) {
   if (f == null) {
     return null;
   }
   RingFactory<C> cfac = f.ring.coFac;
   C M = cfac.getONE();
   if (f.isZERO() || f.isConstant()) {
     return M;
   }
   C a = f.leadingBaseCoefficient().abs();
   for (C c : f.getMap().values()) {
     C d = c.abs().divide(a);
     if (M.compareTo(d) < 0) {
       M = d;
     }
   }
   // works also without this case, only for optimization
   // to use rational number interval end points
   // can fail if real root is in interval [r,r+1]
   // for too low precision or too big r, since r is approximation
   if ((Object) M instanceof RealAlgebraicNumber) {
     RealAlgebraicNumber Mr = (RealAlgebraicNumber) M;
     BigRational r = Mr.magnitude();
     M = cfac.fromInteger(r.numerator()).divide(cfac.fromInteger(r.denominator()));
   }
   M = M.sum(f.ring.coFac.getONE());
   // System.out.println("M = " + M);
   return M;
 }
 private double selectDeath(RandomGenerator e, C conf, M modif, double[] out) {
   int size = conf.size(clazz);
   if (size < this.n) {
     return 0.;
   }
   int denom = 1;
   int d[] = new int[this.n];
   for (int i = 0; i < this.n; ++i, --size) {
     d[i] = (size == 1) ? 0 : sample(e, size);
     for (int j = 0; j < i; ++j) if (d[j] <= d[i]) ++d[i]; // skip already selected indices
     for (int j = 0; j < i; ++j)
       if (d[j] == d[i]) {
         LOGGER.error("sampled " + d[i] + " twice");
       }
     Iterator<T> it = conf.iterator(clazz);
     for (int j = 0; j < d[i]; j++) {
       it.next();
     }
     T t = it.next();
     modif.insertDeath(t);
     double[] outTmp = new double[this.builder.size()];
     this.builder.setCoordinates(t, outTmp);
     for (int j = 0; j < this.builder.size(); j++) {
       out[i * this.builder.size() + j] = outTmp[j];
     }
     denom *= size;
   }
   return 1. / (double) denom;
 }
Example #18
0
  /**
   * Invariant interval for algebraic number magnitude.
   *
   * @param iv root isolating interval for f, with f(left) * f(right) &lt; 0.
   * @param f univariate polynomial, non-zero.
   * @param g univariate polynomial, gcd(f,g) == 1.
   * @param eps length limit for interval length.
   * @return v with v a new interval contained in iv such that |g(a) - g(b)| &lt; eps for a, b in v
   *     in iv.
   */
  public Interval<C> invariantMagnitudeInterval(
      Interval<C> iv, GenPolynomial<C> f, GenPolynomial<C> g, C eps) {
    Interval<C> v = iv;
    if (g == null || g.isZERO()) {
      return v;
    }
    if (g.isConstant()) {
      return v;
    }
    if (f == null || f.isZERO() || f.isConstant()) { // ?
      return v;
    }
    GenPolynomial<C> gp = PolyUtil.<C>baseDeriviative(g);
    // System.out.println("g  = " + g);
    // System.out.println("gp = " + gp);
    C B = magnitudeBound(iv, gp);
    // System.out.println("B = " + B);

    RingFactory<C> cfac = f.ring.coFac;
    C two = cfac.fromInteger(2);

    while (B.multiply(v.length()).compareTo(eps) >= 0) {
      C c = v.left.sum(v.right);
      c = c.divide(two);
      Interval<C> im = new Interval<C>(c, v.right);
      if (signChange(im, f)) {
        v = im;
      } else {
        v = new Interval<C>(v.left, c);
      }
      // System.out.println("v = " + v.toDecimal());
    }
    return v;
  }
 /** @return the sum of the values of all the counters. */
 public final C sum() {
   final C sum = factory.newInstance();
   for (C c : counts.values()) {
     sum.add(c);
   }
   return sum;
 }
  @Test
  public void
      standardReadMethodInSuperAndSubclassesAndGenericBuilderStyleNonStandardWriteMethodInSuperAndSubclasses()
          throws Exception {
    abstract class B<This extends B<This>> {
      @SuppressWarnings("unchecked")
      protected final This instance = (This) this;

      private String foo;

      public String getFoo() {
        return foo;
      }

      public This setFoo(String foo) {
        this.foo = foo;
        return this.instance;
      }
    }

    class C extends B<C> {
      private int bar = -1;

      public int getBar() {
        return bar;
      }

      public C setBar(int bar) {
        this.bar = bar;
        return this.instance;
      }
    }

    C c = new C().setFoo("blue").setBar(42);

    assertThat(c.getFoo(), is("blue"));
    assertThat(c.getBar(), is(42));

    BeanInfo bi = Introspector.getBeanInfo(C.class);

    assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
    assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));

    assertThat(hasReadMethodForProperty(bi, "bar"), is(true));
    assertThat(hasWriteMethodForProperty(bi, "bar"), is(false));

    BeanInfo ebi = new ExtendedBeanInfo(bi);

    assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
    assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));

    assertThat(hasReadMethodForProperty(bi, "bar"), is(true));
    assertThat(hasWriteMethodForProperty(bi, "bar"), is(false));

    assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
    assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));

    assertThat(hasReadMethodForProperty(ebi, "bar"), is(true));
    assertThat(hasWriteMethodForProperty(ebi, "bar"), is(true));
  }
 /**
  * Product random.
  *
  * @param n such that 0 &le; v &le; (2<sup>n</sup>-1).
  * @param q density of nozero entries.
  * @param rnd is a source for random bits.
  * @return a random product element v.
  */
 public Product<C> random(int n, float q, Random rnd) {
   SortedMap<Integer, C> elem = new TreeMap<Integer, C>();
   float d;
   if (nCopies != 0) {
     for (int i = 0; i < nCopies; i++) {
       d = rnd.nextFloat();
       if (d < q) {
         C r = ring.random(n, rnd);
         if (!r.isZERO()) {
           elem.put(i, r);
         }
       }
     }
   } else {
     int i = 0;
     for (RingFactory<C> f : ringList) {
       d = rnd.nextFloat();
       if (d < q) {
         C r = f.random(n, rnd);
         if (!r.isZERO()) {
           elem.put(i, r);
         }
       }
       i++;
     }
   }
   return new Product<C>(this, elem);
 }
Example #22
0
 public static void main(String[] args) {
   A a = new A();
   a.set(new A());
   a = a.set(new A()).get();
   a = a.get();
   C c = new C();
   c = c.setAndGet(new C());
 }
Example #23
0
  public static void main(String[] args) {
    C c = new C();

    System.out.println("fromC: " + c.fromC());
    System.out.println("fromP: " + c.fromP());
    System.out.println("fromGP: " + c.fromGP());
    System.out.println("get: " + c.get());
  }
Example #24
0
 @Override
 public C set(final int index, final C element) {
   final C result = set(index, element);
   if (result != null) {
     result.setParent(null);
   }
   return result;
 }
Example #25
0
 @Override
 public C remove(final int index) {
   final C result = super.remove(index);
   if (result != null) {
     result.setParent(null);
   }
   return result;
 }
Example #26
0
 private static final <P, C extends MutableChild<? super P>> void setChildrenParent(
     final Iterable<C> children, final P parent) {
   for (final C child : children) {
     if (child != null) {
       child.setParent(parent);
     }
   }
 }
 @Test
 public void testContains() {
   C collection = getCollection();
   for (String data : getData()) {
     Assert.assertTrue(collection.contains(data));
   }
   Assert.assertFalse(collection.contains("qux"));
 }
 @Test
 public void testToArray3() {
   C collection = getCollection();
   String[] array = collection.toArray(new String[2]);
   Assert.assertEquals(Math.max(2, getData().length), array.length);
   Assert.assertArrayEquals(getData(), Arrays.copyOf(array, getData().length));
   Assert.assertEquals(String.class, array.getClass().getComponentType());
 }
Example #29
0
 @Override
 protected void syncVars(Sync sync) {
   binding = (Binding) C.sync("binding", binding, sync);
   listNode = (Node) C.sync("listNode", listNode, sync);
   predicate = (Node) C.sync("predicate", predicate, sync);
   objectArgs = (List<Node>) C.sync("objectArgs", objectArgs, sync);
   execCxt = (ExecutionContext) C.sync("execCxt", execCxt, sync);
 }
Example #30
0
 /**
  * Hash code for this local.
  *
  * @see java.lang.Object#hashCode()
  */
 @Override
 public int hashCode() {
   int h;
   h = ring.hashCode();
   h = 37 * h + num.hashCode();
   h = 37 * h + den.hashCode();
   return h;
 }