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:uk.gov.gchq.koryphe.impl.predicate.Regex.java

@Override
public boolean test(final String input) {
    return !(null == input || input.getClass() != String.class) && controlValue.matcher(input).matches();
}

From source file:uk.gov.gchq.gaffer.function.filter.MultiRegex.java

@Override
public boolean isValid(final String input) {
    if (null == input || input.getClass() != String.class) {
        return false;
    }/*from   ww  w  .  ja v a2s  . com*/
    for (final Pattern pattern : patterns) {
        if (pattern.matcher(input).matches()) {
            return true;
        }
    }
    return false;
}

From source file:uk.gov.gchq.koryphe.impl.predicate.MultiRegex.java

@Override
public boolean test(final String input) {
    if (null == input || input.getClass() != String.class) {
        return false;
    }/*from  w  w  w .  j av a 2  s. c o m*/
    for (final Pattern pattern : patterns) {
        if (pattern.matcher(input).matches()) {
            return true;
        }
    }
    return false;
}

From source file:com.cloudbees.plugins.deployer.impl.run.RunDeployedApplicationLocation.java

public RunDeployedApplicationLocation(@NonNull String applicationId, @NonNull String applicationEnvironment,
        @NonNull String appURL) {
    super(appURL);
    applicationId.getClass(); // throw NPE if null
    applicationEnvironment.getClass(); // throw NPE if null
    this.applicationId = applicationId;
    this.applicationEnvironment = applicationEnvironment;
}

From source file:com.ikanow.aleph2.v1.document_db.hadoop.assets.TestAleph2V1InputFormat.java

@Test
public void test_V1DocumentDbRecordReader_objectConversion() throws IOException, InterruptedException {

    @SuppressWarnings("unchecked")
    final RecordReader<Object, BSONObject> mock_record_reader = (RecordReader<Object, BSONObject>) Mockito
            .mock(RecordReader.class);
    Mockito.when(mock_record_reader.getCurrentKey()).thenReturn("text_test");
    final BasicDBObject test_ret = new BasicDBObject();
    test_ret.put("val_key_text", "val_val_text");
    Mockito.when(mock_record_reader.getCurrentValue()).thenReturn(test_ret);

    try (final V1DocumentDbRecordReader reader_under_test = new V1DocumentDbRecordReader(mock_record_reader)) {

        final String key = reader_under_test.getCurrentKey();
        assertEquals(String.class, key.getClass());
        assertEquals("text_test", key);

        final Tuple2<Long, IBatchRecord> value = reader_under_test.getCurrentValue();
        assertEquals(0L, value._1().longValue()); // (so something breaks in here when/if we put some logic in)
        assertEquals(Optional.empty(), value._2().getContent());
        final JsonNode json_val = value._2().getJson();
        assertTrue("Is object: " + json_val, json_val.isObject());
        assertEquals("val_val_text", json_val.get("val_key_text").asText());
    }//from  ww w.  ja v  a 2  s  .c o m
}

From source file:com.ikanow.aleph2.search_service.elasticsearch.hadoop.assets.TestAleph2EsInputFormat.java

@Test
public void test_Aleph2EsRecordReader_objectConversion() throws IOException, InterruptedException {

    @SuppressWarnings("rawtypes")
    final RecordReader mock_shard_record_reader = Mockito.mock(RecordReader.class);

    // mock returns Text key, MapWritable value
    Mockito.when(mock_shard_record_reader.getCurrentKey()).thenReturn(new Text("text_test"));

    final MapWritable test_out = new MapWritable();
    test_out.put(new Text("val_key_text"), new Text("val_val_text"));

    Mockito.when(mock_shard_record_reader.getCurrentValue()).thenReturn(test_out);

    final Aleph2EsRecordReader reader_under_test = new Aleph2EsRecordReader(mock_shard_record_reader);

    final String key = reader_under_test.getCurrentKey();
    assertEquals(String.class, key.getClass());
    assertEquals("text_test", key);

    final Tuple2<Long, IBatchRecord> value = reader_under_test.getCurrentValue();
    assertEquals(0L, value._1().longValue()); // (so something breaks in here when/if we put some logic in)
    assertEquals(Optional.empty(), value._2().getContent());
    final JsonNode json_val = value._2().getJson();
    assertTrue("Is object: " + json_val, json_val.isObject());
    assertEquals("val_val_text", json_val.get("val_key_text").asText());
    assertEquals("text_test", json_val.get("_id").asText());
}

From source file:de.topicmapslab.kuria.runtime.util.TypeUtilTest.java

@SuppressWarnings("unchecked")
@Test//from  w  w w  . j  a v a 2s.  c o  m
public void testGetContainerType() {
    String[] tmp3 = new String[10];
    assertEquals("Check String array: ", String.class, TypeUtil.getContainerType(tmp3.getClass()));

    String tmp4[] = new String[10];
    assertEquals("Check String array: ", String.class, TypeUtil.getContainerType(tmp4.getClass()));

    try {
        Field field = TypeUtilTest.class.getDeclaredField("stringList");
        assertEquals("Check List: ", String.class, TypeUtil.getContainerType(field.getGenericType()));
        assertTrue("Check Vector: ", TypeUtil.isList(field.getGenericType()));

        field = TypeUtilTest.class.getDeclaredField("stringList2");
        assertEquals("Check ArrayListV: ", String.class, TypeUtil.getContainerType(field.getGenericType()));
        assertTrue("Check Vector: ", TypeUtil.isList(field.getGenericType()));

        field = TypeUtilTest.class.getDeclaredField("stringList3");
        assertEquals("Check Vector: ", String.class, TypeUtil.getContainerType(field.getGenericType()));
        assertTrue("Check Vector: ", TypeUtil.isList(field.getGenericType()));

        field = TypeUtilTest.class.getDeclaredField("stack");
        assertEquals("Check Stack: ", Object.class, TypeUtil.getContainerType(field.getGenericType()));

        field = TypeUtilTest.class.getDeclaredField("set1");
        assertEquals("Check Sets Parameter: ", Integer.class,
                TypeUtil.getContainerType(field.getGenericType()));
        assertTrue("Check Set: ", TypeUtil.isSet(field.getGenericType()));

        field = TypeUtilTest.class.getDeclaredField("set2");
        assertEquals("Check HashSet: ", Integer.class, TypeUtil.getContainerType(field.getGenericType()));
        assertTrue("Check HashSet: ", TypeUtil.isSet(field.getGenericType()));

        field = TypeUtilTest.class.getDeclaredField("set3");
        assertEquals("Check untyped Set: ", Object.class, TypeUtil.getContainerType(field.getGenericType()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    // expecting object because no real reflection possible on var types.
    List<String> tmp = new ArrayList<String>();
    assertEquals("Check ArrayList: ", Object.class, TypeUtil.getContainerType(tmp.getClass()));
    tmp = new ArrayStack();
    assertEquals("Check ArrayList: ", Object.class, TypeUtil.getContainerType(tmp.getClass()));
    tmp = new Vector<String>();
    assertEquals("Check ArrayList: ", Object.class, TypeUtil.getContainerType(tmp.getClass()));

    Set<Integer> tmp2 = new HashSet<Integer>();
    assertEquals("Check HashSet: ", Object.class, TypeUtil.getContainerType(tmp2.getClass()));

    try {
        TypeUtil.getContainerType(String.class);
    } catch (IllegalArgumentException e) {
        return;
    }
    fail("No exception thrown");
}

From source file:org.apache.catalina.mbeans.ConnectorMBean.java

/**
 * Set keystorePass/*  w w  w  .j  av a2 s  . com*/
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public void setKeystorePass(String keystorePass) throws Exception {

    if (keystorePass == null) {
        keystorePass = "";
    }
    Class coyoteConnectorCls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
    if (coyoteConnectorCls.isInstance(this.resource)) {
        // get factory
        Method meth1 = coyoteConnectorCls.getMethod("getFactory", null);
        Object factory = meth1.invoke(this.resource, null);
        Class coyoteServerSocketFactoryCls = Class
                .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
        if (coyoteServerSocketFactoryCls.isInstance(factory)) {
            // set keystorePass
            Class partypes2[] = new Class[1];
            String str = new String();
            partypes2[0] = str.getClass();
            Method meth2 = coyoteServerSocketFactoryCls.getMethod("setKeystorePass", partypes2);
            Object arglist2[] = new Object[1];
            arglist2[0] = keystorePass;
            meth2.invoke(factory, arglist2);
        }
    }
}

From source file:org.apache.catalina.mbeans.ConnectorMBean.java

/**
 * Set keystoreFile//from   w w w.j  av  a2  s  .c  om
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public void setKeystoreFile(String keystoreFile) throws Exception {

    if (keystoreFile == null) {
        keystoreFile = "";
    }
    Class coyoteConnectorCls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
    if (coyoteConnectorCls.isInstance(this.resource)) {
        // get factory
        Method meth1 = coyoteConnectorCls.getMethod("getFactory", null);
        Object factory = meth1.invoke(this.resource, null);
        Class coyoteServerSocketFactoryCls = Class
                .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
        if (coyoteServerSocketFactoryCls.isInstance(factory)) {
            // set keystoreFile
            Class partypes2[] = new Class[1];
            String str = new String();
            partypes2[0] = str.getClass();
            Method meth2 = coyoteServerSocketFactoryCls.getMethod("setKeystoreFile", partypes2);
            Object arglist2[] = new Object[1];
            arglist2[0] = keystoreFile;
            meth2.invoke(factory, arglist2);
        }

    }
}

From source file:com.adaptris.core.fs.AggregatingFsConsumer.java

private FileFilter createFileFilter(String filterExpression) throws Exception {
    Class[] paramTypes = { filterExpression.getClass() };
    Object[] args = { filterExpression };

    Class c = Class.forName(fileFilterImp());
    Constructor cnst = c.getDeclaredConstructor(paramTypes);
    return (FileFilter) cnst.newInstance(args);
}