Java Code Examples for org.osgl.Lang#Break

The following examples show how to use org.osgl.Lang#Break . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleStringValueResolver.java    From java-tool with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(String s, Class<?> aClass) throws NotAppliedException, Lang.Break {
    StringValueResolver r = resolvers.get(aClass);
    if (null != r) {
        return r.resolve(s);
    }
    if (null != s && Enum.class.isAssignableFrom(aClass)) {
        return Enum.valueOf(((Class<Enum>) aClass), s);
    }
    return null;
}
 
Example 2
Source File: ReflectionPropertySetter.java    From java-tool with Apache License 2.0 5 votes vote down vote up
private void setProperty(Object entity, Object value) throws NotAppliedException, Lang.Break {
    if (null == entity) {
        return;
    }
    ensureMethodOrField(entity);
    try {
        doSet(entity, value);
    } catch (Exception e) {
        throw E.unexpected(e);
    }
}
 
Example 3
Source File: ReflectionPropertyGetter.java    From java-tool with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Object getProperty(Object entity) throws NotAppliedException, Lang.Break {
    if (null == entity) {
        return null;
    }
    ensureMethodOrField(entity);
    try {
        Object v;
        if (null != m) {
            v = m.invoke(entity);
        } else {
            v = f.get(entity);
        }
        if (null == v) {
            switch (nullValuePolicy) {
                case NPE:
                    throw new NullPointerException();
                case CREATE_NEW:
                    v = objectFactory.apply(getPropertyClass(entity));
                    PropertySetter setter = setter();
                    setter.set(entity, v, null);
                    return v;
                default:
                    return null;
            }
        }
        return v;
    } catch (Exception e) {
        throw E.unexpected(e);
    }
}
 
Example 4
Source File: C.java    From java-tool with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a function that append specified element to argument sequence
 * @param element the element to be added to the tail of the argument (sequence type)
 * @param <T> the element type
 * @return the function as described
 * @see Sequence#append(Iterable)
 * @see #appendTo(Sequence)
 */
@SuppressWarnings("unused")
public static <T> $.Processor<Sequence<? super T>> sequenceAppend(final T element) {
    return new Lang.Processor<Sequence<? super T>>() {
        @Override
        public void process(Sequence<? super T> sequence) throws Lang.Break, NotAppliedException {
            sequence.append(element);
        }
    };
}
 
Example 5
Source File: C.java    From java-tool with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a function that preppend specified element to argument sequence
 * @param element the element to be added to the head of the argument (sequence type)
 * @param <T> the element type
 * @return the function as described
 * @see Sequence#prepend(Object)
 * @see #prependTo(Sequence)
 */
@SuppressWarnings("unused")
public static <T> $.Processor<Sequence<? super T>> sequencePrepend(final T element) {
    return new Lang.Processor<Sequence<? super T>>() {
        @Override
        public void process(Sequence<? super T> sequence) throws Lang.Break, NotAppliedException {
            sequence.prepend(element);
        }
    };
}
 
Example 6
Source File: C.java    From java-tool with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a function that append specified element to argument deque
 * @param element the element to be added to the tail of the argument (deque type)
 * @param <T> the element type
 * @return the function as described
 * @see Deque#add(Object)
 * @see #appendTo(Deque)
 */
@SuppressWarnings("unused")
public static <T> $.Processor<Deque<? super T>> dequeAppend(final T element) {
    return new $.Processor<Deque<? super T>>() {
        @Override
        public void process(Deque<? super T> deque) throws Lang.Break, NotAppliedException {
            deque.add(element);
        }
    };
}
 
Example 7
Source File: C.java    From java-tool with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a function that prepend specified element to argument deque
 * @param element the element to be added to the head of the argument (deque type)
 * @param <T> the element type
 * @return the function as described
 * @see Deque#addFirst(Object)
 * @see #prependTo(Deque)
 */
@SuppressWarnings("unused")
public static <T> $.Processor<Deque<? super T>> dequePrepend(final T element) {
    return new $.Processor<Deque<? super T>>() {
        @Override
        public void process(Deque<? super T> deque) throws Lang.Break, NotAppliedException {
            deque.addFirst(element);
        }
    };
}
 
Example 8
Source File: SimpleObjectFactory.java    From java-tool with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(Class<?> aClass) throws NotAppliedException, Lang.Break {
    if (List.class.isAssignableFrom(aClass)) {
        return C.newList();
    } else if (Map.class.isAssignableFrom(aClass)) {
        return C.newMap();
    }
    return Lang.newInstance(aClass);
}
 
Example 9
Source File: FontProvider.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public Font apply(String text) throws NotAppliedException, Lang.Break {
    Random r = ThreadLocalRandom.current();
    int style = randomStyle(r);
    String fontName = $.random(families);
    int size = MIN_SIZE + r.nextInt(MAX_SIZE - MIN_SIZE);
    return new Font(fontName, style, size);
}
 
Example 10
Source File: AuditHelper.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(Object o) throws Lang.Break {
    if (null == o) {
        return;
    }
    $.setFieldValue(o, field, principalProvider.get());
}
 
Example 11
Source File: SystemAvailabilityMonitor.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(GcInfo gcInfo) throws Lang.Break {
    currentCounter.incrementAndGet();
    if (smallWindowSum.incrementAndGet() > 10) {
        // there are at least 11 gc happened within last 2s
        pauseNow();
        wakeUp();
    }
    largeWindowSum.incrementAndGet();
    LOGGER.debug("gc notified. gc summary: %s | %s", smallWindowSum.get(), largeWindowSum.get());
}
 
Example 12
Source File: N.java    From java-tool with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean apply(Number number, Number number2) throws NotAppliedException, Lang.Break {
    return !number.equals(number2);
}
 
Example 13
Source File: N.java    From java-tool with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean apply(Number number, Number number2) throws NotAppliedException, Lang.Break {
    return number.equals(number2);
}
 
Example 14
Source File: N.java    From java-tool with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean apply(Number number, Number number2) throws NotAppliedException, Lang.Break {
    return number.doubleValue() < number2.doubleValue() || number.equals(number2);
}
 
Example 15
Source File: N.java    From java-tool with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean apply(Number number, Number number2) throws NotAppliedException, Lang.Break {
    return number.doubleValue() < number2.doubleValue();
}
 
Example 16
Source File: N.java    From java-tool with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean apply(Number number, Number number2) throws NotAppliedException, Lang.Break {
    return number.doubleValue() > number2.doubleValue() || number.equals(number2);
}
 
Example 17
Source File: N.java    From java-tool with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean apply(Number number, Number number2) throws NotAppliedException, Lang.Break {
    return number.doubleValue() > number2.doubleValue();
}
 
Example 18
Source File: C.java    From java-tool with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a function that add specified element into the argument list at specified position. The
 * function returns the argument list after element added
 * @param index the location at where the element should be added to
 * @param element the element the be added to the argument list
 * @param <L> the list type
 * @param <T> the element type
 * @return the function
 * @see java.util.List#add(int, Object)
 * @see #addTo(int, List)
 */
public static <L extends List<? super T>, T> $.F1<L, L> add(final int index, final T element) {
    return new $.F1<L, L>() {
        @Override
        public L apply(L list) throws NotAppliedException, Lang.Break {
            list.add(index, element);
            return list;
        }
    };
}