简体   繁体   English

使番石榴ArrayListMultimap工作

[英]Getting Guava ArrayListMultimap to work

I'm relatively new to java, and am working on a new analysis method to improve my current implementation of ( https://stackoverflow.com/questions/26577172/inefficcient-optimally-deleting-2s-rows-and-columns-from-a-random-mod2 ). 我是Java的新手,正在研究一种新的分析方法,以改善我当前的实现( https://stackoverflow.com/questions/26577172/inefficcient-optimally-deleting-2s-rows-and-columns-from -a-random-mod2 )。

I've determined that I want a multimap to process my dataset. 我确定我想要一个多重地图来处理我的数据集。 Thus, I downloaded Guava and placed the ~2MB file into a directory. 因此,我下载了Guava并将〜2MB的文件放入目录中。 I compile my program using Multimap or ArrayListMultimap with: 我使用Multimap或ArrayListMultimap编译我的程序:

javac -classpath C:\mywork\guava-18.0.jar myfile.java

Edit: At the advice of user2336315, I changed the code to: 编辑:在user2336315的建议下,我将代码更改为:

ArrayListMultimap<String, int[]> combinations = ArrayListMultimap.create();

This compiles perfectly. 这样可以完美编译。 However, I then get another error when I run the script with 'java Optimize': 但是,当我使用“ java Optimize”运行脚本时,又遇到了另一个错误:

To see how to run the code properly after compiling, please refer to the answer comments below. 要查看编​​译后如何正确运行代码,请参阅下面的答案注释。


Here's my current test code: 这是我当前的测试代码:

import java.util.Random;
import com.google.common.collect.ArrayListMultimap;    

class Determine {
    public static int[][] rando() {
        // Various lines of code to product a random matrix
    }
}

class Search {
    public static void finalize(int[][] a) {
        int bluejay =  a.length;
        int minimum = 1;

        ArrayListMultimap<String, int[]> combinations = ArrayListMultimap.create();
        for (int x = 0; x < bluejay - minimum + 1; x++) {
            int y = 0;
            while (y < 5) {
                int[] rows = new int[x + 1];
                rows[0] = 1;
                combinations.put(Integer.toString(x), rows);
                y += 1;                 
            }
            System.out.println(combinations);
        }
    }
}

public class Optimize {
    public static void main(String[] args) {
        int[][] matrix  = Determine.rando();
        Search.finalize(matrix);
    }
}

The constructors of the class are private, you cannot see them outside the class. 该类的构造函数是私有的,您无法在类外部看到它们。 You have to use the static method that creates the map. 您必须使用创建地图的静态方法。

ArrayListMultimap<String, int[]> combinations = ArrayListMultimap.create();

As for the second error, I don't see any Guava class with this name, so maybe you mispelled it? 至于第二个错误,我看不到任何具有该名称的Guava类,所以也许您拼错了?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM