Example usage for java.lang String getClass

List of usage examples for java.lang String getClass

Introduction

In this page you can find the example usage for java.lang String getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement.java

/**
 * Sets a property into the paramMap. Special implementation note - Null values aren't supported in the Map. So,
 * if a null value is passed in, this implementation will remove the entry from the map.
 * //  www.  j a v a  2  s . c  o  m
 * @param key
 *          The key into the map.
 * @param value
 *          The value to set.
 */
public void setStringProperty(final String key, final String value) {
    this.updateOk();
    trace(Messages.getInstance().getString("RTREPO.DEBUG_PROPERTY_GETSET", "setString", key)); //$NON-NLS-1$ //$NON-NLS-2$
    Map theMapSS = getParamMapSS();
    Map theMapLS = getParamMapLS();
    if (value != null) {
        checkType(key, value.getClass().getName(), true);
        if (value.length() > SimpleRuntimeElement.MAXSSLENGH) {
            theMapSS.remove(key); // Make sure it's not in the short map
            // first.
            theMapLS.put(key, new StringBuffer(value));
        } else {
            theMapLS.remove(key);
            theMapSS.put(key, value);
        }
    } else {
        theMapSS.remove(key);
        theMapLS.remove(key);
    }
}

From source file:org.apache.struts2.s1.DynaBeanPropertyAccessorTest.java

/**
 * Create and return a <code>DynaClass</code> instance for our test
 * <code>DynaBean</code>.//w  ww.j  a va2 s .  co  m
 */
protected DynaClass createDynaClass() {

    int intArray[] = new int[0];
    String stringArray[] = new String[0];

    DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null, new DynaProperty[] {
            new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("booleanSecond", Boolean.TYPE),
            new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE),
            new DynaProperty("intArray", intArray.getClass()),
            new DynaProperty("intIndexed", intArray.getClass()), new DynaProperty("intProperty", Integer.TYPE),
            new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE),
            new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class),
            new DynaProperty("nullProperty", String.class), new DynaProperty("shortProperty", Short.TYPE),
            new DynaProperty("stringArray", stringArray.getClass()),
            new DynaProperty("stringIndexed", stringArray.getClass()),
            new DynaProperty("stringProperty", String.class), });
    return (dynaClass);

}

From source file:com.juliazozulia.wordusage.Utils.Frequency.java

/**
 * Increments the frequency count for v.
 * <p>//from   w  ww. j a va 2 s .c  o m
 * If other objects have already been added to this Frequency, v must
 * be comparable to those that have already been added.
 * </p>
 *
 * @param v         the value to add.
 * @param increment the amount by which the value should be incremented
 * @throws MathIllegalArgumentException if <code>v</code> is not comparable with previous entries
 * @since 3.1
 */
public void incrementValue(String v, Integer increment) throws MathIllegalArgumentException {

    String obj = v;

    try {
        Integer count = freqTable.get(obj);
        if (count == null) {
            freqTable.put(obj, Integer.valueOf(increment));
        } else {
            freqTable.put(obj, Integer.valueOf(count + increment));
        }
    } catch (ClassCastException ex) {
        //TreeMap will throw ClassCastException if v is not comparable
        throw new MathIllegalArgumentException(LocalizedFormats.INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES,
                v.getClass().getName());
    }
}

From source file:com.infochimps.hadoop.pig.hbase.StaticFamilyStorage.java

@SuppressWarnings("unchecked")
@Override//from   ww  w  .j  a v a 2s  .c o  m
public void putNext(Tuple t) throws IOException {
    if (!initialized) {
        Properties p = UDFContext.getUDFContext().getUDFProperties(this.getClass(),
                new String[] { contextSignature });
        String serializedSchema = p.getProperty(contextSignature + "_schema");
        if (serializedSchema != null) {
            schema_ = (ResourceSchema) ObjectSerializer.deserialize(serializedSchema);
        }
        initialized = true;
    }
    ResourceFieldSchema[] fieldSchemas = (schema_ == null) ? null : schema_.getFields();
    Put put = new Put(objToBytes(t.get(0),
            (fieldSchemas == null) ? DataType.findType(t.get(0)) : fieldSchemas[0].getType()));
    long ts = System.currentTimeMillis();

    // Allow for custom timestamp
    if (tsField_ != -1) {
        try {
            ts = Long.valueOf(t.get(tsField_).toString());
        } catch (Exception e) {
            ts = System.currentTimeMillis();
        }
    }

    if (LOG.isDebugEnabled()) {
        for (ColumnInfo columnInfo : columnInfo_) {
            LOG.debug("putNext -- col: " + columnInfo);
        }
    }

    for (int i = 1; i < t.size(); ++i) {
        ColumnInfo columnInfo = columnInfo_.get(i - 1);
        if (LOG.isDebugEnabled()) {
            LOG.debug("putNext - tuple: " + i + ", value=" + t.get(i) + ", cf:column=" + columnInfo);
        }

        if (!columnInfo.isColumnMap()) {
            if ((columnInfo.getColumnFamily() != null) && (columnInfo.getColumnName() != null)
                    && !t.isNull(i)) {
                put.add(columnInfo.getColumnFamily(), columnInfo.getColumnName(), ts, objToBytes(t.get(i),
                        (fieldSchemas == null) ? DataType.findType(t.get(i)) : fieldSchemas[i].getType()));
            }
        } else {
            Map<String, Object> cfMap = (Map<String, Object>) t.get(i);
            for (String colName : cfMap.keySet()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("putNext - colName=" + colName + ", class: " + colName.getClass());
                }
                // TODO deal with the fact that maps can have types now. Currently we detect types at
                // runtime in the case of storing to a cf, which is suboptimal.
                if ((columnInfo.getColumnFamily() != null) && (colName != null)
                        && (cfMap.get(colName) != null)) {
                    put.add(columnInfo.getColumnFamily(), Bytes.toBytes(colName.toString()), ts,
                            objToBytes(cfMap.get(colName), DataType.findType(cfMap.get(colName))));
                }
            }
        }
    }

    try {
        if (!put.isEmpty()) { // Don't try to write a row with 0 columns
            writer.write(null, put);
        }
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}

From source file:fr.landel.utils.assertor.OperatorTest.java

/**
 * Test method for {@link Operator#or()}.
 *//*  w ww.ja va2s .  co m*/
@Test
public void testOr() {
    final String text = "text";
    assertTrue(Assertor.that(text).isEmpty().or().isNotBlank().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(true).isTrue().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(true).isFalse().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(text.getClass()).isAssignableFrom(CharSequence.class).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(text.getClass()).isAssignableFrom(StringBuilder.class).isOK());

    assertTrue(Assertor.that(text).isEmpty().or(Calendar.getInstance())
            .isAfter(DateUtils.getCalendar(new Date(0))).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Calendar.getInstance())
            .isBefore(DateUtils.getCalendar(new Date(0))).isOK());

    assertTrue(Assertor.that(text).isEmpty().or(new Date()).isAfter(new Date(0)).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(new Date()).isBefore(new Date(0)).isOK());

    assertTrue(Assertor.that(text).isEmpty().or(LocalDateTime.now()).isAfter(LocalDateTime.MIN).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(LocalDateTime.now()).isAfter(LocalDateTime.MAX).isOK());

    assertTrue(Assertor.that(text).isEmpty().or(2).isGT(1).isOK());
    assertFalse(Assertor.that(text).isEmpty().or(2).isLT(1).isOK());

    assertTrue(Assertor.that(text).isEmpty().or("tt").isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or("tt").isEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(new String[] {}).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(new String[] {}).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().or(new String[] {}, EnumAnalysisMode.STREAM).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(new String[] {}, EnumAnalysisMode.STREAM).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().or(new String[] {}, EnumAnalysisMode.PARALLEL).isEmpty().isOK());
    assertFalse(
            Assertor.that(text).isEmpty().or(new String[] {}, EnumAnalysisMode.PARALLEL).isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyList()).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyList()).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyList(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyList(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyList(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyList(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyMap()).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyMap()).isNotEmpty().isOK());
    assertTrue(
            Assertor.that(text).isEmpty().or(Collections.emptyMap(), EnumAnalysisMode.STREAM).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyMap(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().or(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().or(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isNotEmpty()
            .isOK());

    assertTrue(Assertor.that(text).isEmpty().or((Object) 0).isNotNull().isOK());
    assertFalse(Assertor.that(text).isEmpty().or((Object) 0).isNull().isOK());

    assertTrue(Assertor.that(text).isEmpty().or(new Exception()).isNotNull().isOK());
    assertFalse(Assertor.that(text).isEmpty().or(new Exception()).isNull().isOK());

    assertTrue(Assertor.that(Color.BLACK).isNull().or().isEqual(Color.black).isOK());
    assertTrue(Assertor.that(Color.BLACK).isNull().or((Object) 0).isNotNull().isOK());

    assertTrue(Assertor.that(Color.BLACK).isNotNull().or(Assertor.that(text).isEmpty()).isOK());

    assertTrue(
            Assertor.that(true).isFalse().or(Assertor.that("text").startsWith("t").and().contains("e")).isOK());

    // SUB ASSERTOR

    assertTrue(Assertor.that(text).isNotEmpty().orAssertor(t -> Assertor.that(t.length()).isGT(4)).isOK());
    assertEquals(
            "the char sequence 'text' should be null or empty OR (the number '4' should be greater than '4')",
            Assertor.that(text).isEmpty().orAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get());

    assertException(() -> Assertor.that(text).isNotEmpty()
            .orAssertor((Function<String, StepCharSequence<String>>) null).isOK(), IllegalStateException.class,
            "sub assertor cannot be null");

    // MAPPER

    assertTrue(Assertor.that(true).isTrue().orObject(b -> b.toString()).hasHashCode(Objects.hashCode("true"))
            .isOK());
    assertTrue(Assertor.that(true).isTrue().orCharSequence(b -> b.toString()).contains("ue").isOK());
    assertTrue(Assertor.that("test").isNotEmpty()
            .orArray(s -> ArrayUtils.toObject(s.getBytes(StandardCharsets.UTF_8))).contains((byte) 'e').isOK());
    assertTrue(Assertor.that(true).isTrue().orBoolean(b -> !b).isFalse().isOK());
    assertTrue(Assertor.that(true).isTrue().orClass(b -> b.getClass()).hasSimpleName("Boolean").isOK());
    assertTrue(Assertor.that(true).isTrue().orDate(b -> new Date(1464475553641L))
            .isAfter(new Date(1464475553640L)).isOK());
    assertTrue(Assertor.that(true).isTrue().orCalendar(b -> DateUtils.getCalendar(new Date(1464475553641L)))
            .isBefore(Calendar.getInstance()).isOK());
    assertTrue(
            Assertor.that(true).isTrue().orTemporal(b -> DateUtils.getLocalDateTime(new Date(1464475553641L)))
                    .isBefore(LocalDateTime.now()).isOK());
    assertTrue(Assertor.that(true).isTrue().orEnum(b -> EnumOperator.AND).hasName("AND").isOK());
    assertTrue(Assertor.that(true).isTrue().orIterable(b -> Arrays.asList('t', 'r')).contains('t').isOK());
    assertTrue(Assertor.that(true).isTrue().orMap(b -> MapUtils2.newHashMap("key", b)).contains("key", true)
            .isOK());
    assertTrue(Assertor.that(true).isTrue().orNumber(b -> b.hashCode()).isGT(0).isOK()); // 1231
    assertTrue(Assertor.that(true).isTrue().orThrowable(b -> new IOException(b.toString()))
            .validates(e -> e.getMessage().contains("true")).isOK());
}

From source file:fr.landel.utils.assertor.OperatorTest.java

/**
 * Test method for {@link Operator#xor()}.
 *///from  w  w w.  j  a va  2  s  . co m
@Test
public void testXor() {
    final String text = "text";
    assertTrue(Assertor.that(text).isEmpty().xor().isNotBlank().isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(true).isTrue().isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(true).isFalse().isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(text.getClass()).isAssignableFrom(CharSequence.class).isOK());
    assertFalse(
            Assertor.that(text).isEmpty().xor(text.getClass()).isAssignableFrom(StringBuilder.class).isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(Calendar.getInstance())
            .isAfter(DateUtils.getCalendar(new Date(0))).isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(Calendar.getInstance())
            .isBefore(DateUtils.getCalendar(new Date(0))).isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(new Date()).isAfter(new Date(0)).isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(new Date()).isBefore(new Date(0)).isOK());

    assertTrue(Assertor.that(text).isNotEmpty().xor(LocalDateTime.now()).isAfter(LocalDateTime.MAX).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().xor(LocalDateTime.now()).isAfter(LocalDateTime.MIN).isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(2).isGT(1).isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(2).isLT(1).isOK());

    assertTrue(Assertor.that(text).isEmpty().xor("tt").isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().xor("tt").isEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(new String[] {}).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(new String[] {}).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().xor(new String[] {}, EnumAnalysisMode.STREAM).isEmpty().isOK());
    assertFalse(
            Assertor.that(text).isEmpty().xor(new String[] {}, EnumAnalysisMode.STREAM).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().xor(new String[] {}, EnumAnalysisMode.PARALLEL).isEmpty().isOK());
    assertFalse(
            Assertor.that(text).isEmpty().xor(new String[] {}, EnumAnalysisMode.PARALLEL).isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(Collections.emptyList()).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(Collections.emptyList()).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().xor(Collections.emptyList(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(Collections.emptyList(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().xor(Collections.emptyList(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(Collections.emptyList(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(Collections.emptyMap()).isEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(Collections.emptyMap()).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().xor(Collections.emptyMap(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(Collections.emptyMap(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().xor(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(Collections.emptyMap(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isEmpty().xor((Object) 0).isNotNull().isOK());
    assertFalse(Assertor.that(text).isEmpty().xor((Object) 0).isNull().isOK());

    assertTrue(Assertor.that(text).isEmpty().xor(new Exception()).isNotNull().isOK());
    assertFalse(Assertor.that(text).isEmpty().xor(new Exception()).isNull().isOK());

    assertTrue(Assertor.that(Color.BLACK).isNull().xor().isEqual(Color.black).isOK());
    assertTrue(Assertor.that(Color.BLACK).isNull().xor((Object) 0).isNotNull().isOK());

    assertTrue(Assertor.that(Color.BLACK).isNotNull().xor(Assertor.that(text).isEmpty()).isOK());

    // SUB ASSERTOR

    assertTrue(Assertor.that(text).isNotEmpty().xorAssertor(t -> Assertor.that(t.length()).isGT(4)).isOK());
    assertEquals(
            "the char sequence 'text' should be null or empty XOR (the number '4' should be greater than '4')",
            Assertor.that(text).isEmpty().xorAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors()
                    .get());

    assertException(
            () -> Assertor.that(text).isNotEmpty()
                    .xorAssertor((Function<String, StepCharSequence<String>>) null).isOK(),
            IllegalStateException.class, "sub assertor cannot be null");

    // MAPPER

    assertTrue(Assertor.that(false).isTrue().xorObject(b -> b.toString()).hasHashCode(Objects.hashCode("false"))
            .isOK());
    assertTrue(Assertor.that(false).isTrue().xorCharSequence(b -> b.toString()).contains("se").isOK());
    assertTrue(Assertor.that("test").isNotEmpty()
            .xorArray(s -> ArrayUtils.toObject(s.getBytes(StandardCharsets.UTF_8))).contains((byte) 'x')
            .isOK());
    assertTrue(Assertor.that(false).isTrue().xorBoolean(b -> b).isFalse().isOK());
    assertTrue(Assertor.that(false).isTrue().xorClass(b -> b.getClass()).hasSimpleName("Boolean").isOK());
    assertTrue(Assertor.that(false).isTrue().xorDate(b -> new Date(1464475553641L))
            .isAfter(new Date(1464475553640L)).isOK());
    assertTrue(Assertor.that(false).isTrue().xorCalendar(b -> DateUtils.getCalendar(new Date(1464475553641L)))
            .isBefore(Calendar.getInstance()).isOK());
    assertTrue(
            Assertor.that(false).isTrue().xorTemporal(b -> DateUtils.getLocalDateTime(new Date(1464475553641L)))
                    .isBefore(LocalDateTime.now()).isOK());
    assertTrue(Assertor.that(false).isTrue().xorEnum(b -> EnumOperator.AND).hasName("AND").isOK());
    assertTrue(Assertor.that(false).isTrue().xorIterable(b -> Arrays.asList('t', 'r')).contains('t').isOK());
    assertTrue(Assertor.that(false).isTrue().xorMap(b -> MapUtils2.newHashMap("key", b)).contains("key", false)
            .isOK());
    assertTrue(Assertor.that(false).isTrue().xorNumber(b -> b.hashCode()).isGT(0).isOK()); // 1231
    assertTrue(Assertor.that(false).isTrue().xorThrowable(b -> new IOException(b.toString()))
            .validates(e -> e.getMessage().contains("false")).isOK());
}

From source file:org.openecomp.sdnc.sli.aai.AAIRequest.java

public URL getRequestUrl(String method, String resourceVersion)
        throws UnsupportedEncodingException, MalformedURLException {

    String request_url = null;

    request_url = target_uri + getRequestPath();

    Set<String> uniqueResources = extractUniqueResourceSetFromKeys(requestProperties.stringPropertyNames());

    //      request_url = processPathData(request_url, requestProperties);

    for (String resoourceName : uniqueResources) {
        AAIRequest locRequest = AAIRequest.createRequest(resoourceName, new HashMap<String, String>());
        if (locRequest != null) {
            Class<?> clazz = locRequest.getClass();
            Method function = null;
            try {
                function = clazz.getMethod("processPathData", request_url.getClass(),
                        requestProperties.getClass());
                request_url = (String) function.invoke(null, request_url, requestProperties);
            } catch (Exception e) {
                e.printStackTrace();/*from  w w w.j  a  va 2 s . c om*/
            }
            //            request_url = locRequest.processPathData(request_url, requestProperties);
        }
    }

    if (resourceVersion != null) {
        request_url = request_url + "?resource-version=" + resourceVersion;
    }
    URL http_req_url = new URL(request_url);

    aaiService.LOGwriteFirstTrace(method, http_req_url.toString());

    return http_req_url;
}

From source file:fr.landel.utils.assertor.OperatorTest.java

/**
 * Test method for {@link Operator#nand()}.
 *///  w w w  . j  a  v  a 2  s.  com
@Test
public void testNand() {
    final String text = "text";
    assertFalse(Assertor.that(text).isEmpty().nand().isNotBlank().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(true).isTrue().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(true).isFalse().isOK());

    assertFalse(
            Assertor.that(text).isEmpty().nand(text.getClass()).isAssignableFrom(CharSequence.class).isOK());
    assertTrue(
            Assertor.that(text).isEmpty().nand(text.getClass()).isAssignableFrom(StringBuilder.class).isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(Calendar.getInstance())
            .isAfter(DateUtils.getCalendar(new Date(0))).isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Calendar.getInstance())
            .isBefore(DateUtils.getCalendar(new Date(0))).isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(new Date()).isAfter(new Date(0)).isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(new Date()).isBefore(new Date(0)).isOK());

    assertFalse(Assertor.that(text).isNotEmpty().nand(LocalDateTime.now()).isAfter(LocalDateTime.MAX).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().nand(LocalDateTime.now()).isAfter(LocalDateTime.MIN).isOK());

    assertFalse(Assertor.that(text).isNotEmpty().nandNumber(t -> t.length()).isGT(Integer.MAX_VALUE).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().nandNumber(t -> t.length()).isGT(Integer.MIN_VALUE).isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(2).isGT(1).isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(2).isLT(1).isOK());

    assertFalse(Assertor.that(text).isEmpty().nand("tt").isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand("tt").isEmpty().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(new String[] {}).isEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(new String[] {}).isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(new String[] {}, EnumAnalysisMode.STREAM).isEmpty().isOK());
    assertTrue(
            Assertor.that(text).isEmpty().nand(new String[] {}, EnumAnalysisMode.STREAM).isNotEmpty().isOK());
    assertFalse(
            Assertor.that(text).isEmpty().nand(new String[] {}, EnumAnalysisMode.PARALLEL).isEmpty().isOK());
    assertTrue(
            Assertor.that(text).isEmpty().nand(new String[] {}, EnumAnalysisMode.PARALLEL).isNotEmpty().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyList()).isEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyList()).isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyList(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyList(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyList(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyList(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyMap()).isEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyMap()).isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyMap(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyMap(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyMap(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand((Object) 0).isNotNull().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand((Object) 0).isNull().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(new Exception()).isNotNull().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(new Exception()).isNull().isOK());

    assertFalse(Assertor.that(Color.BLACK).isNull().nand().isEqual(Color.black).isOK());
    assertFalse(Assertor.that(Color.BLACK).isNull().nand((Object) 0).isNotNull().isOK());

    assertFalse(Assertor.that(Color.BLACK).isNotNull().nand(Assertor.that(text).isEmpty()).isOK());
    assertEquals("the combination 'true' and ' NAND ' is invalid",
            Assertor.that(Color.BLACK).isNotNull().nand(Assertor.that(text).isEmpty()).getErrors().get());

    // SUB ASSERTOR

    assertTrue(Assertor.that(text).isEmpty().nandAssertor(t -> Assertor.that(t.length()).isGT(4)).isOK());
    assertEquals("the combination 'true' and ' NAND ' is invalid", Assertor.that(text).isNotEmpty()
            .nandAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get());

    assertException(
            () -> Assertor.that(text).isNotEmpty()
                    .nandAssertor((Function<String, StepCharSequence<String>>) null).isOK(),
            IllegalStateException.class, "sub assertor cannot be null");

    // MAPPER

    assertException(() -> Assertor.that(text).isNotEmpty().nandNumber((Function<String, Integer>) null)
            .isGT(Integer.MAX_VALUE).isOK(), IllegalStateException.class, "property cannot be null");

    assertTrue(Assertor.that(false).isTrue().nandObject(b -> b.toString()).hasHashCode(0).isOK());
    assertTrue(Assertor.that(false).isTrue().nandCharSequence(b -> b.toString()).contains("ue").isOK());
    assertTrue(Assertor.that("test").isEmpty()
            .nandArray(s -> ArrayUtils.toObject(s.getBytes(StandardCharsets.UTF_8))).contains((byte) 'x')
            .isOK());
    assertTrue(Assertor.that(false).isTrue().nandBoolean(b -> !b).isFalse().isOK());
    assertTrue(Assertor.that(false).isTrue().nandClass(b -> b.getClass()).hasSimpleName("Bool").isOK());
    assertTrue(Assertor.that(false).isTrue().nandDate(b -> new Date(1464475553641L))
            .isBefore(new Date(1464475553640L)).isOK());
    assertTrue(Assertor.that(false).isTrue().nandCalendar(b -> DateUtils.getCalendar(new Date(1464475553641L)))
            .isAfter(Calendar.getInstance()).isOK());
    assertTrue(Assertor.that(false).isTrue()
            .nandTemporal(b -> DateUtils.getLocalDateTime(new Date(1464475553641L)))
            .isAfter(LocalDateTime.now()).isOK());
    assertTrue(Assertor.that(false).isTrue().nandEnum(b -> EnumOperator.OR).hasName("AND").isOK());
    assertTrue(Assertor.that(false).isTrue().nandIterable(b -> Arrays.asList('t', 'r')).contains('u').isOK());
    assertTrue(Assertor.that(false).isTrue().nandMap(b -> MapUtils2.newHashMap("key", b)).contains("key", true)
            .isOK());
    assertTrue(Assertor.that(false).isTrue().nandNumber(b -> b.hashCode()).isGT(Integer.MAX_VALUE).isOK()); // 1231
    assertTrue(Assertor.that(false).isTrue().nandThrowable(b -> new IOException(b.toString()))
            .validates(e -> e.getMessage().contains("true")).isOK());
}

From source file:fr.landel.utils.assertor.OperatorTest.java

/**
 * Test method for {@link Operator#and()}.
 *///from w w  w.  j  ava2s  . c o  m
@Test
public void testAnd() {
    final String text = "text";
    assertTrue(Assertor.that(text).isNotEmpty().and().isNotBlank().isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(true).isTrue().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(true).isFalse().isOK());

    assertTrue(
            Assertor.that(text).isNotEmpty().and(text.getClass()).isAssignableFrom(CharSequence.class).isOK());
    assertFalse(
            Assertor.that(text).isNotEmpty().and(text.getClass()).isAssignableFrom(StringBuilder.class).isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(Calendar.getInstance())
            .isAfter(DateUtils.getCalendar(new Date(0))).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(Calendar.getInstance())
            .isBefore(DateUtils.getCalendar(new Date(0))).isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(new Date()).isAfter(new Date(0)).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(new Date()).isBefore(new Date(0)).isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(LocalDateTime.now()).isAfter(LocalDateTime.MIN).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(LocalDateTime.now()).isAfter(LocalDateTime.MAX).isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(2).isGT(1).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(2).isLT(1).isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and("tt").isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and("tt").isEmpty().isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(new String[] {}).isEmpty().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(new String[] {}).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isNotEmpty().and(new String[] {}, EnumAnalysisMode.STREAM).isEmpty().isOK());
    assertFalse(
            Assertor.that(text).isNotEmpty().and(new String[] {}, EnumAnalysisMode.STREAM).isNotEmpty().isOK());
    assertTrue(
            Assertor.that(text).isNotEmpty().and(new String[] {}, EnumAnalysisMode.PARALLEL).isEmpty().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(new String[] {}, EnumAnalysisMode.PARALLEL).isNotEmpty()
            .isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyList()).isEmpty().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyList()).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyList(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyList(), EnumAnalysisMode.STREAM)
            .isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyList(), EnumAnalysisMode.PARALLEL)
            .isEmpty().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyList(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyMap()).isEmpty().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyMap()).isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyMap(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyMap(), EnumAnalysisMode.STREAM)
            .isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyMap(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and((Object) 0).isNotNull().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and((Object) 0).isNull().isOK());

    assertTrue(Assertor.that(text).isNotEmpty().and(new Exception()).isNotNull().isOK());
    assertFalse(Assertor.that(text).isNotEmpty().and(new Exception()).isNull().isOK());

    assertFalse(Assertor.that(Color.BLACK).isNull().and().isEqual(Color.black).isOK());
    assertFalse(Assertor.that(Color.BLACK).isNull().and((Object) 0).isNotNull().isOK());

    // SUB

    assertTrue(Assertor.that(true).isTrue().and(Assertor.that("text").isEmpty().or().contains("e")).isOK());
    // left part error
    assertEquals("the boolean should be false", Assertor.that(true).isFalse()
            .and(Assertor.that("text").isEmpty().or().contains("e")).getErrors().get());
    // right part error
    assertEquals("(the char sequence 'text' should contain 's')",
            Assertor.that(true).isTrue().and(Assertor.that("text").contains("s")).getErrors().get());
    assertFalse(Assertor.that(true).isTrue().and(Assertor.that("text").contains("s")).isOK());
    assertTrue(Assertor.that(true).isTrue().or(Assertor.that("text").contains("s")).isOK());
    assertFalse(Assertor.that(true).isTrue().or(Assertor.that("text").contains("s")).getErrors().isPresent());
    // both parts error
    assertEquals("the boolean should be false", Assertor.that(true).isFalse()
            .and(Assertor.that("text").isEmpty().or().contains("s")).getErrors().get());
    assertEquals("the combination 'true' and ' NAND ' is invalid", Assertor.that(true).isTrue()
            .nand(Assertor.that("text").isEmpty().or().contains("s")).getErrors().get());
    assertEquals("the boolean should be false OR (the char sequence 'text' should contain 's')", Assertor
            .that(true).isFalse().or(Assertor.that("text").isNotEmpty().and().contains("s")).getErrors().get());
    // precondition error
    assertEquals("the char sequence cannot be null and the searched substring cannot be null or empty",
            Assertor.that(true).isTrue().and(Assertor.that("text").contains((String) null)).getErrors().get());

    // SUB ASSERTOR

    assertTrue(Assertor.that(text).isNotEmpty().andAssertor(t -> Assertor.that(t.length()).isGT(3)).isOK());
    // left part error
    assertEquals("the char sequence 'text' should be null or empty", Assertor.that(text).isEmpty()
            .andAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get());
    // right part error
    assertEquals("(the number '4' should be greater than '4')", Assertor.that(text).isNotEmpty()
            .andAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get());
    // precondition error
    assertEquals("the char sequence cannot be null and the searched substring cannot be null or empty",
            Assertor.that(text).isNotEmpty()
                    .andAssertor(t -> Assertor.that(t.substring(0)).contains((String) null)).getErrors().get());
    // null
    assertFalse(Assertor.that((String) null).isEmpty().andAssertor(t -> {
        if (t != null) {
            return Assertor.that(t.substring(1)).contains("e");
        } else {
            return Assertor.that((String) null).isNull();
        }
    }).getErrors().isPresent());

    assertException(
            () -> Assertor.that(text).isNotEmpty()
                    .andAssertor((Function<String, StepCharSequence<String>>) null).isOK(),
            IllegalStateException.class, "sub assertor cannot be null");

    // MAPPER

    assertTrue(Assertor.that(true).isTrue().andObject(b -> b.toString()).hasHashCode(Objects.hashCode("true"))
            .isOK());
    assertTrue(Assertor.that(true).isTrue().andCharSequence(b -> b.toString()).contains("ue").isOK());
    assertTrue(Assertor.that("test").isNotEmpty()
            .andArray(s -> ArrayUtils.toObject(s.getBytes(StandardCharsets.UTF_8))).contains((byte) 'e')
            .isOK());
    assertTrue(Assertor.that(true).isTrue().andBoolean(b -> !b).isFalse().isOK());
    assertTrue(Assertor.that(true).isTrue().andClass(b -> b.getClass()).hasSimpleName("Boolean").isOK());
    assertTrue(Assertor.that(true).isTrue().andDate(b -> new Date(1464475553641L))
            .isAfter(new Date(1464475553640L)).isOK());
    assertTrue(Assertor.that(true).isTrue().andCalendar(b -> DateUtils.getCalendar(new Date(1464475553641L)))
            .isBefore(Calendar.getInstance()).isOK());
    assertTrue(
            Assertor.that(true).isTrue().andTemporal(b -> DateUtils.getLocalDateTime(new Date(1464475553641L)))
                    .isBefore(LocalDateTime.now()).isOK());
    assertTrue(Assertor.that(true).isTrue().andEnum(b -> EnumOperator.AND).hasName("AND").isOK());
    assertTrue(Assertor.that(true).isTrue().andIterable(b -> Arrays.asList('t', 'r')).contains('t').isOK());
    assertTrue(Assertor.that(true).isTrue().andMap(b -> MapUtils2.newHashMap("key", b)).contains("key", true)
            .isOK());
    assertTrue(Assertor.that(true).isTrue().andNumber(b -> b.hashCode()).isGT(0).isOK()); // 1231
    assertTrue(Assertor.that(true).isTrue().andThrowable(b -> new IOException(b.toString()))
            .validates(e -> e.getMessage().contains("true")).isOK());
}

From source file:org.agnitas.dao.impl.MailingDaoImpl.java

public Map<String, String> loadAction(int mailingID, int companyID) {
    Map<String, String> actions = new HashMap<String, String>();
    JdbcTemplate jdbc = new JdbcTemplate((DataSource) applicationContext.getBean("dataSource"));

    String stmt = "select action_id, shortname, full_url from rdir_url_tbl where mailing_id = ? and company_id = ?";
    try {//from www .  ja  v  a2  s. c  o m
        List list = jdbc.queryForList(stmt, new Object[] { new Integer(mailingID), new Integer(companyID) });
        for (int i = 0; i < list.size(); i++) {
            Map map = (Map) list.get(i);
            int action_id = ((Number) map.get("action_id")).intValue();
            if (action_id > 0) {
                stmt = "select shortname from rdir_action_tbl where company_id = " + companyID
                        + " and action_id = " + action_id;
                String action_short = (String) jdbc.queryForObject(stmt, stmt.getClass());

                String name = "";
                if (map.get("shortname") != null) {
                    name = (String) map.get("shortname");
                } else {
                    name = (String) map.get("full_url");
                }
                actions.put(action_short, name);
            }
        }
    } catch (Exception e) {
        AgnUtils.sendExceptionMail("sql:" + stmt + ", " + mailingID + ", " + companyID, e);
        System.err.println(e.getMessage());
        System.err.println(AgnUtils.getStackTrace(e));
    }
    return actions;
}