List of usage examples for java.lang String getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:fr.landel.utils.assertor.OperatorTest.java
/** * Test method for {@link Operator#nor()}. *//* www.ja va 2 s.com*/ @Test public void testNor() { final String text = "text"; assertTrue(Assertor.that(text).isEmpty().nor().isNotBlank().isOK()); assertTrue(Assertor.that(text).isNotEmpty().nor().isBlank().isOK()); assertTrue(Assertor.that(text).isEmpty().nor().isBlank().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(true).isTrue().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(true).isFalse().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(text.getClass()).isAssignableFrom(CharSequence.class).isOK()); assertTrue(Assertor.that(text).isEmpty().nor(text.getClass()).isAssignableFrom(StringBuilder.class).isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Calendar.getInstance()) .isAfter(DateUtils.getCalendar(new Date(0))).isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Calendar.getInstance()) .isBefore(DateUtils.getCalendar(new Date(0))).isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new Date()).isAfter(new Date(0)).isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new Date()).isBefore(new Date(0)).isOK()); assertTrue(Assertor.that(text).isNotEmpty().nor(LocalDateTime.now()).isAfter(LocalDateTime.MAX).isOK()); assertFalse(Assertor.that(text).isNotEmpty().nor(LocalDateTime.now()).isAfter(LocalDateTime.MIN).isOK()); assertTrue(Assertor.that(text).isEmpty().nor(2).isGT(1).isOK()); assertTrue(Assertor.that(text).isEmpty().nor(2).isLT(1).isOK()); assertTrue(Assertor.that(text).isEmpty().nor("tt").isNotEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor("tt").isEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new String[] {}).isEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new String[] {}).isNotEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new String[] {}, EnumAnalysisMode.STREAM).isEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new String[] {}, EnumAnalysisMode.STREAM).isNotEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new String[] {}, EnumAnalysisMode.PARALLEL).isEmpty().isOK()); assertTrue( Assertor.that(text).isEmpty().nor(new String[] {}, EnumAnalysisMode.PARALLEL).isNotEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyList()).isEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyList()).isNotEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyList(), EnumAnalysisMode.STREAM).isEmpty() .isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyList(), EnumAnalysisMode.STREAM).isNotEmpty() .isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyList(), EnumAnalysisMode.PARALLEL).isEmpty() .isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyList(), EnumAnalysisMode.PARALLEL) .isNotEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyMap()).isEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyMap()).isNotEmpty().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyMap(), EnumAnalysisMode.STREAM).isEmpty() .isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyMap(), EnumAnalysisMode.STREAM).isNotEmpty() .isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isEmpty() .isOK()); assertTrue(Assertor.that(text).isEmpty().nor(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isNotEmpty() .isOK()); assertTrue(Assertor.that(text).isEmpty().nor((Object) 0).isNotNull().isOK()); assertTrue(Assertor.that(text).isEmpty().nor((Object) 0).isNull().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new Exception()).isNotNull().isOK()); assertTrue(Assertor.that(text).isEmpty().nor(new Exception()).isNull().isOK()); assertTrue(Assertor.that(Color.BLACK).isNull().nor().isEqual(Color.black).isOK()); assertTrue(Assertor.that(Color.BLACK).isNull().nor((Object) 0).isNotNull().isOK()); assertTrue(Assertor.that(Color.BLACK).isNotNull().nor(Assertor.that(text).isEmpty()).isOK()); // SUB ASSERTOR assertTrue(Assertor.that(text).isNotEmpty().norAssertor(t -> Assertor.that(t.length()).isGT(4)).isOK()); assertEquals("the char sequence 'text' should be null or empty", Assertor.that(text).isEmpty() .norAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get()); assertException( () -> Assertor.that(text).isNotEmpty() .norAssertor((Function<String, StepCharSequence<String>>) null).isOK(), IllegalStateException.class, "sub assertor cannot be null"); // MAPPER assertTrue(Assertor.that(false).isTrue().norObject(b -> b.toString()).hasHashCode(Objects.hashCode("true")) .isOK()); assertTrue(Assertor.that(false).isTrue().norCharSequence(b -> b.toString()).contains("ue").isOK()); assertTrue(Assertor.that("test").isNotEmpty() .norArray(s -> ArrayUtils.toObject(s.getBytes(StandardCharsets.UTF_8))).contains((byte) 'x') .isOK()); assertTrue(Assertor.that(false).isTrue().norBoolean(b -> !b).isFalse().isOK()); assertTrue(Assertor.that(false).isTrue().norClass(b -> b.getClass()).hasSimpleName("Boolean").isOK()); assertTrue(Assertor.that(false).isTrue().norDate(b -> new Date(1464475553641L)) .isAfter(new Date(1464475553640L)).isOK()); assertTrue(Assertor.that(false).isTrue().norCalendar(b -> DateUtils.getCalendar(new Date(1464475553641L))) .isBefore(Calendar.getInstance()).isOK()); assertTrue( Assertor.that(false).isTrue().norTemporal(b -> DateUtils.getLocalDateTime(new Date(1464475553641L))) .isBefore(LocalDateTime.now()).isOK()); assertTrue(Assertor.that(false).isTrue().norEnum(b -> EnumOperator.AND).hasName("AND").isOK()); assertTrue(Assertor.that(false).isTrue().norIterable(b -> Arrays.asList('t', 'r')).contains('t').isOK()); assertTrue(Assertor.that(false).isTrue().norMap(b -> MapUtils2.newHashMap("key", b)).contains("key", true) .isOK()); assertTrue(Assertor.that(false).isTrue().norNumber(b -> b.hashCode()).isGT(0).isOK()); // 1231 assertTrue(Assertor.that(false).isTrue().norThrowable(b -> new IOException(b.toString())) .validates(e -> e.getMessage().contains("true")).isOK()); }
From source file:net.refractions.udig.catalog.internal.CatalogImpl.java
/** * Returns a list of friendly resources working with related data. * <p>/*from w ww .j a v a2 s .c o m*/ * This method is used internally to determine resource handles that * offer different entry points to the same information. * </p> * A friend can be found via: * <ul> * <li>Making use of a CSW2.0 association * <li>URL Pattern matching for well known cases like GeoServer and MapServer * <li>Service Metadata, for example WMS resourceURL referencing a WFS SimpleFeatureType * </ul> * All of these handles will be returned from the find( URL, monitor ) method. * </ul> * @param handle * @return List of frends, possibly empty */ public List<IResolve> friends(final IResolve handle) { final List<IResolve> friends = new ArrayList<IResolve>(); ExtensionPointUtil.process(CatalogPlugin.getDefault(), "net.refractions.udig.catalog.friendly", //$NON-NLS-1$ new ExtensionPointProcessor() { /** * Lets find our friends. */ public void process(IExtension extension, IConfigurationElement element) throws Exception { try { String target = element.getAttribute("target"); //$NON-NLS-1$ String contain = element.getAttribute("contain"); //$NON-NLS-1$ if (target != null) { // perform target check if (target.equals(target.getClass().toString())) { return; } } if (contain != null) { String uri = handle.getIdentifier().toExternalForm(); if (!uri.contains(contain)) { return; } } IFriend friendly = (IFriend) element.createExecutableExtension("class"); //$NON-NLS-1$ friends.addAll(friendly.friendly(handle, null)); } catch (Throwable t) { CatalogPlugin.log(t.getLocalizedMessage(), t); } } }); return friends; }
From source file:org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.java
protected List<Advice> extractAdviceChain(String beanName, List<Annotation> annotations) { List<Advice> adviceChain = null; String[] adviceChainNames = MessagingAnnotationUtils.resolveAttribute(annotations, ADVICE_CHAIN_ATTRIBUTE, String[].class); /*/* w w w . j a va 2 s . c o m*/ * Note: we don't merge advice chain contents; if the directAnnotation has a non-empty * attribute, it wins. You cannot "remove" an advice chain from a meta-annotation * by setting an empty array on the custom annotation. */ if (adviceChainNames != null && adviceChainNames.length > 0) { adviceChain = new ArrayList<Advice>(); for (String adviceChainName : adviceChainNames) { Object adviceChainBean = this.beanFactory.getBean(adviceChainName); if (adviceChainBean instanceof Advice) { adviceChain.add((Advice) adviceChainBean); } else if (adviceChainBean instanceof Advice[]) { Collections.addAll(adviceChain, (Advice[]) adviceChainBean); } else if (adviceChainBean instanceof Collection) { @SuppressWarnings("unchecked") Collection<Advice> adviceChainEntries = (Collection<Advice>) adviceChainBean; for (Advice advice : adviceChainEntries) { adviceChain.add(advice); } } else { throw new IllegalArgumentException("Invalid advice chain type:" + adviceChainName.getClass().getName() + " for bean '" + beanName + "'"); } } } return adviceChain; }
From source file:com.korrelate.pig.hbase.HBaseStorage.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a 2s . c om public void putNext(Tuple t) throws IOException { ResourceFieldSchema[] fieldSchemas = (schema_ == null) ? null : schema_.getFields(); byte type = (fieldSchemas == null) ? DataType.findType(t.get(0)) : fieldSchemas[0].getType(); Long fieldTs = (Long) t.get(timestampVersionFieldIndex_); if (fieldTs != null) { LOG.info("TIMESTAMP: " + fieldTs); } long ts = (timestampVersionFieldIndex_ == -1 || fieldTs == null) ? System.currentTimeMillis() : new Long(fieldTs); Put put = createPut(t.get(0), type); if (LOG.isDebugEnabled()) { LOG.debug("putNext -- WAL disabled: " + noWAL_); 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()) { 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. put.add(columnInfo.getColumnFamily(), Bytes.toBytes(colName.toString()), ts, objToBytes(cfMap.get(colName), DataType.findType(cfMap.get(colName)))); } } } try { writer.write(null, put); } catch (InterruptedException e) { throw new IOException(e); } }
From source file:com.hubspot.jinjava.lib.tag.ForTag.java
@SuppressWarnings("unchecked") @Override/*from w ww .j a va2s .c om*/ public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) { List<String> helper = new HelperStringTokenizer(tagNode.getHelpers()).splitComma(true).allTokens(); List<String> loopVars = Lists.newArrayList(); int inPos = 0; while (inPos < helper.size()) { String val = helper.get(inPos); if ("in".equals(val)) { break; } else { loopVars.add(val); inPos++; } } if (inPos >= helper.size()) { throw new TemplateSyntaxException(tagNode.getMaster().getImage(), "Tag 'for' expects valid 'in' clause, got: " + tagNode.getHelpers(), tagNode.getLineNumber()); } String loopExpr = StringUtils.join(helper.subList(inPos + 1, helper.size()), ","); Object collection = interpreter.resolveELExpression(loopExpr, tagNode.getLineNumber()); ForLoop loop = ObjectIterator.getLoop(collection); try (InterpreterScopeClosable c = interpreter.enterScope()) { interpreter.getContext().put(LOOP, loop); StringBuilder buff = new StringBuilder(); while (loop.hasNext()) { Object val = loop.next(); // set item variables if (loopVars.size() == 1) { interpreter.getContext().put(loopVars.get(0), val); } else { for (String loopVar : loopVars) { if (Map.Entry.class.isAssignableFrom(val.getClass())) { Map.Entry<String, Object> entry = (Entry<String, Object>) val; Object entryVal = null; if ("key".equals(loopVar)) { entryVal = entry.getKey(); } else if ("value".equals(loopVar)) { entryVal = entry.getValue(); } interpreter.getContext().put(loopVar, entryVal); } else { try { PropertyDescriptor[] valProps = Introspector.getBeanInfo(val.getClass()) .getPropertyDescriptors(); for (PropertyDescriptor valProp : valProps) { if (loopVar.equals(valProp.getName())) { interpreter.getContext().put(loopVar, valProp.getReadMethod().invoke(val)); break; } } } catch (Exception e) { throw new InterpretException(e.getMessage(), e, tagNode.getLineNumber()); } } } } for (Node node : tagNode.getChildren()) { buff.append(node.render(interpreter)); } } return buff.toString(); } }
From source file:net.tachtler.browscap4j.Browscap4jFileReader.java
/** * Initialize the Browscap4jDataBean.// ww w . jav a 2s . c o m * * @param csvFile * @return Browscap4jDataBean * @throws IllegalStateException * @throws FileNotFoundException * @throws IOException */ public static Browscap4jDataBean initBrowscap4jData(File csvFile) throws IllegalStateException, FileNotFoundException, IOException { log.debug("*csvFile : " + csvFile); /** * Browscap4jDataBean with the LinkedHashMap<Pattern, Browscap4jPositionBean> * browscap4jMap and the String browscap4jString as data. */ Browscap4jDataBean browscap4jDataBean = new Browscap4jDataBean(); /** * LinkedHashMap with regular expression pattern as key from the original * userAgentString and Browscap4jPositionBean integer variables as value object * by determining the offset and the length for each line. */ LinkedHashMap<Pattern, Browscap4jPositionBean> browscap4jMap = new LinkedHashMap<Pattern, Browscap4jPositionBean>(); /** * Generate browscap4jString with all fields filled up with data from * browscap.csv to a single String. */ String browscap4jString = null; /** * StringBuilder for fast concatenation. */ StringBuilder stringBuilder = new StringBuilder(); /* * Check if csvFile is null. */ if (null == csvFile) { throw new IllegalStateException("Argument csvFile is null (NOT set)."); } /* * Iterate over the csvFile - browscap.csv with all the data and generate a * string with all the lines concatenated. Generate a regular expression pattern * from the first column of the csvFile - browscap.csv as key and calculate the * offset and the length for every single line inside the concatenated string as * Browscap4jPositionBean as value. */ LineIterator lineIterator = FileUtils.lineIterator(csvFile, "UTF-8"); try { int offset = 0; String[] col = null; while (lineIterator.hasNext()) { String line = lineIterator.nextLine(); Browscap4jPositionBean browscap4jPositionBean = new Browscap4jPositionBean(offset, offset + line.length()); offset += line.length(); col = line.split("\",\""); browscap4jMap.put(Pattern.compile(convertToRegex(col[0].substring(1))), browscap4jPositionBean); stringBuilder.append(line); } } finally { LineIterator.closeQuietly(lineIterator); } /* * Generate the String browscap4jString from StringBuilder stringBuilder. */ browscap4jString = stringBuilder.toString(); /* * Debug NOT the Map and the String, because of too much entry's, only the class * should be printed out in debug mode, to see if the browscap4jMap and the * browscap4jString are NOT null. */ log.debug("*browscap4jMap : " + browscap4jMap.getClass()); log.debug("*browscap4jString : " + browscap4jString.getClass()); browscap4jDataBean.setBrowscap4jMap(browscap4jMap); browscap4jDataBean.setBrowscap4jString(browscap4jString); return browscap4jDataBean; }
From source file:org.seasar.dbflute.logic.replaceschema.loaddata.impl.DfAbsractDataWriter.java
protected void processNotNullString(File dataFile, String tableName, String columnName, String value, Connection conn, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap) throws SQLException { if (value == null) { String msg = "This method is only for NotNull and StringExpression:"; msg = msg + " value=" + value + " type=" + (value != null ? value.getClass() : "null"); throw new IllegalStateException(msg); }/* w w w .j a v a 2 s . c om*/ value = Srl.unquoteDouble(value); Map<String, StringProcessor> cacheMap = _stringProcessorCacheMap.get(tableName); if (cacheMap == null) { cacheMap = StringKeyMap.createAsFlexibleOrdered(); _stringProcessorCacheMap.put(tableName, cacheMap); } final StringProcessor processor = cacheMap.get(columnName); if (processor != null) { // cache hit final boolean processed = processor.process(dataFile, tableName, columnName, value, conn, ps, bindCount, columnInfoMap); if (!processed) { throwColumnValueProcessingFailureException(processor, tableName, columnName, value); } return; } for (StringProcessor tryProcessor : _stringProcessorList) { // processing and searching target processor if (tryProcessor.process(dataFile, tableName, columnName, value, conn, ps, bindCount, columnInfoMap)) { cacheMap.put(columnName, tryProcessor); // use cache next times break; } } // must be bound here // (_stringProcessorList has processor for real string) }
From source file:catalina.mbeans.MBeanFactory.java
/** * Create a new HttpConnector/* w w w .ja v a 2 s . c om*/ * * @param parent MBean Name of the associated parent component * @param address The IP address on which to bind * @param port TCP port number to listen on * * @exception Exception if an MBean cannot be created or registered */ public String createHttpConnector(String parent, String address, int port) throws Exception { Object retobj = null; try { // Create a new CoyoteConnector instance // use reflection to avoid j-t-c compile-time circular dependencies Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); Constructor ct = cls.getConstructor(null); retobj = ct.newInstance(null); Class partypes1[] = new Class[1]; // Set address String str = new String(); partypes1[0] = str.getClass(); Method meth1 = cls.getMethod("setAddress", partypes1); Object arglist1[] = new Object[1]; arglist1[0] = address; meth1.invoke(retobj, arglist1); // Set port number Class partypes2[] = new Class[1]; partypes2[0] = Integer.TYPE; Method meth2 = cls.getMethod("setPort", partypes2); Object arglist2[] = new Object[1]; arglist2[0] = new Integer(port); meth2.invoke(retobj, arglist2); } catch (Exception e) { throw new MBeanException(e); } // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Server server = ServerFactory.getServer(); Service service = server.findService(pname.getKeyProperty("name")); service.addConnector((Connector) retobj); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("CoyoteConnector"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), (Connector) retobj); return (oname.toString()); }
From source file:catalina.mbeans.MBeanFactory.java
/** * Create a new AjpConnector// ww w.ja v a 2s . c om * * @param parent MBean Name of the associated parent component * @param address The IP address on which to bind * @param port TCP port number to listen on * * @exception Exception if an MBean cannot be created or registered */ public String createAjpConnector(String parent, String address, int port) throws Exception { Object retobj = null; try { // Create a new CoyoteConnector instance for AJP // use reflection to avoid j-t-c compile-time circular dependencies Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); Constructor ct = cls.getConstructor(null); retobj = ct.newInstance(null); Class partypes1[] = new Class[1]; // Set address String str = new String(); partypes1[0] = str.getClass(); Method meth1 = cls.getMethod("setAddress", partypes1); Object arglist1[] = new Object[1]; arglist1[0] = address; meth1.invoke(retobj, arglist1); // Set port number Class partypes2[] = new Class[1]; partypes2[0] = Integer.TYPE; Method meth2 = cls.getMethod("setPort", partypes2); Object arglist2[] = new Object[1]; arglist2[0] = new Integer(port); meth2.invoke(retobj, arglist2); // set protocolHandlerClassName for AJP Class partypes3[] = new Class[1]; partypes3[0] = str.getClass(); Method meth3 = cls.getMethod("setProtocolHandlerClassName", partypes3); Object arglist3[] = new Object[1]; arglist3[0] = new String("org.apache.jk.server.JkCoyoteHandler"); meth3.invoke(retobj, arglist3); } catch (Exception e) { throw new MBeanException(e); } // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Server server = ServerFactory.getServer(); Service service = server.findService(pname.getKeyProperty("name")); service.addConnector((Connector) retobj); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("CoyoteConnector"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), (Connector) retobj); return (oname.toString()); }
From source file:com.bac.accountserviceapp.data.mysql.MysqlAccountServiceAppSpringAuthenticationTest.java
@Test public void testAuthentication_InvalidUserName() throws NoSuchAlgorithmException { logger.info("testAuthentication_InvalidUserName"); try {// ww w. j a va 2s . c o m createUserAccount(); final String invalidUserEmail = UUID.randomUUID().toString(); // // Authenticate // UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( invalidUserEmail, userPassword); Authentication resultAuthentication = instance.login(authentication); assertNotNull(resultAuthentication); // // Check the outcome // authenticateOutcome(resultAuthentication, UNKNOWN_PRINCIPAL); // // Get the Authentication Principal: It should represent the invalid user name // authenticatePrincipal(resultAuthentication, invalidUserEmail.getClass()); assertEquals(invalidUserEmail, resultAuthentication.getPrincipal()); // // Ensure that no Authority has been granted // Collection<? extends GrantedAuthority> authorities = resultAuthentication.getAuthorities(); assertNotNull(authorities); int expAuthoritySize = 0; int resultAuthoritySize = authorities.size(); assertEquals(expAuthoritySize, resultAuthoritySize); } catch (InvalidKeySpecException ex) { logger.error("Password encryption error"); } finally { // Clean up logger.info("testAuthentication: Delete"); deleteUserAccount(); } }