List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:uk.bl.wa.extract.LinkExtractor.java
/** * Attempt to parse out the private domain. Fall back on host if things go * awry./*from www . j a v a2 s. c o m*/ * * @param host * @return */ public static String extractPrivateSuffixFromHost(String host) { if (host == null) return null; // Parse out the public suffix: InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch (Exception e) { return host; } InternetDomainName suffix = null; // It appears the IDN class does not know about the various UK // second-level domains. // If it's a UK host, override the result by assuming three levels: if (host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if (parts.size() >= 3) { suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { if (domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix()) { suffix = domainName.topPrivateDomain(); } else { suffix = domainName; } } // If it all failed for some reason, fall back on the host value: if (suffix == null) suffix = domainName; return suffix.toString(); }
From source file:eu.eubrazilcc.lvl.core.conf.ConfigurationFinder.java
private static String filesToString(final ImmutableList<File> files) { String str = ""; if (files != null && files.size() > 0) { int i = 0; for (; i < (files.size() - 1); i++) { try { str += files.get(i).getCanonicalPath() + ", "; } catch (Exception ignore) { }/* w ww .j ava 2 s . com*/ } try { str += files.get(i).getCanonicalPath(); } catch (Exception ignore) { } } return str; }
From source file:com.spectralogic.ds3autogen.test.helpers.RemoveDollarSignConverterHelper.java
/** * Checks if a list of Ds3Params generated by the createPopulatedParams function * has successfully changed all type names to remove the '$' symbol. Assumes * that the specified variation matches the variation used during the param * list generation./* w w w . j a va 2 s .c om*/ */ public static void checkAutoPopulatedParams(final ImmutableList<Ds3Param> params, final String variation) { assertThat(params.size(), is(2)); assertThat(params.get(0).getType(), is("com.test.package.TypeOne" + variation)); assertThat(params.get(1).getType(), is("com.test.package.TypeTwo" + variation)); }
From source file:com.spectralogic.ds3autogen.test.helpers.RemoveDollarSignConverterHelper.java
/** * Checks if a list of Ds3Response codes generated by the createPopulatedResponseCodes * function has successfully changed all type names by removing the '$' symbol *///from w ww . j av a 2s. com public static void checkAutoPopulatedResponseCodes(final ImmutableList<Ds3ResponseCode> responseCodes) { assertThat(responseCodes.size(), is(2)); final ImmutableList<Ds3ResponseType> firstResponseTypes = responseCodes.get(0).getDs3ResponseTypes(); assertThat(firstResponseTypes.size(), is(2)); assertThat(firstResponseTypes.get(0).getType(), is("com.test.package.Type1")); assertThat(firstResponseTypes.get(0).getComponentType(), is("com.test.package.Type2")); assertThat(firstResponseTypes.get(1).getType(), is("com.test.package.Type3")); assertThat(firstResponseTypes.get(1).getComponentType(), is("com.test.package.Type4")); final ImmutableList<Ds3ResponseType> secondResponseTypes = responseCodes.get(1).getDs3ResponseTypes(); assertThat(secondResponseTypes.size(), is(2)); assertThat(secondResponseTypes.get(0).getType(), is("com.test.package.Type1")); assertThat(secondResponseTypes.get(0).getComponentType(), is("com.test.package.Type2")); assertThat(secondResponseTypes.get(1).getType(), is("com.test.package.Type3")); assertThat(secondResponseTypes.get(1).getComponentType(), is("com.test.package.Type4")); }
From source file:net.techcable.pineapple.collect.ImmutableMaps.java
@SuppressWarnings("unchecked") public static <K, V> void forEach(ImmutableMap<K, V> map, BiConsumer<? super K, ? super V> action) { checkNotNull(map, "Null map"); if (ENTRIES_ARRAY_FIELD != null && ENTRIES_ARRAY_FIELD.getDeclaringClass().isInstance(map)) { for (Map.Entry<K, V> entry : ENTRIES_ARRAY_FIELD.get(map)) { K key = entry.getKey();// ww w . j a v a 2 s. c o m V value = entry.getValue(); checkNotNull(action, "Null action").accept(key, value); } } else { ImmutableList<Map.Entry<K, V>> entryList = map.entrySet().asList(); // Since they don't support forEach this is the fastest way to iterate for (int i = 0; i < entryList.size(); i++) { Map.Entry<K, V> entry = entryList.get(i); action.accept(entry.getKey(), entry.getValue()); } } }
From source file:com.spectralogic.ds3autogen.utils.ResponsePayloadUtil.java
/** * Retrieves the non-error non-null response payload associated with the request. * If one does not exist, then null is returned *///from w w w. j a va2 s. c o m public static String getResponsePayload(final ImmutableList<Ds3ResponseCode> responseCodes) { if (!hasResponsePayload(responseCodes)) { return null; } final ImmutableList.Builder<String> builder = ImmutableList.builder(); for (final String payload : getAllResponseTypes(responseCodes)) { if (!payload.equalsIgnoreCase("null")) { builder.add(payload); } } final ImmutableList<String> responsePayloads = builder.build(); switch (responsePayloads.size()) { case 0: return null; case 1: return responsePayloads.get(0); default: throw new IllegalArgumentException("Request has multiple non-error response payloads"); } }
From source file:com.spectralogic.dsbrowser.gui.services.ds3Panel.DeleteService.java
/** * Delete a Single Selected Spectra S3 bucket * * @param ds3Common ds3Common object//from w ww .j ava2 s . co m * @param values list of objects to be deleted */ public static void deleteBucket(final Ds3Common ds3Common, final ImmutableList<TreeItem<Ds3TreeTableValue>> values, final Workers workers, final LoggingService loggingService, final DateTimeUtils dateTimeUtils, final ResourceBundle resourceBundle) { LOG.info("Got delete bucket event"); final LazyAlert alert = new LazyAlert(resourceBundle); final Ds3PanelPresenter ds3PanelPresenter = ds3Common.getDs3PanelPresenter(); final Session currentSession = ds3Common.getCurrentSession(); if (currentSession != null) { final ImmutableList<String> buckets = getBuckets(values); if (buckets.size() > 1) { loggingService.logMessage(resourceBundle.getString("multiBucketNotAllowed"), LogType.ERROR); LOG.info("The user selected objects from multiple buckets. This is not allowed."); alert.error("multiBucketNotAllowed"); return; } final Optional<TreeItem<Ds3TreeTableValue>> first = values.stream().findFirst(); if (first.isPresent()) { final TreeItem<Ds3TreeTableValue> value = first.get(); final String bucketName = value.getValue().getBucketName(); if (!Ds3PanelService.checkIfBucketEmpty(bucketName, currentSession)) { loggingService.logMessage(resourceBundle.getString("failedToDeleteBucket"), LogType.ERROR); alert.error("failedToDeleteBucket"); } else { final Ds3DeleteBucketTask ds3DeleteBucketTask = new Ds3DeleteBucketTask( currentSession.getClient(), bucketName); DeleteFilesPopup.show(ds3DeleteBucketTask, ds3Common); ds3Common.getDs3TreeTableView().setRoot(new TreeItem<>()); RefreshCompleteViewWorker.refreshCompleteTreeTableView(ds3Common, workers, dateTimeUtils, loggingService); ds3PanelPresenter.getDs3PathIndicator().setText(StringConstants.EMPTY_STRING); ds3PanelPresenter.getDs3PathIndicatorTooltip().setText(StringConstants.EMPTY_STRING); } } } else { LOG.error("NULL Session when attempting to deleteBucket"); } }
From source file:org.glowroot.api.internal.ThrowableInfo.java
private static ThrowableInfo from(Throwable t, @Nullable List<StackTraceElement> causedStackTrace) { int framesInCommon = 0; ImmutableList<StackTraceElement> stackTrace = ImmutableList.copyOf(t.getStackTrace()); if (causedStackTrace != null) { ListIterator<StackTraceElement> i = stackTrace.listIterator(stackTrace.size()); ListIterator<StackTraceElement> j = causedStackTrace.listIterator(causedStackTrace.size()); while (i.hasPrevious() && j.hasPrevious()) { StackTraceElement element = i.previous(); StackTraceElement causedElement = j.previous(); if (!element.equals(causedElement)) { break; }//from w ww . j ava2 s .com framesInCommon++; } if (framesInCommon > 0) { // strip off common frames stackTrace = stackTrace.subList(0, stackTrace.size() - framesInCommon); } } ImmutableThrowableInfo.Builder builder = ImmutableThrowableInfo.builder().display(t.toString()) .addAllStackTrace(stackTrace).framesInCommonWithCaused(framesInCommon); Throwable cause = t.getCause(); if (cause != null) { // pass t's original stack trace to construct the nested cause // (not stackTraces, which now has common frames removed) builder.cause(from(cause, Arrays.asList(t.getStackTrace()))); } return builder.build(); }
From source file:com.google.caliper.util.Util.java
public static <T> ImmutableBiMap<T, String> assignNames(Set<T> items) { ImmutableList<T> itemList = ImmutableList.copyOf(items); ImmutableBiMap.Builder<T, String> itemNamesBuilder = ImmutableBiMap.builder(); for (int i = 0; i < itemList.size(); i++) { itemNamesBuilder.put(itemList.get(i), generateUniqueName(i)); }//www . j a v a 2 s. co m return itemNamesBuilder.build(); }
From source file:com.mogujie.instantrun.IncrementalTool.java
public static byte[] getPatchFileContents(ImmutableList<String> patchFileContents, ImmutableList<Integer> patchIndexContents) { if (patchFileContents.size() != patchIndexContents.size()) { throw new GradleException("patchFileContents's size is " + patchFileContents.size() + ", but patchIndexContents's size is " + patchIndexContents.size() + ", please check the changed classes."); }/*from w w w.j ava 2s . c om*/ ClassWriter cw = new ClassWriter(0); MethodVisitor mv; cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, IncrementalVisitor.APP_PATCHES_LOADER_IMPL, null, IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, null); { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPatchedClasses", "()[Ljava/lang/String;", null, null); mv.visitCode(); mv.visitIntInsn(Opcodes.SIPUSH, patchFileContents.size()); mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String"); for (int index = 0; index < patchFileContents.size(); index++) { mv.visitInsn(Opcodes.DUP); mv.visitIntInsn(Opcodes.SIPUSH, index); mv.visitLdcInsn(patchFileContents.get(index)); mv.visitInsn(Opcodes.AASTORE); } mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(4, 1); mv.visitEnd(); } { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPatchedClassIndexes", "()[I", null, null); mv.visitCode(); mv.visitIntInsn(Opcodes.SIPUSH, patchIndexContents.size()); mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); for (int index = 0; index < patchIndexContents.size(); index++) { mv.visitInsn(Opcodes.DUP); mv.visitIntInsn(Opcodes.SIPUSH, index); mv.visitLdcInsn(patchIndexContents.get(index)); mv.visitInsn(Opcodes.IASTORE); } mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(4, 1); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }