Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.anshul.interviewmagnasoft;

public class EntryPoint {
public static void main(String[] args) {

SwapNElementsLinkedList obj = new SwapNElementsLinkedList();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow naming convention

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow naming convention for variables

SwapNElementsLinkedList.Node listOfNElements = obj.createListOfNElements(5);

obj.printLinkedList(listOfNElements);
SwapNElementsLinkedList.Node reverse = obj.reverse(listOfNElements, 2);

obj.printLinkedList(reverse);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.anshul.interviewmagnasoft;

public class Node {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be inner class if no other class is using Node class

public int data;
public Node next;

}
1 change: 1 addition & 0 deletions programming-parent/datastructurealgo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
35 changes: 35 additions & 0 deletions programming-parent/datastructurealgo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<project
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.anshul</groupId>
<artifactId>datastructurealgo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>datastructurealgo</name>
<url>http://maven.apache.org</url>


<parent>
<groupId>com.anshul</groupId>
<artifactId>programming-parent</artifactId>
<version>2.0</version>
</parent>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>com.anshul.interview.TestSuites.GoodTestCategoryTest</groups>
<excludedGroups>com.anshul.interview.TestSuites.BadTestCategoryTest</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.anshul.designpatterns.behavioural.iterator.channelIterator;

public class Channel {
private double frequency;
private ChannelType type;
private String name;

public Channel(double frequency, ChannelType type, String name) {
this.frequency = frequency;
this.type = type;
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Channel{" +
"frequency=" + frequency +
", type=" + type +
'}';
}

public double getFrequency() {
return frequency;
}

public void setFrequency(double frequency) {
this.frequency = frequency;
}

public ChannelType getType() {
return type;
}

public void setType(ChannelType type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.anshul.designpatterns.behavioural.iterator.channelIterator;

interface ChannelCollection {
void addChannel(Channel channel);

void removeChannel(Channel channel);

ChannelIterator iterator(ChannelType channelType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.anshul.designpatterns.behavioural.iterator.channelIterator;

import java.util.LinkedList;
import java.util.List;

public class ChannelCollectionImpl implements ChannelCollection {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elaborated comments missing on class declaration


private List<Channel> channels = new LinkedList<>();

@Override
public void addChannel(Channel channel) {
channels.add(channel);
}

@Override
public void removeChannel(Channel channel) {
channels.remove(channel);
}

@Override
public ChannelIterator iterator(ChannelType channelType) {
return new ChannelTypeIterator<Channel>(channelType, channels);
}

private class ChannelTypeIterator<T> implements ChannelIterator<T> {

private final List<T> channelList;
private ChannelType channelType;
// to keep track of next channel of given type in the list
private int channelPositionIndex;

public ChannelTypeIterator(ChannelType channelType, List<T> channels) {
this.channelType = channelType;
synchronized (channels) {
channelList = channels;
}
}

@Override
public boolean hasNext() {

while (channelPositionIndex < channelList.size()) {
if (((Channel) channelList.get(channelPositionIndex)).getType().equals(channelType)) {
return true;
} else {
channelPositionIndex++;
}
}
return false;
}

@Override
public T next() {
return channelList.get(channelPositionIndex++);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.anshul.designpatterns.behavioural.iterator.channelIterator;

public interface ChannelIterator<T> {
boolean hasNext();

T next();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.anshul.designpatterns.behavioural.iterator.channelIterator;

public enum ChannelType {
ENGLISH, HINDI, PUNJABI, HARYANAVI;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.anshul.designpatterns.behavioural.iterator.channelIterator;

public class EntryPointChannelIterator {
public static void main(String[] args) {
ChannelCollection c = new ChannelCollectionImpl();
c.addChannel(new Channel(70, ChannelType.ENGLISH, "HBO"));
c.addChannel(new Channel(75, ChannelType.ENGLISH, "DISCOVERY"));
c.addChannel(new Channel(80, ChannelType.HINDI, "SUB TV"));
c.addChannel(new Channel(85, ChannelType.HINDI, "SONY"));
c.addChannel(new Channel(90, ChannelType.HINDI, "Aaj Tak"));

ChannelIterator hindiIterator = c.iterator(ChannelType.HINDI);
while (hindiIterator.hasNext()) {
System.out.println(hindiIterator.next().toString());
}


ChannelIterator englishIterator = c.iterator(ChannelType.ENGLISH);
while (englishIterator.hasNext()) {
System.out.println(englishIterator.next().toString());
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// package whatever; // don't place package name!

import java.io.*;

interface Message {
private String getId();
public String getPayload();
public MessageType getMessageType();

//getters & setters
}
BinaryMessage implements Message
TextMessage implements Message
interface MessageListener<T extends Message>{
public void onMessage(List<T> messageList);
}

class MessageListenerImpl<T extends Message,U> implements MessageListener{

//Remove duplicate messages based on ID


//OCP
<T> public U onMessage(T message){
Set<Message> messageSet
//

}
}

//Requirment: if Message is of type XML then persist it
//if it is JSON then publish it


interface MessagePublisher{
public void publish(Message msg)
}
interface MessagePersistenceSvc{
public void persist(Message msg)
}

interface MessageHandlerChain{
public void handler();
public Priority getPriority();
}

class MessageHandlerChainImpl{



public void handler(){

}
public Priority getPriority(){

}
}
enum Priority{
CRITICAl,MEDIUM,
}

class MessgePublisherImpl implements MessagePublisher{

private MessageHandlerChain nextHandler;

public MessagePublisherImpl(MessageHandlerChain nextHandler){
this.nextHandler = handler;
}

public void publish(Message msg){
if(msg.getType().equals("JSON"))
{
//
}
else{
nextHandler.handler(Message msg);
}
}
}

// class MessagePublisherHanler implements MessageHandlerChain{

// private MessegePublisher messagePublisher;
// private MessageHandlerChain nextHandler;

// public MessagePublisherImp(MessageHandlerChain nextHandler, MessegePublisher messagePublisher){
// this.handler = nextHandler;
// this.messagePublisher = messagePublisher;
// }

// public void handler(){
// }

}
Loading