Example usage for com.google.common.collect Iterables toArray

List of usage examples for com.google.common.collect Iterables toArray

Introduction

In this page you can find the example usage for com.google.common.collect Iterables toArray.

Prototype

static <T> T[] toArray(Iterable<? extends T> iterable, T[] array) 

Source Link

Usage

From source file:ec.tss.sa.output.SpreadsheetOutput.java

@Override
public void end(Object context) throws Exception {
    String file = new File(folder_, config_.getFileName()).getAbsolutePath();
    file = Paths.changeExtension(file, "xlsx");
    File ssfile = new File(file);
    //File ssfile = new File("C:\\test.xls");
    SXSSFWorkbook workbook = new SXSSFWorkbook(null, 100, false, true);

    try (FileOutputStream stream = new FileOutputStream(ssfile)) {
        switch (config_.getLayout()) {
        case ByComponent: {
            HashMap<String, List<NamedObject<TsData>>> allData = new HashMap<>();
            for (DefaultSummary summary : summaries_) {
                for (Entry<String, TsData> keyValue : summary.getAllSeries().entrySet()) {
                    List<NamedObject<TsData>> list = null;
                    if (!allData.containsKey(keyValue.getKey())) {
                        list = new ArrayList<>();
                        allData.put(keyValue.getKey(), list);
                    } else {
                        list = allData.get(keyValue.getKey());
                    }/*from w w w.ja  va  2s . c  o  m*/
                    String name;

                    if (fullName) {
                        name = MultiLineNameUtil.join(summary.getName(), " * ");
                    } else {
                        name = MultiLineNameUtil.last(summary.getName());
                    }
                    list.add(new NamedObject<>(name, keyValue.getValue()));
                }
            }
            for (Entry<String, List<NamedObject<TsData>>> keyValue : allData.entrySet()) {
                TsDataTable byComponentTable = new TsDataTable();
                List<NamedObject<TsData>> value = keyValue.getValue();
                String[] headers = new String[value.size()];
                for (int i = 0; i < headers.length; i++) {
                    NamedObject<TsData> data = value.get(i);
                    headers[i] = data.name;
                    byComponentTable.insert(-1, data.object);
                }
                //ADD SHEET
                XSSFHelper.addSheet(workbook, keyValue.getKey(), new String[] { keyValue.getKey() }, headers,
                        byComponentTable, config_.isVerticalOrientation());
            }
            break;
        }
        case BySeries: {
            for (int i = 0; i < summaries_.size(); i++) {
                DefaultSummary summary = summaries_.get(i);
                Set<Entry<String, TsData>> tmp = summary.getAllSeries().entrySet();
                TsDataTable bySeriesTable = new TsDataTable();
                String[] componentHeaders = new String[tmp.size()];
                int j = 0;
                for (Entry<String, TsData> keyValue : tmp) {
                    componentHeaders[j++] = keyValue.getKey();
                    bySeriesTable.insert(-1, keyValue.getValue());
                }
                //ADD SHEET
                String name;
                if (fullName) {
                    name = MultiLineNameUtil.join(summary.getName(), " * ");
                } else {
                    name = MultiLineNameUtil.last(summary.getName());
                }
                XSSFHelper.addSheet(workbook, "Series" + Integer.toString(i), new String[] { name },
                        componentHeaders, bySeriesTable, config_.isVerticalOrientation());
            }
            break;
        }
        case OneSheet: {
            List<String> headers0 = new ArrayList<>();
            List<String> headers1 = new ArrayList<>();
            TsDataTable oneSheetTable = new TsDataTable();

            for (DefaultSummary summary : summaries_) {
                String name;
                if (fullName) {
                    name = MultiLineNameUtil.join(summary.getName(), " * ");
                } else {
                    name = MultiLineNameUtil.last(summary.getName());
                }
                headers0.add(name);
                Map<String, TsData> data = summary.getAllSeries();
                for (Entry<String, TsData> keyValue : data.entrySet()) {
                    headers1.add(keyValue.getKey());
                    oneSheetTable.insert(-1, keyValue.getValue());
                }
                for (int i = 1; i < data.size(); i++) {
                    headers0.add("");
                }
            }
            //ADD SHEET
            XSSFHelper.addSheet(workbook, "Series", Iterables.toArray(headers0, String.class),
                    Iterables.toArray(headers1, String.class), oneSheetTable, config_.isVerticalOrientation());
            break;
        }
        }
        workbook.write(stream);
    } finally {
        workbook.dispose();
    }
}

From source file:com.linkedin.bowser.core.eval.EvalHandler.java

/**
 * @param left/* w  w w . ja v  a2 s .  c  o  m*/
 * @param right
 * @return
 */
public static NQLObject plus(NQLObject left, NQLObject right) {
    if ((left instanceof Numeric) && (right instanceof Numeric)) {
        Numeric l = (Numeric) left;
        Numeric r = (Numeric) right;

        if (left.getType() == Type.FLOAT || right.getType() == Type.FLOAT)
            return Objects.create(l.getAsFloat() + r.getAsFloat());
        else if (left.getType() == Type.LONG || right.getType() == Type.LONG)
            return Objects.create(l.getAsLong() + r.getAsLong());
        else
            return Objects.create(l.getAsInt() + r.getAsInt());
    }

    if ((left instanceof Sequence) && (right instanceof Sequence)) {
        Sequence l = (Sequence) left;
        Sequence r = (Sequence) right;

        if (left.getType() != right.getType())
            throw new TypeError(left, "can only concatenate sequences of the same type");

        if (left.getType() == Type.LIST)
            switch (left.getType()) {
            case LIST:
                return new ListObject(Lists.newArrayList(Iterables.concat(l, r)));
            case STRING:
                return new StringObject(l.toString() + r.toString());
            case TUPLE:
                NQLObject[] result = Iterables.toArray(Iterables.concat(l, r), NQLObject.class);
                return new TupleObject(result);
            }
    }

    throw new TypeError("can only add/concatenate types that are either numeric or sequence");
}

From source file:org.cfr.capsicum.server.ServerRuntimeFactoryBean.java

/**
 * Builds Cayenne configuration object based on configured properties.
 *//*from   w  w w .ja  v  a2 s .  c  o  m*/
@Override
public void afterPropertiesSet() throws Exception {
    // check datasource and transaction
    if (transactionManager == null && dataSource == null) {
        throw new IllegalArgumentException("Property 'transactionManager' or 'dataSource' is required");
    }

    // create default resource loader if no attached spring context.
    if (applicationContext == null) {
        this.resourceLoader = new DefaultResourceLoader();
    } else {
        this.resourceLoader = applicationContext;
    }
    SpringServerModule springModule = new SpringServerModule();
    List<String> configurationLocations = ImmutableList.of();
    if (dataDomainDefinitions != null && !dataDomainDefinitions.isEmpty()) {
        configurationLocations = Lists.newArrayListWithCapacity(dataDomainDefinitions.size());
        for (DataDomainDefinition dataDomainDefinition : dataDomainDefinitions) {
            Assert.notNull(dataDomainDefinition.getName(), "the name of DataDomain is required");
            Resource resource = Assert.notNull(dataDomainDefinition.getDomainResource(),
                    "the resource of DataDomain is required");
            URL url = null;
            try {
                url = resource.getURL();
            } catch (IOException ex) {
                throw new CayenneException(ex.getMessage(), ex);
            }
            configurationLocations.add(url.toString());
            // set default update strategy
            if (dataDomainDefinition.getSchemaUpdateStrategy() == null) {
                dataDomainDefinition.setSchemaUpdateStrategy(getDefaultSchemaUpdateStrategy());
            }
        }
    }
    // create specific datasource Factory
    if (dataSourceFactory == null) {
        dataSourceFactory = new SpringDataSourceFactory(this);
    }
    // create cayenne runtime instance with domain definitions
    cayenneRuntime = new ServerRuntime(Iterables.toArray(configurationLocations, String.class), springModule);

    // create default transaction manager
    if (transactionManager == null) {
        transactionManager = new CayenneTransactionManager(dataSource, cayenneRuntime);
    } else {
        this.transactionManager.setCayenneRuntime(cayenneRuntime);
    }

}

From source file:com.android.tools.idea.npw.deprecated.ChooseModuleTypeStep.java

@Override
public void init() {
    super.init();
    ImmutableList.Builder<ModuleTemplate> deviceTemplates = ImmutableList.builder();
    ImmutableList.Builder<ModuleTemplate> extrasTemplates = ImmutableList.builder();
    Set<FormFactor> formFactorSet = Sets.newHashSet();
    // Android device templates are shown first, with less important templates following
    for (ModuleTemplateProvider provider : myModuleTypesProviders) {
        for (ModuleTemplate moduleTemplate : provider.getModuleTemplates()) {
            FormFactor formFactor = moduleTemplate.getFormFactor();
            if (formFactor != null) {
                if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
                    // Hidden if not installed
                    continue;
                }/*from  w  ww .  j av a2 s  .  c  o m*/
                if (formFactor != FormFactor.CAR) {
                    // Auto is not a standalone module (but rather a modification to a mobile module):
                    deviceTemplates.add(moduleTemplate);
                    formFactorSet.add(formFactor);
                }
            } else {
                extrasTemplates.add(moduleTemplate);
            }
        }
    }

    for (final FormFactor formFactor : formFactorSet) {
        registerValueDeriver(FormFactorUtils.getInclusionKey(formFactor), new ValueDeriver<Boolean>() {
            @Nullable
            @Override
            public Boolean deriveValue(@NotNull ScopedStateStore state,
                    @Nullable ScopedStateStore.Key changedKey, @Nullable Boolean currentValue) {
                ModuleTemplate moduleTemplate = myState.get(SELECTED_MODULE_TYPE_KEY);
                return moduleTemplate != null && Objects.equal(formFactor, moduleTemplate.getFormFactor());
            }
        });
    }

    List<ModuleTemplate> galleryTemplatesList = deviceTemplates.build();
    List<ModuleTemplate> extrasTemplatesList = extrasTemplates.build();

    Iterable<ModuleTemplate> allTemplates = Iterables.concat(galleryTemplatesList, extrasTemplatesList);
    myFormFactorGallery
            .setModel(JBList.createDefaultListModel(Iterables.toArray(allTemplates, ModuleTemplate.class)));
    ModuleTypeBinding binding = new ModuleTypeBinding();
    register(SELECTED_MODULE_TYPE_KEY, myPanel, binding);

    myFormFactorGallery.addListSelectionListener(new ModuleTypeSelectionListener());

    if (!galleryTemplatesList.isEmpty()) {
        myState.put(SELECTED_MODULE_TYPE_KEY, galleryTemplatesList.get(0));
    }
}

From source file:org.apache.parquet.cli.Util.java

public static ColumnDescriptor descriptor(String column, MessageType schema) {
    String[] path = Iterables.toArray(DOT.split(column), String.class);
    Preconditions.checkArgument(schema.containsPath(path), "Schema doesn't have column: " + column);
    return schema.getColumnDescription(path);
}

From source file:com.addthis.hydra.data.filter.value.ValueFilterSplit.java

protected String[] splitFixedLength(String line, int length) {
    Iterable<String> splitIter = Splitter.fixedLength(length).split(line);
    List<String> tok = new ArrayList<>();
    Iterables.addAll(tok, splitIter);/*from   w  ww . j  av a  2 s. c  o m*/
    return Iterables.toArray(tok, String.class);
}

From source file:dagger.internal.codegen.writer.JavaWriter.java

public void file(Filer filer, CharSequence name, Iterable<? extends Element> originatingElements)
        throws IOException {
    final JavaFileObject sourceFile = filer.createSourceFile(name,
            Iterables.toArray(originatingElements, Element.class));
    try {/* www.  j  ava  2 s  .  c  o m*/
        new Formatter().formatSource(CharSource.wrap(write(new StringBuilder())), new CharSink() {
            @Override
            public Writer openStream() throws IOException {
                return sourceFile.openWriter();
            }
        });
    } catch (FormatterException e) {
        throw new IllegalStateException("The writer produced code that could not be parsed by the formatter",
                e);
    }
}

From source file:edu.umn.msi.tropix.persistence.service.impl.FolderServiceImpl.java

public Folder[] getAllGroupFolders(final String gridId) {
    return Iterables.toArray(getTropixObjectDao().getAllGroupFolders(), Folder.class);
}

From source file:org.blip.workflowengine.transferobject.ModifiablePropertyNode.java

@Override
public PropertyNode add(final String key, final byte[] value, final Collection<Attribute> attributes) {
    return internalAdd(true, key, value, Iterables.toArray(attributes, Attribute.class));
}

From source file:gov.nih.nci.firebird.selenium2.pages.user.MyAccountPageHelper.java

public void checkSponsorRepresentativeInformationDisplayed(FirebirdUser user) {
    page.getPersonTag().getHelper().verifyPersonInformationIsDisplayed(user.getPerson());
    Organization[] sponsors = Iterables.toArray(user.getSponsorRepresentativeOrganizations(),
            Organization.class);
    page.getSponsorSection().getHelper().verifySponsorRepresentativesAreDisplayed(sponsors);
    checkSelectedRolesDisplayed(UserRoleType.SPONSOR);
}