List of usage examples for java.util List getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static void main(String[] args) { List<Integer> list = new LinkedList<Integer>(); list.add(1);/*from w w w .jav a 2 s .c o m*/ List<Integer> unmodifiableList = Collections.unmodifiableList(list); System.out.println(unmodifiableList.getClass()); if (unmodifiableList.getClass().getName().contains("UnmodifiableList")) System.out.println(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { String WRITE_OBJECT_SQL = "BEGIN " + " INSERT INTO java_objects(object_id, object_name, object_value) " + " VALUES (?, ?, empty_blob()) " + " RETURN object_value INTO ?; " + "END;"; String READ_OBJECT_SQL = "SELECT object_value FROM java_objects WHERE object_id = ?"; Connection conn = getOracleConnection(); conn.setAutoCommit(false);//w w w .ja v a 2 s . c o m List<Object> list = new ArrayList<Object>(); list.add("This is a short string."); list.add(new Integer(1234)); list.add(new java.util.Date()); // write object to Oracle long id = 0001; String className = list.getClass().getName(); CallableStatement cstmt = conn.prepareCall(WRITE_OBJECT_SQL); cstmt.setLong(1, id); cstmt.setString(2, className); cstmt.registerOutParameter(3, java.sql.Types.BLOB); cstmt.executeUpdate(); BLOB blob = (BLOB) cstmt.getBlob(3); OutputStream os = blob.getBinaryOutputStream(); ObjectOutputStream oop = new ObjectOutputStream(os); oop.writeObject(list); oop.flush(); oop.close(); os.close(); // Read object from oracle PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL); pstmt.setLong(1, id); ResultSet rs = pstmt.executeQuery(); rs.next(); InputStream is = rs.getBlob(1).getBinaryStream(); ObjectInputStream oip = new ObjectInputStream(is); Object object = oip.readObject(); className = object.getClass().getName(); oip.close(); is.close(); rs.close(); pstmt.close(); conn.commit(); // de-serialize list a java object from a given objectID List listFromDatabase = (List) object; System.out.println("[After De-Serialization] list=" + listFromDatabase); conn.close(); }
From source file:Main.java
@NonNull public static Class getListTypeClass(List<?> list) { Class elementType;// www .j av a 2 s. c o m if (isEmpty(list)) { final Class<? extends List> listClass = list.getClass(); final ParameterizedType genericSuperclass = (ParameterizedType) listClass.getGenericSuperclass(); elementType = (Class) genericSuperclass.getActualTypeArguments()[0]; } else { elementType = list.get(0).getClass(); } return elementType; }
From source file:Main.java
/** * Wraps a List with the {@code Collections.unmodifiableList}, but only once. * * <p>Checks the {@link List} passed to ensure that it is not already a {@code Collections.unmodifiableLisy}. * If the parameter is a null or empty, then it returns {@code Collections.emptyList}. * * @param list {@link List} to wrap with {@code Collections.unmodifiableList} * @param <V> Value type/*from w ww. j av a 2s . co m*/ * @return An unmodifiable List. */ public static <V> List<V> unmodifiableList(final List<V> list) { if (isNotEmpty(list)) { if (!(exampleUnmodifiableList.getClass().equals(list.getClass()))) { return Collections.unmodifiableList(list); } return list; } return Collections.emptyList(); }
From source file:com.cedarsoft.history.core.GlazedPerformanceTest.java
private static StopWatch checkPerformance(@Nonnull List<String> list) { StopWatch stopWatch = new StopWatch(); stopWatch.start("adding to " + list.getClass().getName()); for (int i = 0; i < 100000; i++) { list.add(String.valueOf(i)); }// w w w .ja va2 s. c o m stopWatch.stop(); stopWatch.start("iterating through " + list.getClass().getName()); for (String currentEntry : list) { assertNotNull(currentEntry); } stopWatch.stop(); assertNotNull(stopWatch); return stopWatch; }
From source file:projekat.rest_client.Test.java
public static void mainsss(String[] args) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, KeyManagementException, Exception { // String uri = "https://localhost:8443/secure/rest/clients/search/as"; RestTemplateFactory factory = new RestTemplateFactory(); factory.afterPropertiesSet();// ww w . j a v a 2s.c o m String uri = "https://localhost:8443/secure/rest/places"; String uri2 = "https://localhost:8443/secure/rest/clients/search/8"; Response<List<Mesto>> executeGetRequest = factory.executeRequest(uri, (Class<List<Mesto>>) (Object) List.class, HttpMethod.GET); Response<LinkedList<Klijent>> executeRequest = factory.executeRequest(uri2, (Class<LinkedList<Klijent>>) (Object) LinkedList.class, HttpMethod.GET); List<Klijent> data = executeRequest.getData(); System.out.println("Tip liste: " + data.getClass().getSimpleName()); for (Klijent klijent : data) { System.out.println("Klijent: " + klijent.getIme()); } List<Mesto> mesta = executeGetRequest.getData(); System.out.println(mesta); for (Mesto m : mesta) { System.out.println("Mesto: " + m); } }
From source file:naftoreiclag.flowchartarch.ParseFiler.java
public static Genes readGenes() throws IOException { List<String> data = FileUtils.readLines(new File("file.txt")); System.out.println(data.getClass().toString()); System.out.println(data.size()); Genes genes = new Genes(); List<Element> linage = new ArrayList<Element>(); linage.add(0, genes);/*from w w w. ja va2 s .c o m*/ for (String line : data) { // Track where we are on the string int head = 0; // Depth for (; head < line.length(); ++head) { if (line.charAt(head) != tab) { break; } } int depth = head; if (depth < 1) { continue; } // Type name for (; head < line.length(); ++head) { if (line.charAt(head) == sep) { break; } } String name = line.substring(depth, head); ++head; System.out.println("depth: " + depth + " type: " + name); // parse accordingly Element el = parse(name); linage.add(depth, el); linage.get(depth - 1).addChild(el); } return genes; }
From source file:org.rivalry.core.funcprog.ListUtils.java
/** * @param list List.//from w w w .j av a 2s. c o m * * @return a new instance of the given type of list. */ private static <E> List<E> newInstance(final List<E> list) { List<E> answer = null; try { @SuppressWarnings("unchecked") final List<E> newList = list.getClass().newInstance(); answer = newList; } catch (final InstantiationException e) { throw new RuntimeException(e.getMessage()); } catch (final IllegalAccessException e) { throw new RuntimeException(e.getMessage()); } return answer; }
From source file:Lists.java
public static <T> List<T> normalize(List<T> list) { switch (list.size()) { case 0://from w w w . j ava 2 s. co m return create(); case 1: { if (list.getClass() == SINGLETON_LIST_CLASS) { return list; } return create(list.get(0)); } default: if (list.getClass() == MULTI_LIST_CLASS) { return list; } return new ArrayList<T>(list); } }
From source file:org.docx4j.template.utils.WMLPackageUtils.java
public static <T> List<T> getChildrenElements(Object source, Class<T> targetClass) { List<T> result = new ArrayList<T>(); //?/*from w w w . j a va 2s. c o m*/ Object target = XmlUtils.unwrap(source); //if (target.getClass().equals(targetClass)) { if (targetClass.isAssignableFrom(target.getClass())) { result.add((T) target); } else if (target instanceof ContentAccessor) { List<?> children = ((ContentAccessor) target).getContent(); //if (children.getClass().equals(targetClass)) { if (targetClass.isAssignableFrom(children.getClass())) { result.add((T) children); } } return result; }