GOF23设计模式之 迭代器模式

告别瞎猜!用通达信/同花顺这些资金流向函数,一眼看穿主力动向(附实战公式) 本文详细解析了通达信/同花顺资金流向函数的实战应用,帮助投资者精准识别主力动向。通过12个核心资金函数的组合逻辑,构建主力行为监控体系,避免未来函数陷阱,识别主力对倒行为,并提前捕捉异动。适合股票投资者提升自选股分析能力。 阅读详情

场景:

  • 提供一种可以遍历聚合对象的方式。又称为:游标cursor模式
  • 聚合对象:存储数据
  • 迭代器:遍历数据

基本案例

  • 实现正向遍历的迭代器
  • 实现逆向遍历的迭代器

开发中常见的场景

  • JDK内置的迭代器(List/Set)

一种实现

  • MyIterator
package com.coderbean.iterator;

/**
 * Created by Chang on 15/10/3.
 */
public interface MyIterator {
    void first();//将游标指向第一个
    void next();    //将游标指向下一个
    boolean hasNext();
    boolean isFirst();
    boolean isLast();

    //获取当前游标所指向的对象
    Object getCurrentObj();


}
  • ConcreteMyAggregate
package com.coderbean.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义的聚合类
 * Created by Chang on 15/10/3.
 */
public class ConcreteMyAggregate {
    private List<Object> list = new ArrayList<Object>();

    public void addObject(Object object){
        this.list.add(object);
    }

    public void removeObject(Object object){
        this.list.remove(object);
    }

    public List<Object> getList() {
        return list;
    }

    public void setList(List<Object> list) {
        this.list = list;
    }

    public MyIterator createIterator(){
        return new ConcreteIterator();
    }

    private class ConcreteIterator implements MyIterator {

        private int cursor; //定义游标用于纪录遍历时的位置

        @Override
        public void first() {
            cursor = 0;
        }
TE
        @Override
        public void next() {
            if(this.hasNext()){
                cursor++;
            }
        }

        @Override
        public boolean hasNext() {
            if(cursor<list.size())
                return true;
            return false;
        }

        @Override
        public boolean isFirst() {
            return cursor==0;
        }

        @Override
        public boolean isLast() {
            return cursor==list.size()-1;
        }

        @Override
        public Object getCurrentObj() {
            return list.get(cursor);
        }
    }
}
  • Client
package com.coderbean.iterator;

/**
 * Created by Chang on 15/10/3.
 */
public class Client {
    public static void main(String[] args) {
        ConcreteMyAggregate concreteMyAggregate = new ConcreteMyAggregate();
        concreteMyAggregate.addObject("aa");
        concreteMyAggregate.addObject("bb");
        concreteMyAggregate.addObject("cc");

        MyIterator iter = concreteMyAggregate.createIterator();
        while(iter.hasNext()){
            System.out.println(iter.getCurrentObj());
            iter.next();
        }
    }
}
扫地机器人:从仿真到决策,一个完整SLAM导航系统的自研之路 本文详细记录了从零开始自研扫地机器人SLAM导航系统的全过程,涵盖ROS-Gazebo仿真系统搭建、地图预处理优化、全覆盖规划算法迭代等关键技术。通过三次算法升级,最终实现92%的清洁效率,并分享DWA调参、状态机设计等实战经验,为开发者提供从仿真到落地的完整解决方案。 阅读详情

相关推荐

opencv去除印章痕迹

今天看到一个很有意思的程序,就是去除票据上的红色印章,觉得很有意思,就把它抄过来记录一下,同时自己也开了一下脑洞。 原来的程序来自:https://www.cnblogs.com/skyfsm/p/7638301.html 可以看到图像效果很不错,下面是源码实现: #include &lt;iostream&gt; #include &lt;opencv2/imgproc/imgpro...

zeng_haoyu的博客 7956

GOF之迭代器模式

迭代器模式   其实迭代器模式的话,我们经常使用。现在我们就来学习一个迭代器的底层的实现。        现在我们来学习一下迭代器的底层的实现:     package com.bjsxt.iterator;     /**  *  自定义的迭代器接口  * @author Administrator  *  */ public interface MyIter

li12412414的博客 291

告别BAPI!深入SAP S/4HANA BP框架:cl_md_bp_maintain维护客户主数据的正确姿势与性能优化

本文深入解析SAP S/4HANA中cl_md_bp_maintain框架的高效实践与架构设计,对比传统BAPI方式,展示其在业务伙伴(BP)主数据维护中的性能优势与现代化特性。通过详细代码示例和性能测试数据,揭示如何利用该框架实现批量处理、集中校验及智能错误恢复,助力企业从ECC向S/4HANA平滑迁移。

weixin_30596735的博客 357

《GOF设计模式》学习笔记—Iterator迭代器

 官方描述提供一种方法顺序访问一个聚合对象中的各元素,而又无需暴露该聚合对象的内部表示。 我的理解1、价值所在:Iterator迭代器模式相对于其他模式显得对于要处理的问题更具体一些,它把一个聚合对象中元素访问和遍历操作从该聚合对象内部分离出去,从而提供了以下三方面的好处:1)简化聚合类型接口因为聚合对象不再需要直接对外提供访问和遍历自己内部元素的服务,所以简化了聚

qinysong的专栏 1525

记录LeNet的硬件加速器设计(一)

LeNet的硬件加速器设计实现。

2301_81029398的博客 3543

Seedance2.5本地部署指南:从环境配置到生产优化的完整实践

在 AI 内容生成领域,本地部署方案正逐渐成为开发者和技术团队关注的焦点。Seedance2.5 作为一款支持图像和视频生成的 AI 工具,其完全离线运行的能力解决了云端服务在数据隐私、使用成本和访问稳定性方面的痛点。对于需要处理敏感内容、频繁生成素材或希望完全掌控生成流程的技术人员来说,掌握本地部署方法具有实际价值。 本文将以 Seedance2.5 的本地部署为例,详细介绍从环境准备、依赖配置到运行验证的完整流程,同时深入分析关键参数配置、常见问题排查方法以及生产环境下的优化建议。通过实际部署过程,理解

weixin_33139275的博客 726

【十四】Java设计模式GOF23之迭代器模式

简介 迭代器模式(Iterator Pattern)是 Java 和 .Net 编程环境中非常常用的设计模式。这种模式用于顺序访问集合对象的元素,不需要知道集合对象的底层表示。 它提供一种方法顺序访问一个聚合对象中各个元素, 而又无须暴露该对象的内部表示。 迭代器模式的结构 1.抽象容器:一般是一个接口,提供一个iterator()方法,例如java中的Collection接口,List接...

Sid小杰的博客 307

GPS-SDR-SIM使用详解

GPS-SDR-SIM 是一款开源工具,能够生成 GPS 基带信号数据流,这些数据流可通过软件定义无线电(SDR)平台(如 ADALM-Pluto、bladeRF、HackRF、USRP 等)转换为射频(RF)信号。简单来说,它能模拟 GPS 卫星信号,帮助开发者或爱好者测试 GPS 接收设备的性能,而无需依赖真实的卫星信号。

qq_35621280的博客 1241

设计模式之GOF23迭代器模式

迭代器模式Iterator /*** 自定义迭代器接口* @author 小帆敲代码**/public interface MyIterator {void first();//游标置于第一个void last();//游标置于最后一个boolean isfirst();boolean isLast();void next();//游标后移一...

qq_44711190的博客 129

撸毛笔记-朴朴超市 v1.01

朴朴超市 v1.01脚本地址:自动签到和组队赚朴分, 朴分可以抵扣50%的金额组队瓜分需要4人成团, 每个号每天只能开团和入队各一次每天跑一两次即可使用扫码或自己想办法捉refreshToken扫码获取token: (先微信进入朴朴超市小程序并登录注册过账号再扫码)把获取的refreshToken和备注(非必须)填到文件pupuCookie.txt里(第一次运行会自动创建), 多账号换行或&或@隔开。

xiaoshun007的专栏 1805

含分布式电源的配电网三段式电流保护影响仿真研究

文章摘要 本文研究了分布式电源(DG)接入对配电网三段式电流保护的影响。通过在Matlab/Simulink平台搭建含同步发电机型DG的10kV配电网模型,设计了基于傅里叶算法的三段式电流保护模块(I段瞬时速断、II段限时速断、III段定时限过流)。研究分析了不同DG接入位置、容量及故障点对保护系统的影响机理。仿真结果表明,DG接入会改变故障电流特性,可能导致三种典型问题:保护范围扩大引起误动、保护灵敏度下降导致拒动,以及保护选择性丧失。该研究为含DG配电网的保护配置与整定提供了理论依据和仿真参考,对保障分

huanghm88的专栏 268

GOF23设计模式之迭代器模式

根据迭代器常用接口 first next hasnext isFirst isLast getCurrentObj ,在做自定义的聚合类,实现迭代器接口。

开心杨的个人博客 345

python中有趣的库 freegames 的详细使用

freegames 是一个包含多个简单 Python 游戏的开源库,适合初学者学习 Python 编程和游戏开发。以下是 freegames 的详细介绍和用法示例。

数据知道的博客 3万+

GOF23设计模式之迭代器模式(iterator)

一、迭代器模式概述   提供一种可以遍历聚合对象的方式。又称为:游标(cursor)模式   结构:     (1)聚合对象:存储数据     (2)迭代器:遍历数据 二、迭代器模式示例代码   定义:正向遍历迭代器和逆向遍历迭代器 1 /** 2 * 自定义迭代器接口 3 * @author CL 4 * 5 */ 6 public in...

dcpvpf6917的博客 168

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

【Go实现】实践GoF的23种设计模式:迭代器模式

迭代器模式主要用在访问对象集合的场景,能够向客户端隐藏集合的实现细节

ruanrunxue的博客 404

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

设计模式GOF23——迭代器模式

迭代器模式(iterator),又称为游标(cursor)模式

buyoufa的博客 483

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Java23种设计模式(GOF)——迭代器模式

迭代器模式(iterator)结构案例开发中常见场景 提供一种可以遍历聚合对象的方式。又称为:游标cursor模式 结构 聚合对象:存储数据 迭代器:遍历数据 案例 /** * 自定义迭代器接口 * @author huangyzh * @create 2020-05-19 0:28 */ public interface MyIterator { void first();//将游标指向第一个 void next();//将游标指向下一个 boolean hasNext

ozhi的博客 225

【GOF23设计模式】迭代器模式

【GOF23设计模式】迭代器模式 来源:http://www.bjsxt.com/一、【GOF23设计模式】_迭代器模式、JDK内置迭代器、内部类迭代器 1 package com.test.iterator; 2 /** 3 * 自定义的迭代器接口 4 */ 5 public interface MyIt...

weixin_30653023的博客 102

GoF23种设计模式之行为型模式之迭代器模式

一、概述     给定一种语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子。 二、适用性 1.当访问一个聚合对象的内容而无需暴露它的内部表示的时候。 2.当对聚合对象的多种遍历提供支持的时候。 3.当为了遍历不同的聚合结构提供一个统一的接口的时候(多态迭代)。 三、参与者 1.Iterator:迭代器定义访问和遍历元素的接口。 2.Concr

leverli的专栏 1650

GOF23设计模式之迭代器模式理解与实现

 迭代器模式      场景:          提供一种可以遍历聚合对象的方式。又称为游标cursor模式          聚合对象:存储数据          迭代器模式:遍历数据   聚集抽象类 Aggregate Iterator 迭代抽象类,用于定义得到开始对象,得到下一个对象,判断是否

不当初 892

厚积薄发打卡Day46: [itcast] GoF23通俗易懂的设计模式之 <迭代器模式>

前言: 视频教程:黑马程序员Java设计模式详解,全网最全23种Java设计模式 什么是设计模式? 设计模式(Design Pattern)是前辈们对代码开发经验的总结,是一套用来提高代码可复用性、可维护性、可读性、稳健性以及安全性的解决方案。 1995年,GoF(Gang of Four,四人组)合作出版了《设计模式:可复用面向对象软件的基础》一书,共收录了23种设计模式,人称 【GoF设计模式】 设计模式分类 具体模式 创建型模式:它的主要特点是“将对象的创建与使用分离”。这样可

COOLGWAYNE_TECH_BLOG 171

java 23种设计模式之 迭代器模式(cursor模式)GOF 23-1

今天分享一个迭代器模式(Iterator 模式)          如果存在什么不对的地方,感谢大佬们给予指正,谢谢。 先谈谈具体的思路,然后我再上图。         1.首先建立一个接口。接口的具体的需要被实现的方法 可以自行添加。 (也就是我们的需求,要求这个迭代器需要些什么功能。)                 2.创建一个普通类。             (1).这

Snail_Come_On的博客 622

GOF23设计模式-行为型模式2-迭代器模式(Iterator)

GOF23设计模式-行为型模式2-迭代器模式(Iterator):提供一种遍历聚合对象的方式,而又不暴露该对象的内部表示。

Tumbler 217

GOF23 设计模式 之外观模式和迭代器模式

外观模式就是你平时 写代码的时候的封装; 遵循着 迪米特法则:一个软件实体 尽量减少和其他软件实体的发生作用; 尽可能的封装 ,使代码复用提高,层次清楚。 *************************************** 迭代器模式 就是 一个迭代器 实现上 比如数组,list 等,一般 很少在业务代码中使用 ...

wangrong111222的博客 167

java_244_GOF23设计模式_迭代器模式_JDK内置迭代器_内部类迭代器_练习

迭代器模式iterator //--------------------迭代器的接口------------------------- package java_244_GOF23设计模式_迭代器模式_JDK内置迭代器_内部类迭代器_练习; /** 自定义迭代器的接口 */ public interface MyIterator {//MyIterator我的迭代器 void first();//最前面的;将游标指向第一个元素 void next();//紧接在后的;将游标指向下一个元素 boole

weixin_45339692的博客 113
上一篇: GOF 23 设计模式之 责任链模式(Chain Of Responsibility)
下一篇: GOF23设计模式之 中介者模式Mediator
coderbean
博客等级 码龄11年 12粉丝 84原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值