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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added README.md
Empty file.
6 changes: 6 additions & 0 deletions echoStream/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions echoStream/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>echoStream</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions echoStream/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
14 changes: 14 additions & 0 deletions echoStream/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=1.8
Binary file added echoStream/bin/GUI/Gui$1.class
Binary file not shown.
Binary file added echoStream/bin/GUI/Gui$2.class
Binary file not shown.
Binary file added echoStream/bin/GUI/Gui$3.class
Binary file not shown.
Binary file added echoStream/bin/GUI/Gui.class
Binary file not shown.
Binary file added echoStream/bin/components/GlobalHolder.class
Binary file not shown.
Binary file added echoStream/bin/components/Graph.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added echoStream/bin/components/Post$1.class
Binary file not shown.
Binary file added echoStream/bin/components/Post$2.class
Binary file not shown.
Binary file added echoStream/bin/components/Post$3.class
Binary file not shown.
Binary file added echoStream/bin/components/Post.class
Binary file not shown.
Binary file not shown.
Binary file added echoStream/bin/components/Tag.class
Binary file not shown.
Binary file added echoStream/bin/interfaces/HasPopularity.class
Binary file not shown.
Binary file added echoStream/bin/interfaces/HasPost.class
Binary file not shown.
Binary file added echoStream/bin/interfaces/HasTag.class
Binary file not shown.
Binary file added echoStream/bin/phaseOne/Phase1.class
Binary file not shown.
Binary file added echoStream/bin/utilities/CreateMedia.class
Binary file not shown.
Binary file added echoStream/bin/utilities/TagComparator.class
Binary file not shown.
93 changes: 93 additions & 0 deletions echoStream/src/GUI/Gui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package GUI;
import phaseOne.Phase1;

import javax.swing.*;

import components.Post;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class Gui extends JFrame {
static final long serialVersionUID = 6536891361170925993L;
private int currentPage = 1;
private final int postsPerPage = 20;
private ArrayList<Post> posts;
private JPanel postsPanel;
private JScrollPane scrollPane;

public Gui() {
setTitle("Social Media App");
setSize(600, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
Phase1 tempo = new Phase1();

posts = tempo.getRawTempoData();

// posts = new ArrayList<>();
//
// for (int i = 1; i <= 50; i++) {
// posts.add(new Post("Post " + i, "Caption for post " + i, "HashTag" + i));
// }

postsPanel = new JPanel();
postsPanel.setLayout(new BoxLayout(postsPanel, BoxLayout.Y_AXIS));
scrollPane = new JScrollPane(postsPanel);

loadPosts();

JPanel buttonPanel = new JPanel();
JButton prevButton = new JButton("Previous");
JButton nextButton = new JButton("Next");
prevButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (currentPage > 1) {
currentPage--;
loadPosts();
}
}
});
nextButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (currentPage < (posts.size() / postsPerPage)) {
currentPage++;
loadPosts();
}
}
});
buttonPanel.add(prevButton);
buttonPanel.add(nextButton);

add(scrollPane, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
}

private void loadPosts() {
postsPanel.removeAll();
int start = (currentPage - 1) * postsPerPage;
int end = Math.min(start + postsPerPage, posts.size());
for (int i = start; i < end; i++) {
postsPanel.add(posts.get(i).getPostPanel());
}
postsPanel.revalidate();
postsPanel.repaint();
}




public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Gui().setVisible(true);
}
});
}


}
40 changes: 40 additions & 0 deletions echoStream/src/components/GlobalHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package components;

import java.util.HashMap;
import java.util.Map;

public class GlobalHolder {
private static GlobalHolder instance;
private Map<String, Float> sharedValues;

private GlobalHolder() {
sharedValues = new HashMap<>();
} // Private constructor

public static GlobalHolder getInstance() {
if (instance == null) {
instance = new GlobalHolder();
}
return instance;
}

public Float getSharedValue(String key) {
return sharedValues.get(key);
}

public void setSharedValue(String key, Float value) {
sharedValues.put(key, value);
}

public void removeSharedValue(String key) {
sharedValues.remove(key);
}

public boolean containsKey(String key) {
return sharedValues.containsKey(key);
}

public Map<String, Float> getAllSharedValues() {
return new HashMap<>(sharedValues);
}
}
170 changes: 170 additions & 0 deletions echoStream/src/components/Graph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package components;

import java.util.ArrayList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.TreeMap;

import interfaces.HasPost;
import interfaces.HasTag;
import utilities.TagComparator;

public class Graph<T extends HasTag, A extends HasPost> {

@SuppressWarnings({ "unchecked", "rawtypes" })
private Map<T, PriorityQueue<A>> map = new TreeMap<>(new TagComparator());

// This function adds a new vertex to the graph
public void addVertex(T s) {
if (!map.containsKey(s)) {
map.put(s, new PriorityQueue<>((a1, a2) -> Float.compare(a1.getPriority(), a2.getPriority())));
} else {
System.out.println("Vertex already exists: " + s.getTitle());
}
}

// This function adds the edge between source and destination
public void addEdge(T source, A destination) {
if (!map.containsKey(source)) {
addVertex(source);
}
map.get(source).offer(destination); // Using offer to add elements to the priority queue
}





//just for testing
public void getKey(T source) {
PriorityQueue<A> collection = map.get(source);
ArrayList<A> list = new ArrayList<>(collection);
System.out.println(list.get(1).getPriority());
}


//setting TagPopularity Dynamically
@SuppressWarnings("unchecked")
public void setTagPopularity(T vertex, float newPopularity) {

if (!map.containsKey(vertex)) {
System.out.println("Vertex not found.");
return;
}

PriorityQueue<A> edges = map.remove(vertex);

Tag tempoTag = new Tag(vertex.getTitle());
tempoTag.setPopularity(newPopularity);
GlobalHolder.getInstance().setSharedValue(tempoTag.getTitle(),newPopularity);




// Create a new vertex with updated priority



// Replace the old vertex in the map with the new one
map.put((T) tempoTag, edges);
}


//setting Post Priority Dynamically
public void setPriority(T source, String element, float newPriority) {
PriorityQueue<A> collection = map.get(source);
if (collection == null) {
System.out.println("No such priority queue for the given source.");
return;
}

// Create a temporary priority queue to hold the updated elements
PriorityQueue<A> updatedQueue = new PriorityQueue<>((a1, a2) -> Float.compare(a1.getPriority(), a2.getPriority()));
boolean found = false;

// Iterate through the original queue to find and update the element
for (A e : collection) {
if (e.getTitle().equals(element)) {

e.setPriority(newPriority);

found = true;
}
updatedQueue.add(e);
}

if (!found) {
System.out.println("Element not found in the priority queue.");
return;
}

// Replace the old priority queue with the updated one

map.put(source, updatedQueue);
}

// This function gives the count of vertices
public void getVertexCount() {
System.out.println("The graph has " + map.keySet().size() + " vertices.");
}

// This function gives the count of edges
public void getEdgesCount() {
int count = 0;
for (PriorityQueue<A> neighbors : map.values()) {
count += neighbors.size();
}
System.out.println("The graph has " + count + " edges.");
}

// This function gives whether a vertex is present or not
public void hasVertex(T s) {
if (map.containsKey(s)) {
System.out.println("The graph contains " + s.getTitle() + " as a vertex.");
} else {
System.out.println("The graph does not contain " + s.getTitle() + " as a vertex.");
}
}

// This function gives whether an edge is present or not
public void hasEdge(T s, A d) {
if (map.containsKey(s)) {
PriorityQueue<A> queue = map.get(s);
// Check if the destination exists in the queue
if (queue.contains(d)) {
System.out.println("The graph has an edge between " + s.getTitle() + " and " + d.getTitle() + ".");
} else {
System.out.println("The graph has no edge between " + s.getTitle() + " and " + d.getTitle() + ".");
}
} else {
System.out.println("The graph has no edge between " + s.getTitle() + " and " + d.getTitle() + ".");
}
}

// This function prints the neighbors of a vertex
public void neighbours(T s) {
if (!map.containsKey(s)) {
System.out.println("Vertex " + s.getTitle() + " not found.");
return;
}
System.out.print("The neighbors of " + s.getTitle() + " are: ");
for (A w : map.get(s)) {
System.out.print(w.getTitle() + " ");
}
System.out.println();
}

// Prints the adjacency list of each vertex
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (T v : map.keySet()) {
builder.append(v.getTitle()).append(": ");
for (A w : map.get(v)) {
builder.append(w.getTitle()).append(" <-> ");
}
builder.append("\n");
}
return builder.toString();
}
}
Loading