filename stringlengths 7 140 | content stringlengths 0 76.7M |
|---|---|
code/data_structures/src/tree/space_partitioning_tree/interval_tree/interval_tree.java | //This is a java program to implement a interval tree
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
class Interval<Type> implements Comparable<Interval<Type>>
{
private lo... |
code/data_structures/src/tree/space_partitioning_tree/kd_tree/kd_tree.cpp | #include <iostream>
using namespace std;
// Part of Cosmos by OpenGenus Foundation
const int k = 2;
struct Node
{
int point[k]; // To store k dimensional point
Node *left, *right;
};
struct Node* newNode(int arr[])
{
struct Node* temp = new Node;
for (int i = 0; i < k; i++)
temp->point[i] = a... |
code/data_structures/src/tree/space_partitioning_tree/kd_tree/kd_tree.java | import java.util.Comparator;
import java.util.HashSet;
public class KDTree
{
int k;
KDNode root;
public KDTree(KDPoint[] points)
{
k = 2;
root = createNode(points,0);
}
public KDNode createNode(KDPoint[] points,int level)
{
if(points.length == 0) return null;
int axis = level % k;
KDPoint median =... |
code/data_structures/src/tree/space_partitioning_tree/oc_tree/oc_tree.py | # Part of Cosmos by OpenGenus Foundation
class Octant:
"""
UP: Y positive.
DOWN: Y negative.
FRONT: Z positive.
BACK: Z negative.
RIGHT: X positive.
LEFT: X negative.
"""
UP_FRONT_LEFT = 0
UP_FRONT_RIGHT = 1
UP_BACK_LEFT = 2
UP_BACK_RIGHT = 3
DOWN_FRONT_LEFT = 4
... |
code/data_structures/src/tree/space_partitioning_tree/quad_tree/Python_Implementation_Visualization/QuadTree.py | # Part of Cosmos by OpenGenus Foundation
from tkinter import *
class Rectangle:
def __init__(self, x, y, h, w):
self.x = x
self.y = y
self.h = h
self.w = w
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
class QuadTree:
def __init__(self, bo... |
code/data_structures/src/tree/space_partitioning_tree/quad_tree/Python_Implementation_Visualization/Visualizer.py | # Part of Cosmos by OpenGenus Foundation
from QuadTree import *
if __name__ == '__main__':
boundary = Rectangle(200, 200, 150, 150)
QT = QuadTree(boundary, 1)
pointsList = [Point(240, 240), Point(150, 150), Point(300, 215), Point(200, 266), Point(333, 190)]
for point in pointsList:
QT.insert(po... |
code/data_structures/src/tree/space_partitioning_tree/quad_tree/quad_tree.swift | // Part of Cosmos by OpenGenus Foundation
public struct Point {
let x: Double
let y: Double
public init(_ x: Double, _ y: Double) {
self.x = x
self.y = y
}
}
extension Point: CustomStringConvertible {
public var description: String {
return "Point(\(x), \(y))"
}
}
public struct Size: CustomSt... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/README.md | # Segment Trees
Segment Tree is used in cases where there are multiple range queries on array and modifications of elements of the same array. For example, finding the sum of all the elements in an array from indices **L to R**, or finding the minimum (famously known as **Range Minumum Query problem**) of all the elem... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/lazy_segment_tree.java | // Java program to demonstrate lazy propagation in segment tree
// Part of Cosmos by OpenGenus Foundation
class LazySegmentTree
{
final int MAX = 1000; // Max tree size
int tree[] = new int[MAX]; // To store segment tree
int lazy[] = new int[MAX]; // To store pending updates
/* index -> inde... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/persistent_segment_tree_sum.cpp | // Fully persistent Segment tree with spaces. Allows to find sum in O(log size) time in any version. Uses O(n log size) memory.
#include <iostream>
#include <string>
const int size = 1000000000;
const int versionCount = 100000;
struct node
{
int leftBound, rightBound;
node *leftChild, *rightChild;
int val... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree.java | // Part of Cosmos by OpenGenus Foundation
// Java Program to show segment tree operations like construction, query and update
class SegmentTree {
int st[]; // The array that stores segment tree nodes
SegmentTree(int arr[], int n) {
// Allocate memory for segment tree
//Height of segment tree
... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree.scala | import scala.reflect.ClassTag
case class SegmentTree[T: ClassTag](input: Array[T], aggregator: (T, T) => T) {
val maxArraySize = Math.pow(2.0, Math.ceil(Math.log(input.length) / Math.log(2.0))).toInt * 2 - 1
val treeArray = populateTree((0, input.length - 1), Array.ofDim[T](maxArraySize), 0)
def leftChil... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_kth_statistics_on_segment.cpp | #include <cassert>
#include <iostream>
#include <vector>
using namespace std;
const int lb = -1e9, rb = 1e9;
struct node
{
int val;
node *l, *r;
node()
{
val = 0;
l = r = nullptr;
}
node(int x)
{
val = x;
l = r = nullptr;
}
node(node* vl, node* vr)
... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_lazy_propagation.cpp | // Part of Cosmos by OpenGenus Foundation
#include <iostream>
using namespace std;
#define N 10000000
int tree[N + 1], lazy[N + 1], A[N];
void build(int node, int start, int end)
{
if (start == end)
// Leaf node will have a single element
tree[node] = A[start];
else
{
int mid = (sta... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_rmq.adb | with Ada.Integer_Text_IO, Ada.Text_IO;
use Ada.Integer_Text_IO, Ada.Text_IO;
-- Compile:
-- gnatmake segment_Tree_rmq
procedure segment_Tree_rmq is
INT_MAX: constant integer := 999999;
MAXN : constant integer := 100005;
v : array(0..MAXN) of integer;
tree: array(0..4*MAXN) of integer;
n : integer;
q : integer;
a : i... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_rmq.cpp | /* Name: Mohit Khare
* B.Tech 2nd Year
* Computer Science and Engineering
* MNNIT Allahabad
*/
#include <cstdio>
#include <climits>
#define min(a, b) ((a) < (b) ? (a) : (b))
using namespace std;
typedef long long int ll;
#define mod 1000000007
const int maxn = 1e5 + 1;
void build(ll segtree[], ll arr[], int low,... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_rmq.go | /*
* Segment Tree
* Update: 1 point
* Query: Range
* Query Type: Range Minimum Query
*/
package main
import "fmt"
type SegmentTree struct {
N int
tree []int
}
func Min(x int, y int) int {
if x < y {
return x
}
return y
}
func (stree *SegmentTree) Initialize(n int) {
stree.N = n
stree.tree = make([]... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_rmq.py | import math
def update(tree, l, r, node, index, diff):
if l == r:
tree[node] = diff
return tree[l]
mid = l + (r - l) // 2
if index <= mid:
update(tree, l, mid, (2 * node) + 1, index, diff)
tree[node] = min(tree[node * 2 + 2], tree[node * 2 + 1])
return diff
els... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_rmq_with_update.cpp | /* Part of Cosmos by OpenGenus Foundation */
/*
* Processes range minimum query.
* Query function returns index of minimum element in given interval.
* Code assumes that length of array can be contained into integer.
*/
#include <iostream>
#include <utility>
#include <vector>
struct Node
{
// store the data ... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_sum.cpp | // Segment tree with spaces. Allows to find sum in O(log size) time. Uses O(n log size) memory.
#include <iostream>
#include <string>
const int size = 1000000000;
struct node
{
int leftBound, rightBound;
node *leftChild, *rightChild;
int value;
node (int LeftBound, int RightBound)
{
leftB... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_sum.go | /*
* Segment Tree
* Update: 1 point
* Query: Range
* Query Type: Range Sum Query
*/
package main
import "fmt"
type SegmentTree struct {
N int
tree []int
}
func (stree *SegmentTree) Initialize(n int) {
stree.N = n
stree.tree = make([]int, 4*n)
}
func (stree *SegmentTree) build(arr []int, idx int, l int, ... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_sum.py | # Part of Cosmos by OpenGenus Foundation
class SegmentTree:
def __init__(self, arr):
self.n = len(arr) # number of elements in array
self.arr = arr # stores given array
self.segtree = [0] * (
4 * self.n
) # stores segment tree, space required is 4 * (number of elemen... |
code/data_structures/src/tree/space_partitioning_tree/segment_tree/segment_tree_sum.rb | # Part of Cosmos by OpenGenus Foundation
class SegTree
def initialize(arr)
@arr = arr
@end = arr.length - 1
@tree = Array.new(arr.length * 4, 0)
start(0, 0, @end)
end
def start(root, left, right)
if left == right
@tree[root] = @arr[left]
return 0
end
mid = (left + right) ... |
code/data_structures/src/tree/tree/suffix_array/suffix_array.cpp | #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll size_t
using namespace std;
struct ranking
{
ll index;
ll first;
ll second;
};
bool comp(ranking a, ranking b)
{
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
vector<l... |
code/data_structures/src/tree/tree/trie/README.md | # Trie
Description
---
In computer science, also called digital tree and sometimes radix tree or prefix tree
(as they can be searched by prefixes),
is a kind of search tree -- an ordered tree data structure that is used to store a
dynamic set or associative array where the keys are usually strings.
Trie API
---
- i... |
code/data_structures/src/tree/tree/trie/trie.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
// Part of Cosmos by OpenGenus Foundation
#define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
#define ALPHABET_SIZE (26)
#define INDEX(c) ((int)c - (int)'a')
#define FREE(p) \
free(p); \
p = NULL;
typedef struct trie_node trie_node_t... |
code/data_structures/src/tree/tree/trie/trie.cpp | #include <cstdio>
#include <string>
#include <iostream>
// Part of Cosmos by OpenGenus
using namespace std;
#define mod 1000000007
#define all(v) v.begin(), v.end_()
#define rep(i, a, b) for (i = (ll)a; i < (ll)b; i++)
#define revrep(i, a, b) for (i = (ll)a; i >= (ll)b; i--)
#define strep(it, v) for (it = v.begin(); i... |
code/data_structures/src/tree/tree/trie/trie.cs | using System;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;
namespace Cosmos
{
// XUnit test to test Trie data structure.
public class TriestTest
{
private readonly TrieBuilder _trieBuilder = new TrieBuilder();
public TriestTest(ITestOutputHelper output) : base(output)
{
}
... |
code/data_structures/src/tree/tree/trie/trie.go | package main
import "fmt"
// TrieNode has a value and a pointer to another TrieNode
type TrieNode struct {
children map[rune]*TrieNode
value interface{}
}
// New allocates and returns a new *TrieNode.
func New() *TrieNode {
return &TrieNode{
children: make(map[rune]*TrieNode),
}
}
// Contains returns true ... |
code/data_structures/src/tree/tree/trie/trie.java | // Part of Cosmos by OpenGenus Foundation
class TrieNode {
char c;
HashMap<Character, TrieNode> children = new HashMap<Character, TrieNode>();
boolean isEnd;
public TrieNode() {}
public TrieNode(char c){ this.c = c; }
}
public class Trie {
private TrieNode root;
public Trie() {
... |
code/data_structures/src/tree/tree/trie/trie.js | /* Part of Cosmos by OpenGenus Foundation */
class Node {
constructor() {
this.keys = new Map();
this.end = false;
}
setEnd() {
this.end = true;
}
isEnd() {
return this.end;
}
}
class Trie {
constructor() {
this.root = new Node();
}
add(input, node = this.root) {
if (input.l... |
code/data_structures/src/tree/tree/trie/trie.py | # An efficient information reTRIEval data structure
class TrieNode(object):
def __init__(self):
self.children = {}
def __repr__(self):
return str(self.children)
def insert(root_node, word):
n = root_node
for character in word:
t = n.children.get(character)
if not t:
... |
code/data_structures/src/tree/tree/trie/trie.rb | class Trie
def insert(word)
return if word.empty?
first, rest = word.split(''.freeze, 2)
children[first].insert(rest)
end
def search(word)
return true if word.empty?
first, rest = word.split(''.freeze, 2)
children.key?(first) && children[first].search(rest)
end
private
def child... |
code/data_structures/src/tree/tree/trie/trie.scala | import collection.immutable.IntMap
object Trie {
def apply(text: String): Trie = {
if (text == "") {
return new Trie(IntMap(), true)
} else {
return new Trie(IntMap(text.charAt(0).asInstanceOf[Int] -> apply(text.substring(1))), false)
}
}
}
case class Trie(kids:... |
code/data_structures/src/tree/tree/trie/trie.swift | // Part of Cosmos by OpenGenus Foundation
import Foundation
class TrieNode<T: Hashable> {
var value: T?
weak var parentNode: TrieNode?
var children: [T: TrieNode] = [:]
var isTerminating = false
var isLeaf: Bool {
return children.count == 0
}
init(value: T? = nil, parentNode: TrieNode? = nil) {
... |
code/data_structures/src/tree/van_emde_boas_tree/van_emde_boas_tree.cpp | #include <bits/stdc++.h>
using namespace std;
class veb
{
int u;
int *min;
int *max;
veb *summary;
veb **cluster;
public:
veb(int u);
void insert(int x);
void remove(int x);
int* pred(int x);
int minimum();
int maximum();
};
veb :: veb(int u)
{
this->u = u;
this-... |
code/data_structures/test/README.md | # cosmos
Your personal library of every algorithm and data structure code that you will ever encounter
|
code/data_structures/test/bag/test_bag.cpp | //Needed for random and vector
#include <vector>
#include <string>
#include <cstdlib>
#include <iostream>
using std::cout;
using std::endl;
using std::string;
using std::vector;
//Bag Class Declaration
class Bag
{
private:
vector<string> items;
int bagSize;
public:
Bag();
void add(string);
bool isEmpty();
in... |
code/data_structures/test/list/test_list.cpp | /*
* Part of Cosmos by OpenGenus Foundation
*
* test lists for std::list-like
*/
#define CATCH_CONFIG_MAIN
#ifndef XOR_LINKED_LIST_TEST_CPP
#define XOR_LINKED_LIST_TEST_CPP
#include "../../../../test/c++/catch.hpp"
#include "../../src/list/xor_linked_list/xor_linked_list.cpp"
#include <iostream>
#include <list>
#... |
code/data_structures/test/tree/binary_tree/binary_tree/diameter/test_diameter.cpp | #define CATCH_CONFIG_MAIN
#include "../../../../../../../test/c++/catch.hpp"
#include "../../../../../src/tree/binary_tree/binary_tree/serializer/serializer.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/node/node.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/diameter/diameter.cpp"
#inc... |
code/data_structures/test/tree/binary_tree/binary_tree/is_same/test_is_same.cpp | #define CATCH_CONFIG_MAIN
#ifndef TEST_TREE_COMPARER
#define TEST_TREE_COMPARER
#include <memory>
#include <functional>
#include <utility>
#include "../../../../../../../test/c++/catch.hpp"
#include "../../../../../src/tree/binary_tree/binary_tree/is_same/is_same.cpp"
#include "../../../../../src/tree/binary_tree/bina... |
code/data_structures/test/tree/binary_tree/binary_tree/path_sum/test_path_sum_for_sum_of_part_paths.cpp | #define CATCH_CONFIG_MAIN
#include "../../../../../../../test/c++/catch.hpp"
#include <vector>
#include <memory>
#include <queue>
#include "../../../../../src/tree/binary_tree/binary_tree/node/node.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/serializer/serializer.cpp"
#include "../../../../../src/tre... |
code/data_structures/test/tree/binary_tree/binary_tree/path_sum/test_path_sum_for_sum_of_whole_paths.cpp | #define CATCH_CONFIG_MAIN
#include "../../../../../../../test/c++/catch.hpp"
#include <vector>
#include <memory>
#include <queue>
#include "../../../../../src/tree/binary_tree/binary_tree/node/node.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/serializer/serializer.cpp"
#include "../../../../../src/tre... |
code/data_structures/test/tree/binary_tree/binary_tree/path_sum/test_path_sum_for_whole_paths.cpp | #define CATCH_CONFIG_MAIN
#include "../../../../../../../test/c++/catch.hpp"
#include <vector>
#include <memory>
#include <queue>
#include "../../../../../src/tree/binary_tree/binary_tree/node/node.cpp"
#include "../../../../../src/tree/binary_tree/binary_tree/serializer/serializer.cpp"
#include "../../../../../src/tre... |
code/data_structures/test/tree/multiway_tree/red_black_tree/test_red_black.c | /**
* author: JonNRb <[email protected]>
* license: GPLv3
* file: @cosmos//code/data_structures/red_black_tree/red_black_test.c
* info: red black tree
*/
#include "red_black_tree.h"
#include <assert.h>
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <s... |
code/data_structures/test/tree/multiway_tree/union_find/test_union_find.cpp | #include <iostream>
#include <cassert>
#include "../../../../src/tree/multiway_tree/union_find/union_find_dynamic.cpp"
int main()
{
UnionFind<int> unionFind;
unionFind.merge(3, 4);
unionFind.merge(3, 8);
unionFind.merge(0, 8);
unionFind.merge(1, 3);
unionFind.merge(7, 9);
unionFind.merge(5... |
code/data_structures/test/tree/segment_tree/test_generic_segment_tree.cpp | #include <algorithm>
#include <iostream>
#include <vector>
// Note that the below line includes a translation unit and not header file
#include "../../../src/tree/segment_tree/generic_segment_tree.cpp"
#define ASSERT(value, expected_value, message) \
{ ... |
code/design_pattern/src/OOP_patterns/README.md | # cosmos
Your personal library of every design pattern code that you will ever encounter
Collaborative effort by [OpenGenus](https://github.com/opengenus)
|
code/design_pattern/src/OOP_patterns/__init__.py | |
code/design_pattern/src/OOP_patterns/adapter/adaptor.java | package Adapter;
import Adapter.Soldiers.Adaptee;
import Adapter.Soldiers.General;
public class Adaptor implements Movement {
public Adaptee adaptee;
public General general;
public Adaptor(Adaptee adaptee, General general) {
this.adaptee = adaptee;
this.general = general;
}
@Ov... |
code/design_pattern/src/OOP_patterns/adapter/civilian.java | package Adapter;
public class Civilian implements Movement {
@Override
public void walk() {
System.out.println("I'm having a beautiful stroll in my happy, little peaceful town.");
}
}
|
code/design_pattern/src/OOP_patterns/adapter/movement.java | package Adapter;
public interface Movement {
void walk();
}
|
code/design_pattern/src/OOP_patterns/adapter/soldiers/adaptee.java | package Adapter.Soldiers;
public interface Adaptee {
void walk();
void changeWalkStyle(Order newStyle);
}
|
code/design_pattern/src/OOP_patterns/adapter/soldiers/general.java | package Adapter.Soldiers;
import Adapter.Movement;
import java.util.List;
public class General {
private Order order;
public List<Adaptee> troopsUnderCommand;
public void setOrder(Order order) {
this.order = order;
}
public Order receiveOrder() {
if (order == null)
... |
code/design_pattern/src/OOP_patterns/adapter/soldiers/order.java | package Adapter.Soldiers;
public enum Order {
WALKING, RUNNING, STROLLING, LIMPING, AT_EASE
}
|
code/design_pattern/src/OOP_patterns/adapter/soldiers/soldier.java | package Adapter.Soldiers;
public class Soldier implements Adaptee {
private Order order;
@Override
public void walk() {
System.out.println("IM " + order + ", SIR, YES, SIR!");
}
@Override
public void changeWalkStyle(Order newStyle) {
this.order = newStyle;
}
}
|
code/design_pattern/src/OOP_patterns/builder/builder/nationality.java | package builder;
public enum Nationality {
Ro, En, Gr, Br, Ru, Aus
}
|
code/design_pattern/src/OOP_patterns/builder/builder/person.java | package builder;
import java.util.Date;
public class Person {
private String firstname;
private String lastname;
private Date birthdate;
private Nationality nationality;
private boolean isProgrammer;
private Integer iq;
private boolean isPoor;
private boolean isPopular;
private bo... |
code/design_pattern/src/OOP_patterns/builder/builder/personbuilder.java | package builder;
import org.omg.CORBA.DynAnyPackage.InvalidValue;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.function.Consumer;
public class PersonBuilder {
private String firstname;
private String lastname;
private Date birthdate;
pri... |
code/design_pattern/src/OOP_patterns/builder/main.java | import builder.Nationality;
import builder.Person;
import builder.PersonBuilder;
import org.omg.CORBA.DynAnyPackage.InvalidValue;
import java.text.ParseException;
public class Main {
public static void main(String[] args) {
Person person = new PersonBuilder()
.with(personBuilder -> {
... |
code/design_pattern/src/OOP_patterns/decorator/decorator.ts | interface Component {
operation(): string;
}
interface HelloWorldDecorator {
operation(): string;
}
class ComponentImpl implements Component {
public operation(): string {
return 'This method is decorated';
}
}
// This is the general way to implement decorators
class HelloWorldDecoratorImpl i... |
code/design_pattern/src/OOP_patterns/facade/daily/tasks/dailyroutinefacade.java | package daily.tasks;
import daily.tasks.evening.routine.EveningRoutineFacade;
import daily.tasks.gym.GymFacade;
import daily.tasks.job.JobFacade;
import daily.tasks.morning.routine.MorningRoutineFacade;
public class DailyRoutineFacade {
public DailyRoutineFacade() {
new MorningRoutineFacade();
new... |
code/design_pattern/src/OOP_patterns/facade/daily/tasks/evening/routine/eat.java | package daily.tasks.evening.routine;
class Eat {
Eat() {
System.out.println("Dinner - or mostly not");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/evening/routine/eveningroutinefacade.java | package daily.tasks.evening.routine;
public class EveningRoutineFacade {
public EveningRoutineFacade() {
System.out.println("\n\n\t\tEvening Routine\n\n");
new Eat();
new TakeAShower();
new WriteCode();
new WatchYoutubeVideos();
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/evening/routine/takeashower.java | package daily.tasks.evening.routine;
class TakeAShower {
TakeAShower() {
System.out.println("Im taking a good ol' scrub");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/evening/routine/watchyoutubevideos.java | package daily.tasks.evening.routine;
class WatchYoutubeVideos {
WatchYoutubeVideos() {
System.out.println("Im watching some youtube videos");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/evening/routine/writecode.java | package daily.tasks.evening.routine;
class WriteCode {
WriteCode() {
System.out.println("Probably writing some Scala code");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/gym/benchpress.java | package daily.tasks.gym;
class BenchPress {
BenchPress() {
System.out.println("Gotta bench 140 at least");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/gym/deadlift.java | package daily.tasks.gym;
class Deadlift {
Deadlift() {
System.out.println("Deadlifting 100kg at least");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/gym/gymfacade.java | package daily.tasks.gym;
public class GymFacade {
public GymFacade() {
System.out.println("\n\n\t\tGym Routine\n\n");
new Deadlift();
new BenchPress();
new Squat();
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/gym/squat.java | package daily.tasks.gym;
class Squat {
Squat() {
System.out.println("Squatting is awesome");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/job/develop.java | package daily.tasks.job;
class Develop {
Develop() {
System.out.println("I'm writing some basic code");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/job/eatatwork.java | package daily.tasks.job;
class EatAtWork {
EatAtWork() {
System.out.println("This shaorma tastes great!");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/job/jobfacade.java | package daily.tasks.job;
public class JobFacade {
public JobFacade() {
System.out.println("\n\n\t\tJob Routine\n\n");
new Develop();
new WatchYoutubeVideos();
new PlayFifa();
new EatAtWork();
new Develop();
new Develop();
new WatchYoutubeVideos();
... |
code/design_pattern/src/OOP_patterns/facade/daily/tasks/job/leave.java | package daily.tasks.job;
class Leave {
Leave() {
System.out.println("I'm leaving home");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/job/playfifa.java | package daily.tasks.job;
class PlayFifa {
PlayFifa() {
System.out.println("I'm playing fifa");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/job/watchyoutubevideos.java | package daily.tasks.job;
class WatchYoutubeVideos {
WatchYoutubeVideos() {
System.out.println("I'm watching Youtube videos");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/morning/routine/dress.java | package daily.tasks.morning.routine;
class Dress {
Dress() {
System.out.println("Dress");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/morning/routine/eat.java | package daily.tasks.morning.routine;
class Eat {
Eat() {
System.out.println("Im eating");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/morning/routine/leave.java | package daily.tasks.morning.routine;
class Leave {
Leave() {
System.out.println("Im leaving home");
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/morning/routine/morningroutinefacade.java | package daily.tasks.morning.routine;
public class MorningRoutineFacade {
public MorningRoutineFacade() {
System.out.println("\n\n\t\tMorning Routine\n\n");
new WakeUp();
new Eat();
new Dress();
new Leave();
}
}
|
code/design_pattern/src/OOP_patterns/facade/daily/tasks/morning/routine/wakeup.java | package daily.tasks.morning.routine;
class WakeUp {
WakeUp() {
System.out.println("Woken up");
}
}
|
code/design_pattern/src/OOP_patterns/facade/facade | The whole purpose of Facade is to "aggregate" multiple classes and functionality into a single place, thus acting like
well... a Facade - beautiful on the outside, but hiding all the complexity of the "inside building". The example
is taken to the extreme to showcase it properly - imagine each class that is managed has... |
code/design_pattern/src/OOP_patterns/facade/main.java | import daily.tasks.DailyRoutineFacade;
public class Main {
public static void main(String[] args) {
new DailyRoutineFacade();
}
}
|
code/design_pattern/src/OOP_patterns/factory/gifts/booze.java | package factory.gifts;
public class Booze implements Gift {
@Override
public String message() {
return "You won booze - get drunk";
}
}
|
code/design_pattern/src/OOP_patterns/factory/gifts/car.java | package factory.gifts;
public class Car implements Gift {
@Override
public String message() {
return "Nobody wins a car, it's a prank, bro";
}
}
|
code/design_pattern/src/OOP_patterns/factory/gifts/gift.java | package factory.gifts;
public interface Gift {
String message();
}
|
code/design_pattern/src/OOP_patterns/factory/gifts/nothing.java | package factory.gifts;
public class Nothing implements Gift {
@Override
public String message() {
return "YOU WON NOTHING!";
}
}
|
code/design_pattern/src/OOP_patterns/factory/gifts/toy.java | package factory.gifts;
public class Toy implements Gift {
@Override
public String message() {
return "You won a toy! Be happy";
}
}
|
code/design_pattern/src/OOP_patterns/factory/gifttype.java | package factory;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public enum GiftType {
Nothing, Car, Toy, Booze, Error;
public GiftType fromString(String from) {
if (from.equalsIgnoreCase("nothing"))
return Nothing;
if (from... |
code/design_pattern/src/OOP_patterns/factory/roulette.java | package factory;
import factory.gifts.*;
import java.util.Scanner;
public class Roulette {
public void run() throws InterruptedException {
while (true) {
Scanner input = new Scanner(System.in);
System.out.println("Let's see what the russian roulette will give you");
... |
code/design_pattern/src/OOP_patterns/observer_java/demo.java | import observer.Observer;
import observer.Subject;
import observer.network.Artist;
import observer.network.Fan;
public class Demo {
public void startDemo() {
Observer f1 = new Fan("Robert");
Observer f2 = new Fan("David");
Observer f3 = new Fan("Gangplank");
Subject<String> s1 = ne... |
code/design_pattern/src/OOP_patterns/observer_java/main.java | public class Main {
public static void main(String[] args) {
new Demo().startDemo();
}
}
|
code/design_pattern/src/OOP_patterns/observer_java/observer/network/artist.java | package observer.network;
import observer.Observer;
import observer.Subject;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Artist<T extends String> implements Subject {
private Set<Observer> observers;
private String name;
private List<S... |
code/design_pattern/src/OOP_patterns/observer_java/observer/network/fan.java | package observer.network;
import observer.Observer;
import java.util.*;
public class Fan implements Observer {
private String name;
private Set<Artist> followedSubjects;
public Fan(String name) {
this.followedSubjects = new HashSet<>();
this.name = name;
}
public Fan(Set<Artist>... |
code/design_pattern/src/OOP_patterns/observer_java/observer/observer.java | package observer;
public interface Observer {
void receiveNotification(Subject from);
}
|
code/design_pattern/src/OOP_patterns/observer_java/observer/subject.java | package observer;
public interface Subject<T extends String> {
void subscribe(Observer o);
void unsubscribe(Observer o);
void notifyObservers();
String getLastNotification();
void addNotification(T notification);
}
|
code/design_pattern/src/OOP_patterns/observer_pattern/__init__.py | from .observer_pattern import Notifier, Observer
|
code/design_pattern/src/OOP_patterns/observer_pattern/observer_pattern.cpp | /*
* observer_pattern.cpp
*
* Created on: 26 May 2017
* Author: yogeshb2
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class IWeatherChanger
{
public:
virtual ~IWeatherChanger()
{
}
virtual void onTemperatureChange(int temperature) = 0;
};
class ITempe... |
code/design_pattern/src/OOP_patterns/observer_pattern/observer_pattern.py | """
How to use observer:
1. Decorate your observed-class with the Observer class,
which observe some notifier.
2. Implement the update member-function in your the observed-class
which will be passed only one parameter: event and no return.
3. Decorate your notified-class with the Notifier class,
which notif... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.