List of usage examples for org.apache.commons.lang3 ArrayUtils nullToEmpty
public static Boolean[] nullToEmpty(final Boolean[] array)
Defensive programming technique to change a null reference to an empty one.
This method returns an empty array for a null input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.
From source file:com.omnigon.aem.common.utils.ParserUtil.java
/** * * @param array incoming parameters/*from w w w .j a va 2s.co m*/ * @param type type of Object to map * @param <T> - * @return Object with mapped parameters */ public static <T> ImmutableList<T> parseJsonArray(String[] array, Class<T> type) { final ImmutableList.Builder<T> builder = ImmutableList.builder(); final ObjectReader reader = OBJECT_MAPPER.reader(type); for (String element : ArrayUtils.nullToEmpty(array)) { try { builder.add(reader.<T>readValue(element)); } catch (IOException e) { LOGGER.warn(e.getMessage(), e); } } return builder.build(); }
From source file:edu.umich.flowfence.service.NamespaceSharedPrefs.java
public static NamespaceSharedPrefs get(SharedPreferences basePrefs, String taintSetNamespace, String... taintNamespaces) { Objects.requireNonNull(taintSetNamespace); taintNamespaces = ArrayUtils.nullToEmpty(taintNamespaces); if (taintNamespaces.length == 0) { throw new IllegalArgumentException("Need at least one taint namespace!"); }/*from ww w . j a va2s .c om*/ Set<String> taintNamespaceSet = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(taintNamespaces))); if (taintNamespaceSet.contains(taintSetNamespace)) { throw new IllegalArgumentException("Taint set namespace also a taint namespace"); } synchronized (g_mPrefsLookup) { NamespaceSharedPrefs prefsStrong = null; WeakReference<NamespaceSharedPrefs> prefsWeak = g_mPrefsLookup.get(basePrefs); if (prefsWeak != null) { prefsStrong = prefsWeak.get(); } if (prefsStrong != null) { if (!taintSetNamespace.equals(prefsStrong.mTaintSetNamespace) || !taintNamespaceSet.equals(prefsStrong.mTaintNamespaces)) { Log.w(TAG, String.format( "Inconsistent initialization: " + "initialized with TS=%s T=%s, retrieved with TS=%s T=%s", prefsStrong.mTaintSetNamespace, prefsStrong.mTaintNamespaces, taintSetNamespace, taintNamespaceSet)); } } else { prefsStrong = new NamespaceSharedPrefs(basePrefs, taintSetNamespace, taintNamespaceSet); prefsWeak = new WeakReference<>(prefsStrong); g_mPrefsLookup.put(basePrefs, prefsWeak); } return prefsStrong; } }
From source file:net.sf.jsignpdf.JTextAreaAppender.java
@Override protected void append(LoggingEvent event) { if (layout == null) { errorHandler.error("No layout for appender " + name, null, ErrorCode.MISSING_LAYOUT); return;/*from w ww .ja va2 s.co m*/ } final String message = layout.format(event); jTextArea.append(message); //TODO do we need this code if (layout.ignoresThrowable()) { for (String throwableRow : ArrayUtils.nullToEmpty(event.getThrowableStrRep())) { jTextArea.append(throwableRow + NEW_LINE); } } // scroll TextArea jTextArea.setCaretPosition(jTextArea.getText().length()); }
From source file:com.l2jfree.network.ClientProtocolVersion.java
private ClientProtocolVersion(int version, int op2TableSize, int[] ignoredOp1s, int[] ignoredOp2s, boolean enabled, String date) { _version = version;//from w w w.jav a2 s . com _op2TableSize = op2TableSize; _ignoredOp1s = ArrayUtils.nullToEmpty(ignoredOp1s); _ignoredOp2s = ArrayUtils.nullToEmpty(ignoredOp2s); _enabled = enabled; try { _timestamp = new SimpleDateFormat("yyyy-MM-dd").parse(date).getTime(); } catch (ParseException e) { throw new RuntimeException(e); } }
From source file:edu.tsinghua.hotmobi.UploadLogsTask.java
private boolean uploadLogs() { final String uuid = HotMobiLogger.getInstallationSerialId(context); final File logsDir = HotMobiLogger.getLogsDir(context); boolean hasErrors = false; final String todayDir = HotMobiLogger.DATE_FORMAT.format(new Date()); final FilenameFilter filter = new FilenameFilter() { @Override/* ww w.jav a 2 s . co m*/ public boolean accept(File dir, String filename) { return !filename.equalsIgnoreCase(todayDir); } }; for (Object dayLogsDirObj : ArrayUtils.nullToEmpty(logsDir.listFiles(filter))) { final File dayLogsDir = (File) dayLogsDirObj; boolean succeeded = true; for (Object logFileObj : ArrayUtils.nullToEmpty(dayLogsDir.listFiles())) { File logFile = (File) logFileObj; FileTypedData body = null; RestHttpResponse response = null; try { final RestHttpRequest.Builder builder = new RestHttpRequest.Builder(); builder.method(POST.METHOD); builder.url("http://www.dnext.xyz/usage/upload"); final List<Pair<String, String>> headers = new ArrayList<>(); headers.add(Pair.create("X-HotMobi-UUID", uuid)); headers.add(Pair.create("X-HotMobi-Date", dayLogsDir.getName())); headers.add(Pair.create("X-HotMobi-FileName", logFile.getName())); builder.headers(headers); body = new FileTypedData(logFile); builder.body(body); response = client.execute(builder.build()); if (response.isSuccessful()) { succeeded &= logFile.delete(); } response.close(); } catch (IOException e) { Log.w(HotMobiLogger.LOGTAG, e); succeeded = false; hasErrors = true; } finally { Utils.closeSilently(body); Utils.closeSilently(response); } } if (succeeded) { AbsLogger.logIfFalse(dayLogsDir.delete(), "Unable to delete log dir"); } } return hasErrors; }
From source file:me.j360.dubbo.modules.util.reflect.ReflectionUtil.java
/** * , private/protected./*w ww .j av a 2 s . c o m*/ * * ??? */ public static <T> T invokeMethod(Object obj, String methodName, Object... args) { Object[] theArgs = ArrayUtils.nullToEmpty(args); final Class<?>[] parameterTypes = ClassUtils.toClass(theArgs); return (T) invokeMethod(obj, methodName, theArgs, parameterTypes); }
From source file:edu.umich.oasis.sandbox.SandboxService.java
@Override public IBinder onBind(Intent i) { if (localLOGD) { Log.d(TAG, "Bound"); }/* w ww . j a v a 2s . c o m*/ Bundle extras = i.getExtras(); if (extras == null) { throw new IllegalArgumentException("No extras"); } IBinder api = extras.getBinder(EXTRA_TRUSTED_API); if (api == null) { throw new IllegalArgumentException("Trusted API not found in extras"); } IBinder root = extras.getBinder(EXTRA_ROOT_SERVICE); if (root == null) { throw new IllegalArgumentException("OASISService not found in extras"); } mTrustedAPI = ITrustedAPI.Stub.asInterface(api); mRootService = IOASISService.Stub.asInterface(root); mID = extras.getInt(EXTRA_SANDBOX_ID, -1); if (localLOGV) { ClassLoader cl = getClassLoader(); Log.v(TAG, "ClassLoader chain:"); while (cl != null) { Log.v(TAG, cl.toString()); cl = cl.getParent(); } Log.v(TAG, "<end of chain>"); } final String[] packagesToLoad = extras.getStringArray(EXTRA_KNOWN_PACKAGES); getBackgroundHandler().post(new Runnable() { @Override public void run() { if (localLOGD) { Log.d(TAG, "Preloading resolve code"); } // Run through a fake transaction, to preload the appropriate classes. SodaDescriptor preloadDesc = SodaDescriptor.forStatic(SandboxService.this, SandboxService.class, "resolveStub"); Binder testBinder = new Binder() { @Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { return mBinder.onTransact(code, data, reply, flags); } }; testBinder.attachInterface(null, ""); ISandboxService proxy = ISandboxService.Stub.asInterface(testBinder); try { proxy.resolveSoda(preloadDesc, false, null); } catch (Exception e) { Log.w(TAG, "Couldn't preload resolve", e); } if (localLOGD) { Log.d(TAG, "Preloading packages"); } // Load up packages the trusted service tells us we might need. for (String packageName : ArrayUtils.nullToEmpty(packagesToLoad)) { try { if (localLOGD) { Log.d(TAG, "Preloading " + packageName); } getContextForPackage(packageName); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Can't preload package", e); } } Log.i(TAG, "Sandbox #" + mID + ": preload complete"); } }); return mBinder; }
From source file:edu.umich.flowfence.sandbox.SandboxService.java
@Override public IBinder onBind(Intent i) { if (localLOGD) { Log.d(TAG, "Bound"); }//from ww w .ja v a 2 s .c om Bundle extras = i.getExtras(); if (extras == null) { throw new IllegalArgumentException("No extras"); } IBinder api = extras.getBinder(EXTRA_TRUSTED_API); if (api == null) { throw new IllegalArgumentException("Trusted API not found in extras"); } IBinder root = extras.getBinder(EXTRA_ROOT_SERVICE); if (root == null) { throw new IllegalArgumentException("FlowfenceService not found in extras"); } mTrustedAPI = ITrustedAPI.Stub.asInterface(api); mRootService = IFlowfenceService.Stub.asInterface(root); mID = extras.getInt(EXTRA_SANDBOX_ID, -1); if (localLOGV) { ClassLoader cl = getClassLoader(); Log.v(TAG, "ClassLoader chain:"); while (cl != null) { Log.v(TAG, cl.toString()); cl = cl.getParent(); } Log.v(TAG, "<end of chain>"); } final String[] packagesToLoad = extras.getStringArray(EXTRA_KNOWN_PACKAGES); getBackgroundHandler().post(new Runnable() { @Override public void run() { if (localLOGD) { Log.d(TAG, "Preloading resolve code"); } // Run through a fake transaction, to preload the appropriate classes. QMDescriptor preloadDesc = QMDescriptor.forStatic(SandboxService.this, SandboxService.class, "resolveStub"); Binder testBinder = new Binder() { @Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { return mBinder.onTransact(code, data, reply, flags); } }; testBinder.attachInterface(null, ""); ISandboxService proxy = ISandboxService.Stub.asInterface(testBinder); try { proxy.resolveQM(preloadDesc, false, null); } catch (Exception e) { Log.w(TAG, "Couldn't preload resolve", e); } if (localLOGD) { Log.d(TAG, "Preloading packages"); } // Load up packages the trusted service tells us we might need. for (String packageName : ArrayUtils.nullToEmpty(packagesToLoad)) { try { if (localLOGD) { Log.d(TAG, "Preloading " + packageName); } getContextForPackage(packageName); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Can't preload package", e); } } Log.i(TAG, "Sandbox #" + mID + ": preload complete"); } }); return mBinder; }
From source file:edu.umich.flowfence.common.QMDescriptor.java
public static QMDescriptor parse(String descriptorString) { Matcher matcher = NAME_PATTERN.matcher(Objects.requireNonNull(descriptorString, "descriptorString")); Validate.isTrue(matcher.matches(), "Can't parse QMDescriptor '%s'", descriptorString); ComponentName component = ComponentName.unflattenFromString(matcher.group(1)); String indicator = matcher.group(2); int kind = (indicator == null) ? KIND_CTOR : indicator.equals("#") ? KIND_INSTANCE : KIND_STATIC; String methodName = matcher.group(3); String[] typeNameArray = StringUtils.splitByWholeSeparator(matcher.group(4), ", "); List<String> typeNames = Arrays.asList(ArrayUtils.nullToEmpty(typeNameArray)); return new QMDescriptor(kind, component, methodName, typeNames, false); }
From source file:edu.umich.oasis.common.SodaDescriptor.java
public static SodaDescriptor parse(String descriptorString) { Matcher matcher = NAME_PATTERN.matcher(Objects.requireNonNull(descriptorString, "descriptorString")); Validate.isTrue(matcher.matches(), "Can't parse SodaDescriptor '%s'", descriptorString); ComponentName component = ComponentName.unflattenFromString(matcher.group(1)); String indicator = matcher.group(2); int kind = (indicator == null) ? KIND_CTOR : indicator.equals("#") ? KIND_INSTANCE : KIND_STATIC; String methodName = matcher.group(3); String[] typeNameArray = StringUtils.splitByWholeSeparator(matcher.group(4), ", "); List<String> typeNames = Arrays.asList(ArrayUtils.nullToEmpty(typeNameArray)); return new SodaDescriptor(kind, component, methodName, typeNames, false); }