Example usage for java.util List hashCode

List of usage examples for java.util List hashCode

Introduction

In this page you can find the example usage for java.util List hashCode.

Prototype

int hashCode();

Source Link

Document

Returns the hash code value for this list.

Usage

From source file:Main.java

public static void main(String[] a) {
    List list = Arrays.asList(new String[] { "A", "B", "C", "D" });
    System.out.println(list.size());
    System.out.println(list.hashCode());
}

From source file:amie.keys.CSAKey.java

public static void main(String[] args) throws IOException, InterruptedException {
    final Triple<MiningAssistant, Float, String> parsedArgs = parseArguments(args);
    final Set<Rule> output = new LinkedHashSet<>();

    // Helper object that contains the implementation for the calculation
    // of confidence and support
    // The file with the non-keys, one per line
    long timea = System.currentTimeMillis();
    List<List<String>> inputNonKeys = Utilities.parseNonKeysFile(parsedArgs.third);
    System.out.println(inputNonKeys.size() + " input non-keys");
    final List<List<String>> nonKeys = pruneBySupport(inputNonKeys, parsedArgs.second,
            parsedArgs.first.getKb());/* www.  j ava  2  s .  c  o  m*/
    Collections.sort(nonKeys, new Comparator<List<String>>() {

        @Override
        public int compare(List<String> o1, List<String> o2) {
            int r = Integer.compare(o2.size(), o1.size());
            if (r == 0) {
                return Integer.compare(o2.hashCode(), o1.hashCode());
            }

            return r;
        }

    });
    System.out.println(nonKeys.size() + " non-keys after pruning");
    int totalLoad = computeLoad(nonKeys);
    System.out.println(totalLoad + " is the total load");
    int nThreads = Runtime.getRuntime().availableProcessors();
    //int batchSize = Math.max(Math.min(maxBatchSize, totalLoad / nThreads), minBatchSize);
    int batchSize = Math.max(Math.min(maxLoad, totalLoad / nThreads), minLoad);

    final Queue<int[]> chunks = new PriorityQueue(50, new Comparator<int[]>() {
        @Override
        public int compare(int[] o1, int[] o2) {
            return Integer.compare(o2[2], o1[2]);
        }

    });

    final HashSet<HashSet<Integer>> nonKeysInt = new HashSet<>();
    final HashMap<String, Integer> property2Id = new HashMap<>();
    final HashMap<Integer, String> id2Property = new HashMap<>();
    final List<Integer> propertiesList = new ArrayList<>();
    int support = (int) parsedArgs.second.floatValue();
    KB kb = parsedArgs.first.getKb();
    buildDictionaries(nonKeys, nonKeysInt, property2Id, id2Property, propertiesList, support, kb);
    final List<HashSet<Integer>> nonKeysIntList = new ArrayList<>(nonKeysInt);
    int start = 0;
    int[] nextIdx = nextIndex(nonKeysIntList, 0, batchSize);
    int end = nextIdx[0];
    int load = nextIdx[1];
    while (start < nonKeysIntList.size()) {
        int[] chunk = new int[] { start, end, load };
        chunks.add(chunk);
        start = end;
        nextIdx = nextIndex(nonKeysIntList, end, batchSize);
        end = nextIdx[0];
        load = nextIdx[1];
    }

    Thread[] threads = new Thread[Math.min(Runtime.getRuntime().availableProcessors(), chunks.size())];
    for (int i = 0; i < threads.length; ++i) {
        threads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                while (true) {
                    int[] chunk = null;
                    synchronized (chunks) {
                        if (!chunks.isEmpty()) {
                            chunk = chunks.poll();
                        } else {
                            break;
                        }
                    }
                    System.out.println("Processing chunk " + Arrays.toString(chunk));
                    mine(parsedArgs, nonKeysIntList, property2Id, id2Property, propertiesList, chunk[0],
                            chunk[1], output);
                }

            }
        });
        threads[i].start();
    }

    for (int i = 0; i < threads.length; ++i) {
        threads[i].join();
    }
    long timeb = System.currentTimeMillis();
    System.out.println("==== Unique C-keys =====");
    for (Rule r : output) {
        System.out.println(Utilities.formatKey(r));
    }
    System.out.println(
            "VICKEY found " + output.size() + " unique conditional keys in " + (timeb - timea) + " ms");
}

From source file:com.cinchapi.concourse.shell.SyntaxTools.java

/**
 * Check {@code line} to see if it is a function call that is missing any
 * commas among arguments./*www .j av a 2s  . c  o  m*/
 * 
 * @param line
 * @param methods
 * @return the line with appropriate argument commas
 */
public static String handleMissingArgCommas(String line, List<String> methods) {
    int hashCode = methods.hashCode();
    Set<String> hashedMethods = CACHED_METHODS.get(hashCode);
    if (hashedMethods == null) {
        hashedMethods = Sets.newHashSetWithExpectedSize(methods.size());
        hashedMethods.addAll(methods);
        CACHED_METHODS.put(hashCode, hashedMethods);
    }
    char[] chars = line.toCharArray();
    StringBuilder transformed = new StringBuilder();
    StringBuilder gather = new StringBuilder();
    boolean foundMethod = false;
    boolean inSingleQuotes = false;
    boolean inDoubleQuotes = false;
    int parenCount = 0;
    for (char c : chars) {
        if (Character.isWhitespace(c) && !foundMethod) {
            transformed.append(gather);
            transformed.append(c);
            foundMethod = hashedMethods.contains(gather.toString());
            gather.setLength(0);
        } else if (Character.isWhitespace(c) && foundMethod) {
            if (transformed.charAt(transformed.length() - 1) != ',' && !inSingleQuotes && !inDoubleQuotes
                    && c != '\n') {
                transformed.append(",");
            }
            transformed.append(c);
        } else if (c == '(' && !foundMethod) {
            parenCount++;
            transformed.append(gather);
            transformed.append(c);
            foundMethod = hashedMethods.contains(gather.toString());
            gather.setLength(0);
        } else if (c == '(' && foundMethod) {
            parenCount++;
            transformed.append(c);
        } else if (c == ';') {
            transformed.append(c);
            foundMethod = false;
            parenCount = 0;
        } else if (c == ')') {
            parenCount--;
            transformed.append(c);
            foundMethod = parenCount == 0 ? false : foundMethod;
        } else if (c == '"') {
            transformed.append(c);
            inSingleQuotes = !inSingleQuotes;
        } else if (c == '\'') {
            transformed.append(c);
            inDoubleQuotes = !inDoubleQuotes;
        } else if (foundMethod) {
            transformed.append(c);
        } else {
            gather.append(c);
        }
    }
    transformed.append(gather);
    return transformed.toString();
}

From source file:org.dawnsci.spectrum.ui.utils.SpectrumUtils.java

public static ISpectrumFile averageSpectrumFiles(List<IContain1DData> files, IPlottingSystem<?> system) {
    files = getCompatibleDatasets(files);

    if (files == null)
        return null;

    IDataset x0 = files.get(0).getxDataset();

    StringBuilder sb = new StringBuilder();
    sb.append("Average of: ");
    sb.append("\n");
    MultivariateSummaryStatistics ms = new MultivariateSummaryStatistics(x0.getSize(), false);
    for (IContain1DData file : files) {

        sb.append(file.getName() + ":");

        for (IDataset ds : file.getyDatasets()) {

            sb.append(ds.getName() + ":");

            DoubleDataset dd;//from  www .j  a  va  2s . co  m
            if (ds instanceof DoubleDataset)
                dd = (DoubleDataset) ds;
            else {
                dd = (DoubleDataset) DatasetUtils.cast(ds, Dataset.FLOAT64);
            }
            double[] raw = dd.getData();
            ms.addValue(raw);
        }

        sb.deleteCharAt(sb.length() - 1);
        sb.deleteCharAt(sb.length() - 1);
        sb.append("\n");
    }
    List<IDataset> sets = new ArrayList<IDataset>();
    Dataset dd = DatasetFactory.createFromObject(ms.getMean());

    dd.setName("Average");
    sets.add(dd);

    String shortName = "Average: " + files.get(0).getName() + " to " + files.get(files.size() - 1).getName();

    return new SpectrumInMemory(sb.toString() + "[" + sets.hashCode() + "]", shortName, x0, sets, system);
}

From source file:net.sf.jasperreports.engine.export.JsonExporter.java

public static void writeBookmarks(List<PrintBookmark> bookmarks, Writer writer, JacksonUtil jacksonUtil)
        throws IOException {
    // exclude the methods marked with @JsonIgnore in PrintBookmarkMixin from PrintBookmark implementation
    jacksonUtil.getObjectMapper().addMixInAnnotations(PrintBookmark.class, PrintBookmarkMixin.class);

    writer.write("{");

    writer.write("\"id\": \"bkmrk_" + (bookmarks.hashCode() & 0x7FFFFFFF) + "\",");
    writer.write("\"type\": \"bookmarks\",");
    writer.write("\"bookmarks\": " + jacksonUtil.getJsonString(bookmarks));

    writer.write("}");
}

From source file:org.devproof.portal.core.module.common.component.ExtendedLabel.java

private ImgResourceReference getImageResourceAndCache(List<String> str2ImgLines, Font font) {
    String uuid = String.valueOf(str2ImgLines.hashCode());
    String2ImageResource resource = new String2ImageResource(str2ImgLines, font);
    ImgResourceReference imgResource = images.get(uuid);
    if (imgResource == null) {
        imgResource = new ImgResourceReference(uuid, resource);
        // ConcurrentHashMap
        images.put(uuid, imgResource);/*from   w ww . j a  va2s  .  c  om*/
    }
    return imgResource;
}

From source file:pl.edu.icm.comac.vis.server.service.DbGraphIdService.java

/**
 * Just find a proper id and info if the graph exists.
 *
 * @return array, first element is valid id, second element not null means
 * that this graph already exists.//from  www .  ja  v  a2s . c  om
 */
protected String[] findId(List<String> nodes) {
    String[] res = new String[2];
    List<String> arrayList = new ArrayList<>(new HashSet(nodes));
    Collections.sort(arrayList);
    int hash = arrayList.hashCode();
    boolean ok = false;

    do {
        String id = formatHashCodeAsId(hash);
        res[0] = id;
        try {
            List<String> existing = getNodes(id);
            List<String> exS = new ArrayList<>(existing);
            Collections.sort(exS);
            if (exS.equals(arrayList)) {
                ok = true;
                res[1] = "ok";

            }
        } catch (UnknownGraphException ue) {
            res[1] = null;
            ok = true;
        }

        hash++;

    } while (!ok);

    return res;
}

From source file:com.veniosg.dir.android.util.Notifier.java

public static void showNotEnoughSpaceNotification(long spaceNeeded, List<FileHolder> files, String toPath,
        Context context) {/*w  w  w .ja  v a 2  s . c  o  m*/
    Notification not = new NotificationCompat.Builder(context, CHANNEL_FILEOPS).setAutoCancel(true)
            .setContentTitle(context.getString(R.string.notif_no_space))
            .setContentText(
                    context.getString(R.string.notif_space_more, FileUtils.formatSize(context, spaceNeeded)))
            .setContentInfo(toPath).setOngoing(false).setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setSmallIcon(android.R.drawable.stat_sys_warning)
            .setTicker(context.getString(R.string.notif_no_space))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(
                    context.getString(R.string.notif_space_more, FileUtils.formatSize(context, spaceNeeded))))
            .setOnlyAlertOnce(true).build();

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(files.hashCode(), not);
}

From source file:pl.edu.icm.comac.vis.server.service.DbGraphIdServiceTest.java

/**
 * Test of findId method, of class DbGraphIdService.
 *//* w  w  w .  jav  a 2s .co m*/
@Test
public void testFindId() {
    System.out.println("findId");
    List<String> nodes = Arrays.asList(new String[] { "xnode2", "xnode1" });
    List<String> sorted = new ArrayList<>(nodes);
    Collections.sort(sorted);
    String expectedId = DbGraphIdService.formatHashCodeAsId(sorted.hashCode());
    String[] findId = service.findId(nodes);
    assertEquals(2, findId.length);
    assertEquals(expectedId, findId[0]);
    assertNull(findId[1]);
    service.getGraphId(nodes);
    findId = service.findId(nodes);
    assertEquals(2, findId.length);
    assertEquals(expectedId, findId[0]);
    assertNotNull(findId[1]);

}

From source file:pl.edu.icm.comac.vis.server.service.DbGraphIdServiceTest.java

/**
 * Test of getGraphId method, of class DbGraphIdService.
 *//*from   www. ja v  a 2s  . c om*/
@org.junit.Test
public void testGetGraphId() {
    System.out.println("getGraphId");
    List<String> nodes = Arrays.asList(new String[] { "a", "b" });
    String id = service.getGraphId(nodes);
    assertNotNull(id);
    assertEquals(String.format("%08x", nodes.hashCode()), id);
    //        assertEquals(1, JdbcTestUtils.countRowsInTable(jdbcTemplate, "graph"));
    assertEquals(2, JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "graph_entry", "graph_id='" + id + "'"));
}