当前位置: 首页>>代码示例>>Java>>正文


Java Functional类代码示例

本文整理汇总了Java中org.ethereum.util.Functional的典型用法代码示例。如果您正苦于以下问题:Java Functional类的具体用法?Java Functional怎么用?Java Functional使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Functional类属于org.ethereum.util包,在下文中一共展示了Functional类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNodes

import org.ethereum.util.Functional; //导入依赖的package包/类
/**
 * Returns limited list of nodes matching {@code predicate} criteria<br>
 * The nodes are sorted then by their totalDifficulties
 *
 * @param predicate only those nodes which are satisfied to its condition are included in results
 * @param limit max size of returning list
 *
 * @return list of nodes matching criteria
 */
public List<NodeHandler> getNodes(
        Functional.Predicate<NodeHandler> predicate,
        int limit    ) {
    ArrayList<NodeHandler> filtered = new ArrayList<>();
    synchronized (this) {
        for (NodeHandler handler : nodeHandlerMap.values()) {
            if (predicate.test(handler)) {
                filtered.add(handler);
            }
        }
    }
    Collections.sort(filtered, new Comparator<NodeHandler>() {
        @Override
        public int compare(NodeHandler o1, NodeHandler o2) {
            return o2.getNodeStatistics().getEthTotalDifficulty().compareTo(
                    o1.getNodeStatistics().getEthTotalDifficulty());
        }
    });
    return CollectionUtils.truncate(filtered, limit);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:30,代码来源:NodeManager.java

示例2: encodeList

import org.ethereum.util.Functional; //导入依赖的package包/类
private static <T> byte[] encodeList(List<T> entries, Functional.Function<T, byte[]> encoder) {
    byte[][] result = new byte[entries.size()][];
    for (int i = 0; i < entries.size(); i++) {
        result[i] = encoder.apply(entries.get(i));
    }

    return RLP.encodeList(result);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:9,代码来源:BlockSummary.java

示例3: decodeList

import org.ethereum.util.Functional; //导入依赖的package包/类
private static <T> List<T> decodeList(RLPList list, Functional.Function<byte[], T> decoder) {
    List<T> result = new ArrayList<>();
    for (RLPElement item : list) {
        result.add(decoder.apply(item.getRLPData()));
    }
    return result;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:8,代码来源:BlockSummary.java

示例4: encodeMap

import org.ethereum.util.Functional; //导入依赖的package包/类
private static <K, V> byte[] encodeMap(Map<K, V> map, Functional.Function<K, byte[]> keyEncoder, Functional.Function<V, byte[]> valueEncoder) {
    byte[][] result = new byte[map.size()][];
    int i = 0;
    for (Map.Entry<K, V> entry : map.entrySet()) {
        byte[] key = keyEncoder.apply(entry.getKey());
        byte[] value = valueEncoder.apply(entry.getValue());
        result[i++] = RLP.encodeList(key, value);
    }
    return RLP.encodeList(result);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:11,代码来源:BlockSummary.java

示例5: decodeMap

import org.ethereum.util.Functional; //导入依赖的package包/类
private static <K, V> Map<K, V> decodeMap(RLPList list, Functional.Function<byte[], K> keyDecoder, Functional.Function<byte[], V> valueDecoder) {
    Map<K, V> result = new HashMap<>();
    for (RLPElement entry : list) {
        K key = keyDecoder.apply(((RLPList) entry).get(0).getRLPData());
        V value = valueDecoder.apply(((RLPList) entry).get(1).getRLPData());
        result.put(key, value);
    }
    return result;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:10,代码来源:BlockSummary.java

示例6: encodeSummaries

import org.ethereum.util.Functional; //导入依赖的package包/类
private static byte[] encodeSummaries(final List<TransactionExecutionSummary> summaries) {
    return encodeList(summaries, new Functional.Function<TransactionExecutionSummary, byte[]>() {
        @Override
        public byte[] apply(TransactionExecutionSummary summary) {
            return summary.getEncoded();
        }
    });
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:9,代码来源:BlockSummary.java

示例7: decodeSummaries

import org.ethereum.util.Functional; //导入依赖的package包/类
private static List<TransactionExecutionSummary> decodeSummaries(RLPList summaries) {
    return decodeList(summaries, new Functional.Function<byte[], TransactionExecutionSummary>() {
        @Override
        public TransactionExecutionSummary apply(byte[] encoded) {
            return new TransactionExecutionSummary(encoded);
        }
    });
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:9,代码来源:BlockSummary.java

示例8: decodeReceipts

import org.ethereum.util.Functional; //导入依赖的package包/类
private static Map<String, TransactionReceipt> decodeReceipts(RLPList receipts) {
    return decodeMap(receipts, new Functional.Function<byte[], String>() {
        @Override
        public String apply(byte[] bytes) {
            return new String(bytes);
        }
    }, new Functional.Function<byte[], TransactionReceipt>() {
        @Override
        public TransactionReceipt apply(byte[] encoded) {
            return new TransactionReceipt(encoded);
        }
    });
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:14,代码来源:BlockSummary.java

示例9: encodeRewards

import org.ethereum.util.Functional; //导入依赖的package包/类
private static byte[] encodeRewards(Map<byte[], BigInteger> rewards) {
    return encodeMap(rewards, new Functional.Function<byte[], byte[]>() {
        @Override
        public byte[] apply(byte[] bytes) {
            return RLP.encodeElement(bytes);
        }
    }, new Functional.Function<BigInteger, byte[]>() {
        @Override
        public byte[] apply(BigInteger reward) {
            return RLP.encodeBigInteger(reward);
        }
    });
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:14,代码来源:BlockSummary.java

示例10: keyValues

import org.ethereum.util.Functional; //导入依赖的package包/类
private Map<DataWord, DataWord> keyValues(Functional.Function<Entry, Boolean> filter) {
    Map<DataWord, DataWord> result = new HashMap<>();
    for (Entry entry : getEntries()) {
        if (filter == null || filter.apply(entry)) {
            result.put(entry.getKey(), entry.getValue());
        }
    }
    return result;

}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:11,代码来源:TransactionTouchedStorage.java

示例11: getChanged

import org.ethereum.util.Functional; //导入依赖的package包/类
public Map<DataWord, DataWord> getChanged() {
    return keyValues(new Functional.Function<Entry, Boolean>() {
        @Override
        public Boolean apply(Entry entry) {
            return entry.isChanged();
        }
    });
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:9,代码来源:TransactionTouchedStorage.java

示例12: getReadOnly

import org.ethereum.util.Functional; //导入依赖的package包/类
public Map<DataWord, DataWord> getReadOnly() {
    return keyValues(new Functional.Function<Entry, Boolean>() {
        @Override
        public Boolean apply(Entry entry) {
            return !entry.isChanged();
        }
    });
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:9,代码来源:TransactionTouchedStorage.java

示例13: createIn1

import org.ethereum.util.Functional; //导入依赖的package包/类
Functional.Consumer<BzzMessage> createIn1() {
    return new Functional.Consumer<BzzMessage>() {
        @Override
        public void accept(BzzMessage bzzMessage) {
            BzzMessage smsg = serialize(bzzMessage);
            if (TestPeer.MessageOut) {
                stdout.println("+ " + name1 + " => " + name2 + ": " + smsg);
            }
            out2.accept(smsg);
        }
    };
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:13,代码来源:BzzProtocolTest.java

示例14: createIn2

import org.ethereum.util.Functional; //导入依赖的package包/类
Functional.Consumer<BzzMessage> createIn2() {
    return new Functional.Consumer<BzzMessage>() {
        @Override
        public void accept(BzzMessage bzzMessage) {
            BzzMessage smsg = serialize(bzzMessage);
            if (TestPeer.MessageOut) {
                stdout.println("+ " + name2 + " => " + name1 + ": " + smsg);
            }
            out1.accept(smsg);
        }
    };
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:13,代码来源:BzzProtocolTest.java

示例15: setMessageSender

import org.ethereum.util.Functional; //导入依赖的package包/类
public void setMessageSender(Functional.Consumer<DiscoveryEvent> messageSender) {
    this.messageSender = messageSender;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:4,代码来源:NodeManager.java


注:本文中的org.ethereum.util.Functional类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。